From 407a2905f37e5c1d730a92e4b3f0c190bbdd2ca3 Mon Sep 17 00:00:00 2001 From: riban Date: Fri, 22 Mar 2024 09:21:04 +0000 Subject: [PATCH 01/15] Implements JSON-RPC methods to get server lists rpc_notification jamulusclient/serverListReceived rpc_method jamulus/pollServerList --- src/client.h | 4 ++++ src/clientrpc.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/src/client.h b/src/client.h index 1fc33d8430..d6301260b6 100644 --- a/src/client.h +++ b/src/client.h @@ -271,6 +271,10 @@ class CClient : public QObject Channel.GetBufErrorRates ( vecErrRates, dLimit, dMaxUpLimit ); } + CProtocol * getConnLessProtocol() { + return &ConnLessProtocol; + } + // settings CChannelCoreInfo ChannelInfo; QString strClientName; diff --git a/src/clientrpc.cpp b/src/clientrpc.cpp index ee992cbfd9..65d1c6ff9a 100644 --- a/src/clientrpc.cpp +++ b/src/clientrpc.cpp @@ -94,11 +94,62 @@ 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[*].address - IP Address + /// @param {string} params.servers[*].name - Server name + /// @param {number} params.servers[*].country - Server country code + /// @param {string} params.servers[*].city - Server city + connect ( pClient->getConnLessProtocol(), &CProtocol::CLServerListReceived, [=] ( CHostAddress /* unused */, CVector vecServerInfo ) { + QJsonArray arrServerInfo; + for ( const auto& serverInfo : vecServerInfo ) + { + QJsonObject objServerInfo{ + { "address", serverInfo.HostAddr.toString() }, + { "name", serverInfo.strName }, + { "country", serverInfo.eCountry }, + { "city", serverInfo.strCity }, + }; + arrServerInfo.append ( objServerInfo ); + } + pRpcServer->BroadcastNotification ( "jamulusclient/serverListReceived", + QJsonObject{ + { "servers", arrServerInfo }, + } ); + } ); + /// @rpc_notification jamulusclient/disconnected /// @brief Emitted when the client is disconnected from the server. /// @param {object} params - No parameters (empty object). connect ( pClient, &CClient::Disconnected, [=]() { pRpcServer->BroadcastNotification ( "jamulusclient/disconnected", QJsonObject{} ); } ); + /// @rpc_method jamulus/getServerList + /// @brief Returns the list of public servers + /// @param {string} params.directory - URL of directory to query, e.g. anygenre1.jamulus.io:22124. + /// @result {string} result - Always "ok". + pRpcServer->HandleMethod ( "jamulus/getServerList", [=] ( const QJsonObject& params, QJsonObject& response ) { + auto jsonDirectoryIp = params["directory"]; + if ( !jsonDirectoryIp.isString() ) + { + response["error"] = CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: directory is not a string" ); + return; + } + + CHostAddress haDirectoryAddress; + if ( NetworkUtil().ParseNetworkAddress ( + jsonDirectoryIp.toString(), + haDirectoryAddress, + false ) ) + { + // send the request for the server list + pClient->CreateCLReqServerListMes( haDirectoryAddress ); + } + + response["result"] = "ok"; + Q_UNUSED ( params ); + } ); + /// @rpc_method jamulus/getMode /// @brief Returns the current mode, i.e. whether Jamulus is running as a server or client. /// @param {object} params - No parameters (empty object). From aa56c2764a0bfa6060d31c876e26298f69fafc70 Mon Sep 17 00:00:00 2001 From: riban Date: Fri, 22 Mar 2024 09:38:11 +0000 Subject: [PATCH 02/15] Change JSON-RPC for server list. Use pollServerList instead of getServerList. (No result returned from the call.) Change "address" to "url" --- src/clientrpc.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/clientrpc.cpp b/src/clientrpc.cpp index 65d1c6ff9a..7eecdc08b8 100644 --- a/src/clientrpc.cpp +++ b/src/clientrpc.cpp @@ -106,7 +106,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare for ( const auto& serverInfo : vecServerInfo ) { QJsonObject objServerInfo{ - { "address", serverInfo.HostAddr.toString() }, + { "url", serverInfo.HostAddr.toString() }, { "name", serverInfo.strName }, { "country", serverInfo.eCountry }, { "city", serverInfo.strCity }, @@ -124,11 +124,11 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare /// @param {object} params - No parameters (empty object). connect ( pClient, &CClient::Disconnected, [=]() { pRpcServer->BroadcastNotification ( "jamulusclient/disconnected", QJsonObject{} ); } ); - /// @rpc_method jamulus/getServerList - /// @brief Returns the list of public servers + /// @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. - /// @result {string} result - Always "ok". - pRpcServer->HandleMethod ( "jamulus/getServerList", [=] ( const QJsonObject& params, QJsonObject& response ) { + /// @result {string} result - "ok" or "error" if bad arguments. + pRpcServer->HandleMethod ( "jamulus/pollServerList", [=] ( const QJsonObject& params, QJsonObject& response ) { auto jsonDirectoryIp = params["directory"]; if ( !jsonDirectoryIp.isString() ) { @@ -144,6 +144,11 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare { // send the request for the server list pClient->CreateCLReqServerListMes( haDirectoryAddress ); + response["result"] = "ok"; + } + else + { + response["error"] = CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: directory is not a valid url" ); } response["result"] = "ok"; From 667191d48f0334180bed48ade97a3d1e2df7f7bb Mon Sep 17 00:00:00 2001 From: riban Date: Fri, 22 Mar 2024 11:31:39 +0000 Subject: [PATCH 03/15] Adds documentation for new JSON-RPC methods --- docs/JSON-RPC.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/JSON-RPC.md b/docs/JSON-RPC.md index 36cc18e087..b23b570fc0 100644 --- a/docs/JSON-RPC.md +++ b/docs/JSON-RPC.md @@ -186,6 +186,21 @@ Results: | result.clients | array | The client list. See jamulusclient/clientListReceived for the format. | +### jamulusclient/pollServerList + +Requests server list. + +Parameters: + +| Name | Type | Description +| --- | --- | --- | +| params.directory | string | URL of directory, e.g. anygenre1.jamulus.io:22124 | + +Results: + +| Name | Type | Description | +| result | string | "ok" or "error" if invalid URL | + ### jamulusclient/sendChatText Sends a chat text message. @@ -449,6 +464,21 @@ Parameters: | params.clients[*].instrumentId | number | The musician’s instrument ID (see CInstPictures::GetTable). | +### jamulusclient/serverListReceived + +Emitted when the server list is received. + +Parameters: + +| Name | Type | Description | +| --- | --- | --- | +| params.servers | array | The server list. | +| params.servers[*].id | url | The server's URL. | +| 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. | + + ### jamulusclient/connected Emitted when the client is connected to the server. From 0372ce11d735f43400445a825c0bbeb9613673f5 Mon Sep 17 00:00:00 2001 From: riban Date: Fri, 22 Mar 2024 11:36:47 +0000 Subject: [PATCH 04/15] Consistent use of countryId --- docs/JSON-RPC.md | 4 ++-- src/clientrpc.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/JSON-RPC.md b/docs/JSON-RPC.md index b23b570fc0..2a4701776a 100644 --- a/docs/JSON-RPC.md +++ b/docs/JSON-RPC.md @@ -192,7 +192,7 @@ Requests server list. Parameters: -| Name | Type | Description +| Name | Type | Description | | --- | --- | --- | | params.directory | string | URL of directory, e.g. anygenre1.jamulus.io:22124 | @@ -473,7 +473,7 @@ Parameters: | Name | Type | Description | | --- | --- | --- | | params.servers | array | The server list. | -| params.servers[*].id | url | The server's URL. | +| params.servers[*].url | url | The server's URL. | | 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. | diff --git a/src/clientrpc.cpp b/src/clientrpc.cpp index 7eecdc08b8..2bcb98ce91 100644 --- a/src/clientrpc.cpp +++ b/src/clientrpc.cpp @@ -97,9 +97,9 @@ 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[*].address - IP Address + /// @param {string} params.servers[*].url - IP Address /// @param {string} params.servers[*].name - Server name - /// @param {number} params.servers[*].country - Server country code + /// @param {number} params.servers[*].countryId - Server country code /// @param {string} params.servers[*].city - Server city connect ( pClient->getConnLessProtocol(), &CProtocol::CLServerListReceived, [=] ( CHostAddress /* unused */, CVector vecServerInfo ) { QJsonArray arrServerInfo; @@ -108,7 +108,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare QJsonObject objServerInfo{ { "url", serverInfo.HostAddr.toString() }, { "name", serverInfo.strName }, - { "country", serverInfo.eCountry }, + { "countryI", serverInfo.eCountry }, { "city", serverInfo.strCity }, }; arrServerInfo.append ( objServerInfo ); From cbeb68ee4a8f36eeb248e1986eed45d9669d2435 Mon Sep 17 00:00:00 2001 From: riban Date: Fri, 22 Mar 2024 11:38:04 +0000 Subject: [PATCH 05/15] Fixes JSON-RPC docs --- docs/JSON-RPC.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/JSON-RPC.md b/docs/JSON-RPC.md index 2a4701776a..afee0757e1 100644 --- a/docs/JSON-RPC.md +++ b/docs/JSON-RPC.md @@ -199,6 +199,7 @@ Parameters: Results: | Name | Type | Description | +| --- | --- | --- | | result | string | "ok" or "error" if invalid URL | ### jamulusclient/sendChatText From 86ed64e872a0e585eb540f872c59e3755f0daf69 Mon Sep 17 00:00:00 2001 From: riban Date: Sat, 23 Mar 2024 09:36:41 +0000 Subject: [PATCH 06/15] 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. --- docs/JSON-RPC.md | 8 ++++---- src/clientrpc.cpp | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/JSON-RPC.md b/docs/JSON-RPC.md index afee0757e1..d821d424c3 100644 --- a/docs/JSON-RPC.md +++ b/docs/JSON-RPC.md @@ -188,19 +188,19 @@ Results: ### jamulusclient/pollServerList -Requests server list. +Requests the server list from a specified directory. 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 @@ -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. | diff --git a/src/clientrpc.cpp b/src/clientrpc.cpp index 2bcb98ce91..a085bf44b9 100644 --- a/src/clientrpc.cpp +++ b/src/clientrpc.cpp @@ -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 @@ -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 ); @@ -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() ) { @@ -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"; From 401c9f919319aa203eeb190bc6a0ae6edcb6f4d7 Mon Sep 17 00:00:00 2001 From: riban Date: Sun, 24 Mar 2024 16:36:43 +0000 Subject: [PATCH 07/15] JSON-RPC Enhancements Adds jamulusclient/connect method. Adds jamulusclient/disconnect method. Adds jamulusclient/serverInfoReceived notification. Return country string rather than (QT specific) country code. Request server info after server list received (to get each server's ping time and num clients). --- docs/JSON-RPC.md | 53 ++++++++++++++++++++++++++++++++++--- src/clientrpc.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 110 insertions(+), 9 deletions(-) diff --git a/docs/JSON-RPC.md b/docs/JSON-RPC.md index d821d424c3..be3980048c 100644 --- a/docs/JSON-RPC.md +++ b/docs/JSON-RPC.md @@ -194,7 +194,7 @@ Parameters: | Name | Type | Description | | --- | --- | --- | -| params.directory | string | Socket address of directory, e.g. anygenre1.jamulus.io:22124 | +| params.directory | string | Socket address of directory (hostname:port), e.g. anygenre1.jamulus.io:22124 | Results: @@ -219,6 +219,40 @@ Results: | result | string | Always "ok". | +### jamulusclient/connect + +Connect client to a server. + +Parameters: + +| Name | Type | Description | +| --- | --- | --- | +| params.address | string | Server socket address (hostname:port) | + +Results: + +| Name | Type | Description | +| --- | --- | --- | +| result | string | "ok" or error if invalid address. + + +### jamulusclient/disconnect + +Disconnect client from server. + +Parameters: + +| Name | Type | Description | +| --- | --- | --- | +| params | object | No parameters (empty object). | + +Results: + +| Name | Type | Description | +| --- | --- | --- | +| result | string | Always "ok". + + ### jamulusclient/setName Sets your name. @@ -474,12 +508,25 @@ Parameters: | Name | Type | Description | | --- | --- | --- | | params.servers | array | The server list. | -| params.servers[*].address | string | The server's socket address. | +| params.servers[*].address | string | The server's socket address (hostname:port). | | params.servers[*].name | string | The server’s name. | -| params.servers[*].countryId | number | The servers’s country ID (see QLocale::Country). | +| params.servers[*].country | string | The servers’s country. | | params.servers[*].city | string | The server’s city. | +### jamulusclient/serverInfoReceived + +Emitted when a server info is received. + +Parameters: + +| Name | Type | Description | +| --- | --- | --- | +| params.servers[*].address | string | The server's socket address (hostname:port). | +| params.servers[*].pingTime | number | The round-trip ping time in ms. | +| params.servers[*].numClients | number | The quantity of clients connected to the server . | + + ### jamulusclient/connected Emitted when the client is connected to the server. diff --git a/src/clientrpc.cpp b/src/clientrpc.cpp index a085bf44b9..f07f802d1a 100644 --- a/src/clientrpc.cpp +++ b/src/clientrpc.cpp @@ -53,7 +53,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare /// @param {number} params.clients[*].id - The channel ID. /// @param {string} params.clients[*].name - The musician’s name. /// @param {string} params.clients[*].skillLevel - The musician’s skill level (beginner, intermediate, expert, or null). - /// @param {number} params.clients[*].countryId - The musician’s country ID (see QLocale::Country). + /// @param {string} params.clients[*].country - The musician’s country. /// @param {string} params.clients[*].city - The musician’s city. /// @param {number} params.clients[*].instrumentId - The musician’s instrument ID (see CInstPictures::GetTable). connect ( pClient, &CClient::ConClientListMesReceived, [=] ( CVector vecChanInfo ) { @@ -64,7 +64,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare { "id", chanInfo.iChanID }, { "name", chanInfo.strName }, { "skillLevel", SerializeSkillLevel ( chanInfo.eSkillLevel ) }, - { "countryId", chanInfo.eCountry }, + { "country", QLocale::countryToString ( chanInfo.eCountry ) }, { "city", chanInfo.strCity }, { "instrumentId", chanInfo.iInstrument }, }; @@ -99,7 +99,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare /// @param {array} params.servers - The server list. /// @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[*].country - Server country /// @param {string} params.servers[*].city - Server city connect ( pClient->getConnLessProtocol(), &CProtocol::CLServerListReceived, [=] ( CHostAddress /* unused */, CVector vecServerInfo ) { QJsonArray arrServerInfo; @@ -108,10 +108,11 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare QJsonObject objServerInfo{ { "address", serverInfo.HostAddr.toString() }, { "name", serverInfo.strName }, - { "countryId", serverInfo.eCountry }, + { "country", QLocale::countryToString ( serverInfo.eCountry) }, { "city", serverInfo.strCity }, }; arrServerInfo.append ( objServerInfo ); + pClient->CreateCLServerListPingMes ( serverInfo.HostAddr ); } pRpcServer->BroadcastNotification ( "jamulusclient/serverListReceived", QJsonObject{ @@ -119,6 +120,20 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare } ); } ); + /// @rpc_notification jamulusclient/serverInfoReceived + /// @brief Emitted when a server info is received. + /// @param {string} params.address - The server socket address + /// @param {number} params.pingtime - The round-trip ping time in ms + /// @param {number} params.numClients - The quantity of clients connected to the server + connect (pClient, &CClient::CLPingTimeWithNumClientsReceived, [=] ( CHostAddress InetAddr, int iPingTime, int iNumClients ) { + pRpcServer->BroadcastNotification ( "jamulusclient/serverInfoReceived", + QJsonObject{ + {"address", InetAddr.toString()}, + {"pingTime", iPingTime}, + {"numClients", iNumClients} + } ); + } ); + /// @rpc_notification jamulusclient/disconnected /// @brief Emitted when the client is disconnected from the server. /// @param {object} params - No parameters (empty object). @@ -151,6 +166,45 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare response["error"] = CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: directory is not a valid socket address" ); } + response["result"] = "ok"; + } ); + + /// @rpc_method jamulusclient/connect + /// @brief Disconnect client from server + /// @param {string} params.address - Server socket address (ip_addr:port). + /// @result {string} result - Always "ok". + pRpcServer->HandleMethod ( "jamulusclient/connect", [=] ( const QJsonObject& params, QJsonObject& response ) { + auto jsonAddr = params["address"]; + if ( !jsonAddr.isString() ) + { + response["error"] = CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: address is not a string" ); + return; + } + + if ( pClient->SetServerAddr(jsonAddr.toString()) ) + { + if ( !pClient->IsRunning() ) + { + pClient->Start(); + } + response["result"] = "ok"; + } + else + { + response["error"] = CRpcServer::CreateJsonRpcError ( 1, "Bad server address" ); + } + } ); + + /// @rpc_method jamulusclient/disconnect + /// @brief Disconnect client from server + /// @param {object} params - No parameters (empty object). + /// @result {string} result - Always "ok". + pRpcServer->HandleMethod ( "jamulusclient/disconnect", [=] ( const QJsonObject& params, QJsonObject& response ) { + if ( pClient->IsRunning() ) + { + pClient->Stop(); + } + response["result"] = "ok"; Q_UNUSED ( params ); } ); @@ -181,7 +235,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare /// @result {number} result.id - The channel ID. /// @result {string} result.name - The musician’s name. /// @result {string} result.skillLevel - The musician’s skill level (beginner, intermediate, expert, or null). - /// @result {number} result.countryId - The musician’s country ID (see QLocale::Country). + /// @result {string} result.country - The musician’s country. /// @result {string} result.city - The musician’s city. /// @result {number} result.instrumentId - The musician’s instrument ID (see CInstPictures::GetTable). /// @result {string} result.skillLevel - Your skill level (beginner, intermediate, expert, or null). @@ -189,7 +243,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare QJsonObject result{ // TODO: We cannot include "id" here is pClient->ChannelInfo is a CChannelCoreInfo which lacks that field. { "name", pClient->ChannelInfo.strName }, - { "countryId", pClient->ChannelInfo.eCountry }, + { "country", QLocale::countryToString ( pClient->ChannelInfo.eCountry ) }, { "city", pClient->ChannelInfo.strCity }, { "instrumentId", pClient->ChannelInfo.iInstrument }, { "skillLevel", SerializeSkillLevel ( pClient->ChannelInfo.eSkillLevel ) }, From 6573b9c5c4c1e1b63bd0d2b349e074e517b3cb25 Mon Sep 17 00:00:00 2001 From: riban Date: Mon, 25 Mar 2024 07:37:48 +0000 Subject: [PATCH 08/15] JSON-RPC enhancements Adds method jamulusclient/recorderState. Changes intrument code to instrument name (remote client may not have access to lookup table). Fixes errors in docs. --- docs/JSON-RPC.md | 21 ++++++++++++++++----- src/clientrpc.cpp | 18 ++++++++++++++---- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/docs/JSON-RPC.md b/docs/JSON-RPC.md index be3980048c..a6d05cfd23 100644 --- a/docs/JSON-RPC.md +++ b/docs/JSON-RPC.md @@ -148,7 +148,7 @@ Results: | result.skillLevel | string | The musician’s skill level (beginner, intermediate, expert, or null). | | result.countryId | number | The musician’s country ID (see QLocale::Country). | | result.city | string | The musician’s city. | -| result.instrumentId | number | The musician’s instrument ID (see CInstPictures::GetTable). | +| result.instrument | string | The musician’s instrument. | | result.skillLevel | string | Your skill level (beginner, intermediate, expert, or null). | @@ -308,9 +308,9 @@ Results: | result.clients[*].name | string | The client’s name. | | result.clients[*].jitterBufferSize | number | The client’s jitter buffer size. | | result.clients[*].channels | number | The number of audio channels of the client. | -| result.clients[*].instrumentCode | number | The id of the instrument for this channel. | +| result.clients[*].instrument | string | The instrument name provided by the user for this channel. | | result.clients[*].city | string | The city name provided by the user for this channel. | -| result.clients[*].countryName | number | The text name of the country specified by the user for this channel (see QLocale::Country). | +| result.clients[*].countryName | string | The country name provided by the user for this channel. | | result.clients[*].skillLevelCode | number | The skill level id provided by the user for this channel. | @@ -494,9 +494,9 @@ Parameters: | params.clients[*].id | number | The channel ID. | | params.clients[*].name | string | The musician’s name. | | params.clients[*].skillLevel | string | The musician’s skill level (beginner, intermediate, expert, or null). | -| params.clients[*].countryId | number | The musician’s country ID (see QLocale::Country). | +| params.clients[*].country | string | The musician’s country. | | params.clients[*].city | string | The musician’s city. | -| params.clients[*].instrumentId | number | The musician’s instrument ID (see CInstPictures::GetTable). | +| params.clients[*].instrument | string | The musician’s instrument. | ### jamulusclient/serverListReceived @@ -549,3 +549,14 @@ Parameters: | params | object | No parameters (empty object). | +### jamulusclient/recorderState + +Emitted when the client is connected to a server who's recorder state changes. + +Parameters: + +| Name | Type | Description | +| --- | --- | --- | +| params.state | number | The recorder state (see ERecorderState). | + + diff --git a/src/clientrpc.cpp b/src/clientrpc.cpp index f07f802d1a..2366cb8889 100644 --- a/src/clientrpc.cpp +++ b/src/clientrpc.cpp @@ -55,7 +55,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare /// @param {string} params.clients[*].skillLevel - The musician’s skill level (beginner, intermediate, expert, or null). /// @param {string} params.clients[*].country - The musician’s country. /// @param {string} params.clients[*].city - The musician’s city. - /// @param {number} params.clients[*].instrumentId - The musician’s instrument ID (see CInstPictures::GetTable). + /// @param {string} params.clients[*].instrument - The musician’s instrument. connect ( pClient, &CClient::ConClientListMesReceived, [=] ( CVector vecChanInfo ) { QJsonArray arrChanInfo; for ( const auto& chanInfo : vecChanInfo ) @@ -66,7 +66,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare { "skillLevel", SerializeSkillLevel ( chanInfo.eSkillLevel ) }, { "country", QLocale::countryToString ( chanInfo.eCountry ) }, { "city", chanInfo.strCity }, - { "instrumentId", chanInfo.iInstrument }, + { "instrument", CInstPictures::GetName ( chanInfo.iInstrument ) }, }; arrChanInfo.append ( objChanInfo ); } @@ -139,6 +139,16 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare /// @param {object} params - No parameters (empty object). connect ( pClient, &CClient::Disconnected, [=]() { pRpcServer->BroadcastNotification ( "jamulusclient/disconnected", QJsonObject{} ); } ); + /// @rpc_notification jamulusclient/recorderState + /// @brief Emitted when the client is connected to a server who's recorder state changes. + /// @param {number} params.state - The recorder state + connect ( pClient, &CClient::RecorderStateReceived, [=] ( const ERecorderState newRecorderState ) { + pRpcServer->BroadcastNotification ( "jamulusclient/recorderState", + QJsonObject{ + {"state", newRecorderState} + } ); + } ); + /// @rpc_method jamulus/pollServerList /// @brief Request list of servers in a directory /// @param {string} params.directory - socket address of directory to query, e.g. anygenre1.jamulus.io:22124. @@ -237,7 +247,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare /// @result {string} result.skillLevel - The musician’s skill level (beginner, intermediate, expert, or null). /// @result {string} result.country - The musician’s country. /// @result {string} result.city - The musician’s city. - /// @result {number} result.instrumentId - The musician’s instrument ID (see CInstPictures::GetTable). + /// @result {number} result.instrument - The musician’s instrument. /// @result {string} result.skillLevel - Your skill level (beginner, intermediate, expert, or null). pRpcServer->HandleMethod ( "jamulusclient/getChannelInfo", [=] ( const QJsonObject& params, QJsonObject& response ) { QJsonObject result{ @@ -245,7 +255,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare { "name", pClient->ChannelInfo.strName }, { "country", QLocale::countryToString ( pClient->ChannelInfo.eCountry ) }, { "city", pClient->ChannelInfo.strCity }, - { "instrumentId", pClient->ChannelInfo.iInstrument }, + { "instrument", CInstPictures::GetName ( pClient->ChannelInfo.iInstrument ) }, { "skillLevel", SerializeSkillLevel ( pClient->ChannelInfo.eSkillLevel ) }, }; response["result"] = result; From 48f2d6bbcce27bbbb55997695d8ca4537ea1fe1c Mon Sep 17 00:00:00 2001 From: riban Date: Mon, 1 Apr 2024 18:05:58 +0100 Subject: [PATCH 09/15] Fixes coding style --- src/client.h | 4 +-- src/clientrpc.cpp | 66 +++++++++++++++++++++-------------------------- 2 files changed, 31 insertions(+), 39 deletions(-) diff --git a/src/client.h b/src/client.h index d6301260b6..bca905493b 100644 --- a/src/client.h +++ b/src/client.h @@ -271,9 +271,7 @@ class CClient : public QObject Channel.GetBufErrorRates ( vecErrRates, dLimit, dMaxUpLimit ); } - CProtocol * getConnLessProtocol() { - return &ConnLessProtocol; - } + CProtocol * getConnLessProtocol() { return &ConnLessProtocol; } // settings CChannelCoreInfo ChannelInfo; diff --git a/src/clientrpc.cpp b/src/clientrpc.cpp index 2366cb8889..9c3ba56ab8 100644 --- a/src/clientrpc.cpp +++ b/src/clientrpc.cpp @@ -101,37 +101,36 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare /// @param {string} params.servers[*].name - Server name /// @param {string} params.servers[*].country - Server country /// @param {string} params.servers[*].city - Server city - connect ( pClient->getConnLessProtocol(), &CProtocol::CLServerListReceived, [=] ( CHostAddress /* unused */, CVector vecServerInfo ) { - QJsonArray arrServerInfo; - for ( const auto& serverInfo : vecServerInfo ) - { - QJsonObject objServerInfo{ - { "address", serverInfo.HostAddr.toString() }, - { "name", serverInfo.strName }, - { "country", QLocale::countryToString ( serverInfo.eCountry) }, - { "city", serverInfo.strCity }, - }; - arrServerInfo.append ( objServerInfo ); - pClient->CreateCLServerListPingMes ( serverInfo.HostAddr ); - } - pRpcServer->BroadcastNotification ( "jamulusclient/serverListReceived", - QJsonObject{ - { "servers", arrServerInfo }, - } ); - } ); + connect ( pClient->getConnLessProtocol(), + &CProtocol::CLServerListReceived, + [=] ( CHostAddress /* unused */, CVector vecServerInfo ) { + QJsonArray arrServerInfo; + for ( const auto& serverInfo : vecServerInfo ) + { + QJsonObject objServerInfo{ + { "address", serverInfo.HostAddr.toString() }, + { "name", serverInfo.strName }, + { "country", QLocale::countryToString ( serverInfo.eCountry ) }, + { "city", serverInfo.strCity }, + }; + arrServerInfo.append ( objServerInfo ); + pClient->CreateCLServerListPingMes ( serverInfo.HostAddr ); + } + pRpcServer->BroadcastNotification ( "jamulusclient/serverListReceived", + QJsonObject{ + { "servers", arrServerInfo }, + } ); + } ); /// @rpc_notification jamulusclient/serverInfoReceived /// @brief Emitted when a server info is received. /// @param {string} params.address - The server socket address /// @param {number} params.pingtime - The round-trip ping time in ms /// @param {number} params.numClients - The quantity of clients connected to the server - connect (pClient, &CClient::CLPingTimeWithNumClientsReceived, [=] ( CHostAddress InetAddr, int iPingTime, int iNumClients ) { - pRpcServer->BroadcastNotification ( "jamulusclient/serverInfoReceived", - QJsonObject{ - {"address", InetAddr.toString()}, - {"pingTime", iPingTime}, - {"numClients", iNumClients} - } ); + connect ( pClient, &CClient::CLPingTimeWithNumClientsReceived, [=] ( CHostAddress InetAddr, int iPingTime, int iNumClients ) { + pRpcServer->BroadcastNotification ( + "jamulusclient/serverInfoReceived", + QJsonObject{ { "address", InetAddr.toString() }, { "pingTime", iPingTime }, { "numClients", iNumClients } } ); } ); /// @rpc_notification jamulusclient/disconnected @@ -143,10 +142,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare /// @brief Emitted when the client is connected to a server who's recorder state changes. /// @param {number} params.state - The recorder state connect ( pClient, &CClient::RecorderStateReceived, [=] ( const ERecorderState newRecorderState ) { - pRpcServer->BroadcastNotification ( "jamulusclient/recorderState", - QJsonObject{ - {"state", newRecorderState} - } ); + pRpcServer->BroadcastNotification ( "jamulusclient/recorderState", QJsonObject{ { "state", newRecorderState } } ); } ); /// @rpc_method jamulus/pollServerList @@ -162,18 +158,16 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare } CHostAddress haDirectoryAddress; - if ( NetworkUtil().ParseNetworkAddress ( - jsonDirectoryIp.toString(), - haDirectoryAddress, - false ) ) + if ( NetworkUtil().ParseNetworkAddress ( jsonDirectoryIp.toString(), haDirectoryAddress, false ) ) { // send the request for the server list - pClient->CreateCLReqServerListMes( haDirectoryAddress ); + pClient->CreateCLReqServerListMes ( haDirectoryAddress ); response["result"] = "ok"; } else { - response["error"] = CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: directory is not a valid socket address" ); + response["error"] = + CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: directory is not a valid socket address" ); } response["result"] = "ok"; @@ -191,7 +185,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare return; } - if ( pClient->SetServerAddr(jsonAddr.toString()) ) + if ( pClient->SetServerAddr( jsonAddr.toString() ) ) { if ( !pClient->IsRunning() ) { From a23fd991b76acba29f8d997cb853a088e2c636f4 Mon Sep 17 00:00:00 2001 From: riban Date: Mon, 1 Apr 2024 18:09:03 +0100 Subject: [PATCH 10/15] Update docs --- docs/JSON-RPC.md | 113 ++++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 56 deletions(-) diff --git a/docs/JSON-RPC.md b/docs/JSON-RPC.md index a6d05cfd23..8d1c86a251 100644 --- a/docs/JSON-RPC.md +++ b/docs/JSON-RPC.md @@ -129,49 +129,43 @@ Results: | result.version | string | The Jamulus version. | -### jamulusclient/getChannelInfo +### jamulus/pollServerList -Returns the client's profile information. +Request list of servers in a directory Parameters: | Name | Type | Description | | --- | --- | --- | -| params | object | No parameters (empty object). | +| params.directory | string | socket address of directory to query, e.g. anygenre1.jamulus.io:22124. | Results: | Name | Type | Description | | --- | --- | --- | -| result.id | number | The channel ID. | -| result.name | string | The musician’s name. | -| result.skillLevel | string | The musician’s skill level (beginner, intermediate, expert, or null). | -| result.countryId | number | The musician’s country ID (see QLocale::Country). | -| result.city | string | The musician’s city. | -| result.instrument | string | The musician’s instrument. | -| result.skillLevel | string | Your skill level (beginner, intermediate, expert, or null). | +| result | string | "ok" or "error" if bad arguments. | -### jamulusclient/getClientInfo +### jamulusclient/connect -Returns the client information. +Disconnect client from server Parameters: | Name | Type | Description | | --- | --- | --- | -| params | object | No parameters (empty object). | +| params.address | string | Server socket address (ip_addr:port). | Results: | Name | Type | Description | | --- | --- | --- | -| result.connected | boolean | Whether the client is connected to the server. | +| result | string | Always "ok". | -### jamulusclient/getClientList +### jamulusclient/disconnect -Returns the client list. +Disconnect client from server Parameters: @@ -183,74 +177,81 @@ Results: | Name | Type | Description | | --- | --- | --- | -| result.clients | array | The client list. See jamulusclient/clientListReceived for the format. | +| result | string | Always "ok". | -### jamulusclient/pollServerList +### jamulusclient/getChannelInfo -Requests the server list from a specified directory. +Returns the client's profile information. Parameters: | Name | Type | Description | | --- | --- | --- | -| params.directory | string | Socket address of directory (hostname:port), e.g. anygenre1.jamulus.io:22124 | +| params | object | No parameters (empty object). | Results: | Name | Type | Description | | --- | --- | --- | -| result | string | "ok" or "error" if invalid socket address | +| result.id | number | The channel ID. | +| result.name | string | The musician’s name. | +| result.skillLevel | string | The musician’s skill level (beginner, intermediate, expert, or null). | +| result.country | string | The musician’s country. | +| result.city | string | The musician’s city. | +| result.instrument | number | The musician’s instrument. | +| result.skillLevel | string | Your skill level (beginner, intermediate, expert, or null). | -### jamulusclient/sendChatText -Sends a chat text message. +### jamulusclient/getClientInfo + +Returns the client information. Parameters: | Name | Type | Description | | --- | --- | --- | -| params.chatText | string | The chat text message. | +| params | object | No parameters (empty object). | Results: | Name | Type | Description | | --- | --- | --- | -| result | string | Always "ok". | +| result.connected | boolean | Whether the client is connected to the server. | -### jamulusclient/connect +### jamulusclient/getClientList -Connect client to a server. +Returns the client list. Parameters: | Name | Type | Description | | --- | --- | --- | -| params.address | string | Server socket address (hostname:port) | +| params | object | No parameters (empty object). | Results: | Name | Type | Description | | --- | --- | --- | -| result | string | "ok" or error if invalid address. +| result.clients | array | The client list. See jamulusclient/clientListReceived for the format. | -### jamulusclient/disconnect +### jamulusclient/sendChatText -Disconnect client from server. +Sends a chat text message. Parameters: | Name | Type | Description | | --- | --- | --- | -| params | object | No parameters (empty object). | +| params.chatText | string | The chat text message. | Results: | Name | Type | Description | | --- | --- | --- | -| result | string | Always "ok". +| result | string | Always "ok". | ### jamulusclient/setName @@ -308,9 +309,9 @@ Results: | result.clients[*].name | string | The client’s name. | | result.clients[*].jitterBufferSize | number | The client’s jitter buffer size. | | result.clients[*].channels | number | The number of audio channels of the client. | -| result.clients[*].instrument | string | The instrument name provided by the user for this channel. | +| result.clients[*].instrumentCode | number | The id of the instrument for this channel. | | result.clients[*].city | string | The city name provided by the user for this channel. | -| result.clients[*].countryName | string | The country name provided by the user for this channel. | +| result.clients[*].countryName | number | The text name of the country specified by the user for this channel (see QLocale::Country). | | result.clients[*].skillLevelCode | number | The skill level id provided by the user for this channel. | @@ -499,64 +500,64 @@ Parameters: | params.clients[*].instrument | string | The musician’s instrument. | -### jamulusclient/serverListReceived +### jamulusclient/connected -Emitted when the server list is received. +Emitted when the client is connected to the server. Parameters: | Name | Type | Description | | --- | --- | --- | -| params.servers | array | The server list. | -| params.servers[*].address | string | The server's socket address (hostname:port). | -| params.servers[*].name | string | The server’s name. | -| params.servers[*].country | string | The servers’s country. | -| params.servers[*].city | string | The server’s city. | +| params.id | number | The channel ID assigned to the client. | -### jamulusclient/serverInfoReceived +### jamulusclient/disconnected -Emitted when a server info is received. +Emitted when the client is disconnected from the server. Parameters: | Name | Type | Description | | --- | --- | --- | -| params.servers[*].address | string | The server's socket address (hostname:port). | -| params.servers[*].pingTime | number | The round-trip ping time in ms. | -| params.servers[*].numClients | number | The quantity of clients connected to the server . | +| params | object | No parameters (empty object). | -### jamulusclient/connected +### jamulusclient/recorderState -Emitted when the client is connected to the server. +Emitted when the client is connected to a server who's recorder state changes. Parameters: | Name | Type | Description | | --- | --- | --- | -| params.id | number | The channel ID assigned to the client. | +| params.state | number | The recorder state | -### jamulusclient/disconnected +### jamulusclient/serverInfoReceived -Emitted when the client is disconnected from the server. +Emitted when a server info is received. Parameters: | Name | Type | Description | | --- | --- | --- | -| params | object | No parameters (empty object). | +| params.address | string | The server socket address | +| params.pingtime | number | The round-trip ping time in ms | +| params.numClients | number | The quantity of clients connected to the server | -### jamulusclient/recorderState +### jamulusclient/serverListReceived -Emitted when the client is connected to a server who's recorder state changes. +Emitted when the server list is received. Parameters: | Name | Type | Description | | --- | --- | --- | -| params.state | number | The recorder state (see ERecorderState). | +| params.servers | array | The server list. | +| params.servers[*].address | string | Socket address (ip_address:port) | +| params.servers[*].name | string | Server name | +| params.servers[*].country | string | Server country | +| params.servers[*].city | string | Server city | From 65329f2502dbe207ac0cbb88835779e228e34852 Mon Sep 17 00:00:00 2001 From: riban Date: Mon, 1 Apr 2024 19:09:40 +0100 Subject: [PATCH 11/15] Fix coding style --- src/client.h | 2 +- src/clientrpc.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client.h b/src/client.h index bca905493b..dfb0e6fa39 100644 --- a/src/client.h +++ b/src/client.h @@ -271,7 +271,7 @@ class CClient : public QObject Channel.GetBufErrorRates ( vecErrRates, dLimit, dMaxUpLimit ); } - CProtocol * getConnLessProtocol() { return &ConnLessProtocol; } + CProtocol* getConnLessProtocol() { return &ConnLessProtocol; } // settings CChannelCoreInfo ChannelInfo; diff --git a/src/clientrpc.cpp b/src/clientrpc.cpp index 9c3ba56ab8..2a3d0c3018 100644 --- a/src/clientrpc.cpp +++ b/src/clientrpc.cpp @@ -185,7 +185,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare return; } - if ( pClient->SetServerAddr( jsonAddr.toString() ) ) + if ( pClient->SetServerAddr ( jsonAddr.toString() ) ) { if ( !pClient->IsRunning() ) { From 2941143caf456af0112a89e8efe2854178509385 Mon Sep 17 00:00:00 2001 From: riban Date: Mon, 1 Apr 2024 19:29:24 +0100 Subject: [PATCH 12/15] Add back in the country and instrument IDs --- docs/JSON-RPC.md | 5 +++++ src/clientrpc.cpp | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/docs/JSON-RPC.md b/docs/JSON-RPC.md index 8d1c86a251..071751bfc1 100644 --- a/docs/JSON-RPC.md +++ b/docs/JSON-RPC.md @@ -197,8 +197,10 @@ Results: | result.id | number | The channel ID. | | result.name | string | The musician’s name. | | result.skillLevel | string | The musician’s skill level (beginner, intermediate, expert, or null). | +| result.countryId | string | The musician’s country ID (see QLocale::Country). | | result.country | string | The musician’s country. | | result.city | string | The musician’s city. | +| result.instrumentId | number | The musician’s instrument ID (see QLocale::Country). | | result.instrument | number | The musician’s instrument. | | result.skillLevel | string | Your skill level (beginner, intermediate, expert, or null). | @@ -495,8 +497,10 @@ Parameters: | params.clients[*].id | number | The channel ID. | | params.clients[*].name | string | The musician’s name. | | params.clients[*].skillLevel | string | The musician’s skill level (beginner, intermediate, expert, or null). | +| params.clients[*].countryId | number | The musician’s country ID (see QLocale::Country). | | params.clients[*].country | string | The musician’s country. | | params.clients[*].city | string | The musician’s city. | +| params.clients[*].instrumentId | string | The musician’s instrument ID (see QLocale::Country).. | | params.clients[*].instrument | string | The musician’s instrument. | @@ -557,6 +561,7 @@ Parameters: | params.servers | array | The server list. | | params.servers[*].address | string | Socket address (ip_address:port) | | params.servers[*].name | string | Server name | +| params.servers[*].countryId | string | Server country ID (see QLocale::Country). | | params.servers[*].country | string | Server country | | params.servers[*].city | string | Server city | diff --git a/src/clientrpc.cpp b/src/clientrpc.cpp index 2a3d0c3018..31cd29d894 100644 --- a/src/clientrpc.cpp +++ b/src/clientrpc.cpp @@ -53,8 +53,10 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare /// @param {number} params.clients[*].id - The channel ID. /// @param {string} params.clients[*].name - The musician’s name. /// @param {string} params.clients[*].skillLevel - The musician’s skill level (beginner, intermediate, expert, or null). + /// @param {number} params.clients[*].countryId - The musician’s country ID (see QLocale::Country). /// @param {string} params.clients[*].country - The musician’s country. /// @param {string} params.clients[*].city - The musician’s city. + /// @param {string} params.clients[*].instrumentId - The musician’s instrument ID (see QLocale::Country).. /// @param {string} params.clients[*].instrument - The musician’s instrument. connect ( pClient, &CClient::ConClientListMesReceived, [=] ( CVector vecChanInfo ) { QJsonArray arrChanInfo; @@ -64,8 +66,10 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare { "id", chanInfo.iChanID }, { "name", chanInfo.strName }, { "skillLevel", SerializeSkillLevel ( chanInfo.eSkillLevel ) }, + { "countryId", chanInfo.eCountry }, { "country", QLocale::countryToString ( chanInfo.eCountry ) }, { "city", chanInfo.strCity }, + { "instrumentId", chanInfo.iInstrument }, { "instrument", CInstPictures::GetName ( chanInfo.iInstrument ) }, }; arrChanInfo.append ( objChanInfo ); @@ -99,6 +103,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare /// @param {array} params.servers - The server list. /// @param {string} params.servers[*].address - Socket address (ip_address:port) /// @param {string} params.servers[*].name - Server name + /// @param {string} params.servers[*].countryId - Server country ID (see QLocale::Country). /// @param {string} params.servers[*].country - Server country /// @param {string} params.servers[*].city - Server city connect ( pClient->getConnLessProtocol(), @@ -110,6 +115,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare QJsonObject objServerInfo{ { "address", serverInfo.HostAddr.toString() }, { "name", serverInfo.strName }, + { "countryId", serverInfo.eCountry }, { "country", QLocale::countryToString ( serverInfo.eCountry ) }, { "city", serverInfo.strCity }, }; @@ -239,16 +245,20 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare /// @result {number} result.id - The channel ID. /// @result {string} result.name - The musician’s name. /// @result {string} result.skillLevel - The musician’s skill level (beginner, intermediate, expert, or null). + /// @result {string} result.countryId - The musician’s country ID (see QLocale::Country). /// @result {string} result.country - The musician’s country. /// @result {string} result.city - The musician’s city. + /// @result {number} result.instrumentId - The musician’s instrument ID (see QLocale::Country). /// @result {number} result.instrument - The musician’s instrument. /// @result {string} result.skillLevel - Your skill level (beginner, intermediate, expert, or null). pRpcServer->HandleMethod ( "jamulusclient/getChannelInfo", [=] ( const QJsonObject& params, QJsonObject& response ) { QJsonObject result{ // TODO: We cannot include "id" here is pClient->ChannelInfo is a CChannelCoreInfo which lacks that field. { "name", pClient->ChannelInfo.strName }, + { "countryId", pClient->ChannelInfo.eCountry }, { "country", QLocale::countryToString ( pClient->ChannelInfo.eCountry ) }, { "city", pClient->ChannelInfo.strCity }, + { "instrumentId", pClient->ChannelInfo.iInstrument }, { "instrument", CInstPictures::GetName ( pClient->ChannelInfo.iInstrument ) }, { "skillLevel", SerializeSkillLevel ( pClient->ChannelInfo.eSkillLevel ) }, }; From 8938ff94c8d1ab595540bde95bf855485d138be1 Mon Sep 17 00:00:00 2001 From: riban Date: Tue, 2 Apr 2024 07:38:59 +0100 Subject: [PATCH 13/15] Fixes docs and coding style --- docs/JSON-RPC.md | 4 ++-- src/clientrpc.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/JSON-RPC.md b/docs/JSON-RPC.md index 071751bfc1..b770ef11a6 100644 --- a/docs/JSON-RPC.md +++ b/docs/JSON-RPC.md @@ -200,7 +200,7 @@ Results: | result.countryId | string | The musician’s country ID (see QLocale::Country). | | result.country | string | The musician’s country. | | result.city | string | The musician’s city. | -| result.instrumentId | number | The musician’s instrument ID (see QLocale::Country). | +| result.instrumentId | number | The musician’s instrument ID (see CInstPictures::GetTable). | | result.instrument | number | The musician’s instrument. | | result.skillLevel | string | Your skill level (beginner, intermediate, expert, or null). | @@ -500,7 +500,7 @@ Parameters: | params.clients[*].countryId | number | The musician’s country ID (see QLocale::Country). | | params.clients[*].country | string | The musician’s country. | | params.clients[*].city | string | The musician’s city. | -| params.clients[*].instrumentId | string | The musician’s instrument ID (see QLocale::Country).. | +| params.clients[*].instrumentId | string | The musician’s instrument ID (see CInstPictures::GetTable). | | params.clients[*].instrument | string | The musician’s instrument. | diff --git a/src/clientrpc.cpp b/src/clientrpc.cpp index 31cd29d894..8c9ad3a86a 100644 --- a/src/clientrpc.cpp +++ b/src/clientrpc.cpp @@ -56,7 +56,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare /// @param {number} params.clients[*].countryId - The musician’s country ID (see QLocale::Country). /// @param {string} params.clients[*].country - The musician’s country. /// @param {string} params.clients[*].city - The musician’s city. - /// @param {string} params.clients[*].instrumentId - The musician’s instrument ID (see QLocale::Country).. + /// @param {string} params.clients[*].instrumentId - The musician’s instrument ID (see CInstPictures::GetTable). /// @param {string} params.clients[*].instrument - The musician’s instrument. connect ( pClient, &CClient::ConClientListMesReceived, [=] ( CVector vecChanInfo ) { QJsonArray arrChanInfo; @@ -248,7 +248,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare /// @result {string} result.countryId - The musician’s country ID (see QLocale::Country). /// @result {string} result.country - The musician’s country. /// @result {string} result.city - The musician’s city. - /// @result {number} result.instrumentId - The musician’s instrument ID (see QLocale::Country). + /// @result {number} result.instrumentId - The musician’s instrument ID (see CInstPictures::GetTable). /// @result {number} result.instrument - The musician’s instrument. /// @result {string} result.skillLevel - Your skill level (beginner, intermediate, expert, or null). pRpcServer->HandleMethod ( "jamulusclient/getChannelInfo", [=] ( const QJsonObject& params, QJsonObject& response ) { @@ -258,7 +258,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare { "countryId", pClient->ChannelInfo.eCountry }, { "country", QLocale::countryToString ( pClient->ChannelInfo.eCountry ) }, { "city", pClient->ChannelInfo.strCity }, - { "instrumentId", pClient->ChannelInfo.iInstrument }, + { "instrumentId", pClient->ChannelInfo.iInstrument }, { "instrument", CInstPictures::GetName ( pClient->ChannelInfo.iInstrument ) }, { "skillLevel", SerializeSkillLevel ( pClient->ChannelInfo.eSkillLevel ) }, }; From 6c6bfe2235617446f0f1a218a1c1cddb3dd0755a Mon Sep 17 00:00:00 2001 From: riban Date: Tue, 2 Apr 2024 08:05:11 +0100 Subject: [PATCH 14/15] Fixes docs --- docs/JSON-RPC.md | 8 ++++---- src/clientrpc.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/JSON-RPC.md b/docs/JSON-RPC.md index b770ef11a6..678cb2496b 100644 --- a/docs/JSON-RPC.md +++ b/docs/JSON-RPC.md @@ -197,11 +197,11 @@ Results: | result.id | number | The channel ID. | | result.name | string | The musician’s name. | | result.skillLevel | string | The musician’s skill level (beginner, intermediate, expert, or null). | -| result.countryId | string | The musician’s country ID (see QLocale::Country). | +| result.countryId | number | The musician’s country ID (see QLocale::Country). | | result.country | string | The musician’s country. | | result.city | string | The musician’s city. | | result.instrumentId | number | The musician’s instrument ID (see CInstPictures::GetTable). | -| result.instrument | number | The musician’s instrument. | +| result.instrument | string | The musician’s instrument. | | result.skillLevel | string | Your skill level (beginner, intermediate, expert, or null). | @@ -500,7 +500,7 @@ Parameters: | params.clients[*].countryId | number | The musician’s country ID (see QLocale::Country). | | params.clients[*].country | string | The musician’s country. | | params.clients[*].city | string | The musician’s city. | -| params.clients[*].instrumentId | string | The musician’s instrument ID (see CInstPictures::GetTable). | +| params.clients[*].instrumentId | number | The musician’s instrument ID (see CInstPictures::GetTable). | | params.clients[*].instrument | string | The musician’s instrument. | @@ -561,7 +561,7 @@ Parameters: | params.servers | array | The server list. | | params.servers[*].address | string | Socket address (ip_address:port) | | params.servers[*].name | string | Server name | -| params.servers[*].countryId | string | Server country ID (see QLocale::Country). | +| params.servers[*].countryId | number | Server country ID (see QLocale::Country). | | params.servers[*].country | string | Server country | | params.servers[*].city | string | Server city | diff --git a/src/clientrpc.cpp b/src/clientrpc.cpp index 8c9ad3a86a..dc958f7844 100644 --- a/src/clientrpc.cpp +++ b/src/clientrpc.cpp @@ -56,7 +56,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare /// @param {number} params.clients[*].countryId - The musician’s country ID (see QLocale::Country). /// @param {string} params.clients[*].country - The musician’s country. /// @param {string} params.clients[*].city - The musician’s city. - /// @param {string} params.clients[*].instrumentId - The musician’s instrument ID (see CInstPictures::GetTable). + /// @param {number} params.clients[*].instrumentId - The musician’s instrument ID (see CInstPictures::GetTable). /// @param {string} params.clients[*].instrument - The musician’s instrument. connect ( pClient, &CClient::ConClientListMesReceived, [=] ( CVector vecChanInfo ) { QJsonArray arrChanInfo; @@ -103,7 +103,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare /// @param {array} params.servers - The server list. /// @param {string} params.servers[*].address - Socket address (ip_address:port) /// @param {string} params.servers[*].name - Server name - /// @param {string} params.servers[*].countryId - Server country ID (see QLocale::Country). + /// @param {number} params.servers[*].countryId - Server country ID (see QLocale::Country). /// @param {string} params.servers[*].country - Server country /// @param {string} params.servers[*].city - Server city connect ( pClient->getConnLessProtocol(), @@ -245,11 +245,11 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare /// @result {number} result.id - The channel ID. /// @result {string} result.name - The musician’s name. /// @result {string} result.skillLevel - The musician’s skill level (beginner, intermediate, expert, or null). - /// @result {string} result.countryId - The musician’s country ID (see QLocale::Country). + /// @result {number} result.countryId - The musician’s country ID (see QLocale::Country). /// @result {string} result.country - The musician’s country. /// @result {string} result.city - The musician’s city. /// @result {number} result.instrumentId - The musician’s instrument ID (see CInstPictures::GetTable). - /// @result {number} result.instrument - The musician’s instrument. + /// @result {string} result.instrument - The musician’s instrument. /// @result {string} result.skillLevel - Your skill level (beginner, intermediate, expert, or null). pRpcServer->HandleMethod ( "jamulusclient/getChannelInfo", [=] ( const QJsonObject& params, QJsonObject& response ) { QJsonObject result{ From 16d88dfa5bc07315ef8a809d7336b757af69ee01 Mon Sep 17 00:00:00 2001 From: riban Date: Tue, 7 May 2024 06:13:41 +0100 Subject: [PATCH 15/15] Fixes some documentation --- docs/JSON-RPC.md | 2 +- src/clientrpc.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/JSON-RPC.md b/docs/JSON-RPC.md index 678cb2496b..b1fd6d08a0 100644 --- a/docs/JSON-RPC.md +++ b/docs/JSON-RPC.md @@ -528,7 +528,7 @@ Parameters: ### jamulusclient/recorderState -Emitted when the client is connected to a server who's recorder state changes. +Emitted when a server's recorder state changes. Parameters: diff --git a/src/clientrpc.cpp b/src/clientrpc.cpp index dc958f7844..b3f3f3cbff 100644 --- a/src/clientrpc.cpp +++ b/src/clientrpc.cpp @@ -180,7 +180,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare } ); /// @rpc_method jamulusclient/connect - /// @brief Disconnect client from server + /// @brief Connect client to server /// @param {string} params.address - Server socket address (ip_addr:port). /// @result {string} result - Always "ok". pRpcServer->HandleMethod ( "jamulusclient/connect", [=] ( const QJsonObject& params, QJsonObject& response ) { @@ -253,7 +253,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare /// @result {string} result.skillLevel - Your skill level (beginner, intermediate, expert, or null). pRpcServer->HandleMethod ( "jamulusclient/getChannelInfo", [=] ( const QJsonObject& params, QJsonObject& response ) { QJsonObject result{ - // TODO: We cannot include "id" here is pClient->ChannelInfo is a CChannelCoreInfo which lacks that field. + // TODO: We cannot include "id" here as pClient->ChannelInfo is a CChannelCoreInfo which lacks that field. { "name", pClient->ChannelInfo.strName }, { "countryId", pClient->ChannelInfo.eCountry }, { "country", QLocale::countryToString ( pClient->ChannelInfo.eCountry ) },