-
Notifications
You must be signed in to change notification settings - Fork 246
Add jamulusserver/privateChatMessage RPC method for sending messages to single channels #3731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs validating, probably in
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CServer::CreateAndSendChatTextToChannel does actually validate the channel ID and will only send the message if the channel is present. It was copied from the original function for sending chat messages.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Commented there.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still think that it should then not return OK. At least if id is unset, it should fail.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm guessing we have a max message length for UDP CM chat messages? The JSONRPC request message length should be validated against that and an error returned. And yes, it needs to return an error for an incorrect channel id.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't JSON-RPC using a TCP socket, if so, it should be of basically "infinite" length?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It needs to not overrun the existing request expectations. |
||
| if ( !jsonChatMessage.isString() ) | ||
| { | ||
| response["error"] = CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: chatMessage is not a string" ); | ||
| return; | ||
| } | ||
|
|
||
| pServer->SendChatTextToConChannel ( id, jsonChatMessage.toString() ); | ||
| response["result"] = "ok"; | ||
| } ); | ||
| } | ||
|
|
||
| #if defined( Q_OS_MACOS ) && QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we document errors? It should not rather be "ok" on success, no?