Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/JSON-RPC.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,24 @@ Results:
| result.registrationStatus | string | The server registration status as string (see ESvrRegStatus and SerializeRegistrationStatus). |


### jamulusserver/privateChatMessage

Sends a chat message to a single connected client.

Parameters:

| Name | Type | Description |
| --- | --- | --- |
| params.chatMessage | string | The chat message text. |
| params.id | number | The client's channel id. |

Results:

| Name | Type | Description |
| --- | --- | --- |
| result | string | Always "ok". |


### jamulusserver/restartRecording

Restarts the recording into a new directory.
Expand Down
17 changes: 12 additions & 5 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1300,11 +1300,18 @@ void CServer::CreateAndSendChatTextForAllConChannels ( const int iCurChanID, con
// Send chat text to all connected clients ---------------------------------
for ( int i = 0; i < iMaxNumChannels; i++ )
{
if ( vecChannels[i].IsConnected() )
{
// send message
vecChannels[i].CreateChatTextMes ( strActualMessageText );
}
CreateAndSendChatTextToChannel ( strActualMessageText, i );
}
}

// private chat
void CServer::CreateAndSendChatTextToChannel ( const QString& strChatText, const int id )
{
// Check if channel is connected ---------------------------------
if ( vecChannels[id].IsConnected() )

@pljones pljones Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will potentially throw an exception if id is out of bounds. The vector isn't MAX_INT in size, nor are negative indices valid.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but this applies to the original code as well, although it is never called with invalid values at the moment. An idea would be to refactor this on main first so I can rebase this PR and #3730 since this refactor is needed for both PRs.

{
// send message
vecChannels[id].CreateChatTextMes ( strChatText );
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ class CServer : public QObject, public CServerSlots<MAX_NUM_CHANNELS>
void SetEnableDelayPanning ( bool bDelayPanningOn ) { bDelayPan = bDelayPanningOn; }
bool IsDelayPanningEnabled() { return bDelayPan; }

void CreateAndSendChatTextToChannel ( const QString& strChatText, const int id );

protected:
// access functions for actual channels
bool IsConnected ( const int iChanNum ) { return vecChannels[iChanNum].IsConnected(); }
Expand Down
18 changes: 18 additions & 0 deletions src/serverrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,24 @@ CServerRpc::CServerRpc ( CServer* pServer, CRpcServer* pRpcServer, QObject* pare
response["result"] = "acknowledged";
Q_UNUSED ( params );
} );

/// @rpc_method jamulusserver/privateChatMessage
/// @brief Sends a chat message to a single connected client.
/// @param {string} params.chatMessage - The chat message text.
/// @param {number} params.id - The client's channel id.
/// @result {string} result - Always "ok".
pRpcServer->HandleMethod ( "jamulusserver/privateChatMessage", [=] ( const QJsonObject& params, QJsonObject& response ) {
auto jsonChatMessage = params["chatMessage"];
const int id = params["id"].toInt();
Comment thread
dingodoppelt marked this conversation as resolved.
if ( !jsonChatMessage.isString() )
{
response["error"] = CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: chatMessage is not a string" );
return;
}

pServer->CreateAndSendChatTextToChannel ( jsonChatMessage.toString(), id );
response["result"] = "ok";
} );
}

#if defined( Q_OS_MACOS ) && QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
Expand Down
Loading