Skip to content
Merged
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
20 changes: 19 additions & 1 deletion docs/JSON-RPC.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ Results:

### jamulusserver/broadcastChatMessage

Sends a message (as the server) to all connected clients. This can be used to broadcast messages from external sources (e.g. scripts or monitoring tools).
Sends a message (as the server) to all connected clients. This can be used to broadcast messages from external sources (e.g. scripts or monitoring tools).

Parameters:

Expand Down Expand Up @@ -430,6 +430,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 | "ok" or "error" if bad arguments. |


### jamulusserver/restartRecording

Restarts the recording into a new directory.
Expand Down
10 changes: 6 additions & 4 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1379,13 +1379,15 @@ void CServer::SendChatTextToAllConChannels ( const int iSendingChanID, const QSt
emit sentChatMessage ( iSendingChanID, strChatText );
}

void CServer::SendChatTextToConChannel ( const int iCurChanID, const QString& strChatText )
bool CServer::SendChatTextToConChannel ( const int iCurChanID, const QString& strChatText )
{
if ( MathUtils::InRange<int> ( iCurChanID, 0, iMaxNumChannels - 1 ) && vecChannels[iCurChanID].IsConnected() )
if ( !MathUtils::InRange<int> ( iCurChanID, 0, iMaxNumChannels - 1 ) || !vecChannels[iCurChanID].IsConnected() )
{
// send message
vecChannels[iCurChanID].CreateChatTextMes ( strChatText );
return false;
}
// send message
vecChannels[iCurChanID].CreateChatTextMes ( strChatText );
return true;
}

void CServer::CreateAndSendRecorderStateForAllConChannels()
Expand Down
2 changes: 1 addition & 1 deletion src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class CServer : public QObject, public CServerSlots<MAX_NUM_CHANNELS>
bool IsDelayPanningEnabled() { return bDelayPan; }

void SendChatTextToAllConChannels ( const int iSendingChanID, const QString& strChatText );
void SendChatTextToConChannel ( const int iCurChanID, const QString& strChatText );
bool SendChatTextToConChannel ( const int iCurChanID, const QString& strChatText );

protected:
// access functions for actual channels
Expand Down
24 changes: 24 additions & 0 deletions src/serverrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,30 @@ CServerRpc::CServerRpc ( CServer* pServer, CRpcServer* pRpcServer, QObject* pare
response["result"] = "ok";
} );

/// @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 - "ok" or "error" if bad arguments.
pRpcServer->HandleMethod ( "jamulusserver/privateChatMessage", [=] ( const QJsonObject& params, QJsonObject& response ) {
auto jsonChatMessage = params["chatMessage"];
const int id = params["id"].toInt ( INVALID_CLIENT_ID );
const QString chatMessage = jsonChatMessage.toString();
if ( chatMessage.isEmpty() || chatMessage.size() > MAX_LEN_CHAT_TEXT )
{
response["error"] =
CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: chatMessage is not a string or malformed" );
return;
}

if ( !pServer->SendChatTextToConChannel ( id, chatMessage ) )
{
response["error"] = "invalid channel ID";
return;
}
response["result"] = "ok";
} );

/// @rpc_method jamulusserver/getRecorderStatus
/// @brief Returns the recorder state.
/// @param {object} params - No parameters (empty object).
Expand Down
Loading