diff --git a/docs/JSON-RPC.md b/docs/JSON-RPC.md index cfe8dfbe3e..52c8973c29 100644 --- a/docs/JSON-RPC.md +++ b/docs/JSON-RPC.md @@ -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. diff --git a/src/server.cpp b/src/server.cpp index 67274965bc..79e5a4b6e5 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1308,6 +1308,17 @@ void CServer::CreateAndSendChatTextForAllConChannels ( const int iCurChanID, con } } +// private chat +void CServer::CreateAndSendChatTextToChannel ( const QString& strChatText, const int id ) +{ + // Check if channel is connected --------------------------------- + if ( vecChannels[id].IsConnected() ) + { + // send message + vecChannels[id].CreateChatTextMes ( strChatText ); + } +} + void CServer::CreateAndSendRecorderStateForAllConChannels() { // get recorder state diff --git a/src/server.h b/src/server.h index 2e6b13e835..818520145b 100644 --- a/src/server.h +++ b/src/server.h @@ -191,6 +191,8 @@ class CServer : public QObject, public CServerSlots 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(); } diff --git a/src/serverrpc.cpp b/src/serverrpc.cpp index 315a3e262c..6d0b2f926d 100644 --- a/src/serverrpc.cpp +++ b/src/serverrpc.cpp @@ -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(); + 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 )