-
Notifications
You must be signed in to change notification settings - Fork 238
Add JSON-RPC access to directories and server lists. #3249
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
Changes from 5 commits
407a290
aa56c27
667191d
0372ce1
cbeb68e
86ed64e
401c9f9
6573b9c
48f2d6b
a23fd99
65329f2
2941143
8938ff9
6c6bfe2
16d88df
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 |
|---|---|---|
|
|
@@ -94,11 +94,67 @@ 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[*].name - Server name | ||
| /// @param {number} params.servers[*].countryId - Server country code | ||
| /// @param {string} params.servers[*].city - Server city | ||
| connect ( pClient->getConnLessProtocol(), &CProtocol::CLServerListReceived, [=] ( CHostAddress /* unused */, CVector<CServerInfo> vecServerInfo ) { | ||
| QJsonArray arrServerInfo; | ||
| for ( const auto& serverInfo : vecServerInfo ) | ||
| { | ||
| QJsonObject objServerInfo{ | ||
| { "url", serverInfo.HostAddr.toString() }, | ||
| { "name", serverInfo.strName }, | ||
| { "countryI", 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/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 - "ok" or "error" if bad arguments. | ||
| pRpcServer->HandleMethod ( "jamulus/pollServerList", [=] ( 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" ); | ||
riban-bw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return; | ||
| } | ||
|
|
||
| CHostAddress haDirectoryAddress; | ||
| if ( NetworkUtil().ParseNetworkAddress ( | ||
| jsonDirectoryIp.toString(), | ||
| haDirectoryAddress, | ||
| false ) ) | ||
| { | ||
| // 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"; | ||
ann0see marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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). | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.