Skip to content
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

Add JSON-RPC access to directories and server lists. #3249

Closed
wants to merge 15 commits into from
Prev Previous commit
Next Next commit
JSON-RPC fixes for feedback to PR
Changes method "jamulus/pollServerList" to "jamulusclient/pollServerList" (for consistency).
Changes "url" to "address" in protocol and "server address" in docs.
Fixes typo in countryId.
  • Loading branch information
riban-bw committed Mar 23, 2024
commit 86ed64e872a0e585eb540f872c59e3755f0daf69
8 changes: 4 additions & 4 deletions docs/JSON-RPC.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,19 @@ Results:

### jamulusclient/pollServerList

Requests server list.
Requests the server list from a specified directory.
Copy link
Member

Choose a reason for hiding this comment

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

Sorry for my forgetfulness here - you need to update the python script I mentioned below and not edit the file directly

Copy link
Author

Choose a reason for hiding this comment

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

I have run the script and pushed the changes.


Parameters:

| Name | Type | Description |
| --- | --- | --- |
| params.directory | string | URL of directory, e.g. anygenre1.jamulus.io:22124 |
| params.directory | string | Socket address of directory, e.g. anygenre1.jamulus.io:22124 |

Results:

| Name | Type | Description |
| --- | --- | --- |
| result | string | "ok" or "error" if invalid URL |
| result | string | "ok" or "error" if invalid socket address |

### jamulusclient/sendChatText

Expand Down Expand Up @@ -474,7 +474,7 @@ Parameters:
| Name | Type | Description |
| --- | --- | --- |
| params.servers | array | The server list. |
| params.servers[*].url | url | The server's URL. |
| params.servers[*].address | string | The server's socket address. |
| params.servers[*].name | string | The server’s name. |
| params.servers[*].countryId | number | The servers’s country ID (see QLocale::Country). |
| params.servers[*].city | string | The server’s city. |
Expand Down
12 changes: 6 additions & 6 deletions src/clientrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare
/// @rpc_notification jamulusclient/serverListReceived
/// @brief Emitted when the server list is received.
/// @param {array} params.servers - The server list.
/// @param {string} params.servers[*].url - IP Address
/// @param {string} params.servers[*].address - Socket address (ip_address:port)
/// @param {string} params.servers[*].name - Server name
/// @param {number} params.servers[*].countryId - Server country code
/// @param {string} params.servers[*].city - Server city
Expand All @@ -106,9 +106,9 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare
for ( const auto& serverInfo : vecServerInfo )
{
QJsonObject objServerInfo{
{ "url", serverInfo.HostAddr.toString() },
{ "address", serverInfo.HostAddr.toString() },
{ "name", serverInfo.strName },
{ "countryI", serverInfo.eCountry },
{ "countryId", serverInfo.eCountry },
{ "city", serverInfo.strCity },
};
arrServerInfo.append ( objServerInfo );
Expand All @@ -126,9 +126,9 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare

/// @rpc_method jamulus/pollServerList
/// @brief Request list of servers in a directory
/// @param {string} params.directory - URL of directory to query, e.g. anygenre1.jamulus.io:22124.
/// @param {string} params.directory - socket address of directory to query, e.g. anygenre1.jamulus.io:22124.
/// @result {string} result - "ok" or "error" if bad arguments.
pRpcServer->HandleMethod ( "jamulus/pollServerList", [=] ( const QJsonObject& params, QJsonObject& response ) {
pRpcServer->HandleMethod ( "jamulusclient/pollServerList", [=] ( const QJsonObject& params, QJsonObject& response ) {
auto jsonDirectoryIp = params["directory"];
if ( !jsonDirectoryIp.isString() )
{
Expand All @@ -148,7 +148,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare
}
else
{
response["error"] = CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: directory is not a valid url" );
response["error"] = CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: directory is not a valid socket address" );
}

response["result"] = "ok";
Expand Down