@@ -54,8 +54,10 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare
5454 // / @param {string} params.clients[*].name - The musician’s name.
5555 // / @param {string} params.clients[*].skillLevel - The musician’s skill level (beginner, intermediate, expert, or null).
5656 // / @param {number} params.clients[*].countryId - The musician’s country ID (see QLocale::Country).
57+ // / @param {string} params.clients[*].country - The musician’s country.
5758 // / @param {string} params.clients[*].city - The musician’s city.
5859 // / @param {number} params.clients[*].instrumentId - The musician’s instrument ID (see CInstPictures::GetTable).
60+ // / @param {string} params.clients[*].instrument - The musician’s instrument.
5961 connect ( pClient, &CClient::ConClientListMesReceived, [=] ( CVector<CChannelInfo> vecChanInfo ) {
6062 QJsonArray arrChanInfo;
6163 for ( const auto & chanInfo : vecChanInfo )
@@ -65,8 +67,10 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare
6567 { " name" , chanInfo.strName },
6668 { " skillLevel" , SerializeSkillLevel ( chanInfo.eSkillLevel ) },
6769 { " countryId" , chanInfo.eCountry },
70+ { " country" , QLocale::countryToString ( chanInfo.eCountry ) },
6871 { " city" , chanInfo.strCity },
6972 { " instrumentId" , chanInfo.iInstrument },
73+ { " instrument" , CInstPictures::GetName ( chanInfo.iInstrument ) },
7074 };
7175 arrChanInfo.append ( objChanInfo );
7276 }
@@ -94,11 +98,87 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare
9498 } );
9599 } );
96100
101+ // / @rpc_notification jamulusclient/serverListReceived
102+ // / @brief Emitted when the server list is received.
103+ // / @param {array} params.servers - The server list.
104+ // / @param {string} params.servers[*].address - Socket address (ip_address:port).
105+ // / @param {string} params.servers[*].name - Server name.
106+ // / @param {number} params.servers[*].countryId - Server country ID (see QLocale::Country).
107+ // / @param {string} params.servers[*].country - Server country.
108+ // / @param {string} params.servers[*].city - Server city.
109+ connect ( pClient->getConnLessProtocol (),
110+ &CProtocol::CLServerListReceived,
111+ [=] ( CHostAddress /* unused */ , CVector<CServerInfo> vecServerInfo ) {
112+ QJsonArray arrServerInfo;
113+ for ( const auto & serverInfo : vecServerInfo )
114+ {
115+ QJsonObject objServerInfo{
116+ { " address" , serverInfo.HostAddr .toString () },
117+ { " name" , serverInfo.strName },
118+ { " countryId" , serverInfo.eCountry },
119+ { " country" , QLocale::countryToString ( serverInfo.eCountry ) },
120+ { " city" , serverInfo.strCity },
121+ };
122+ arrServerInfo.append ( objServerInfo );
123+ pClient->CreateCLServerListPingMes ( serverInfo.HostAddr );
124+ }
125+ pRpcServer->BroadcastNotification ( " jamulusclient/serverListReceived" ,
126+ QJsonObject{
127+ { " servers" , arrServerInfo },
128+ } );
129+ } );
130+
131+ // / @rpc_notification jamulusclient/serverInfoReceived
132+ // / @brief Emitted when a server info is received.
133+ // / @param {string} params.address - The server socket address.
134+ // / @param {number} params.pingtime - The round-trip ping time, in milliseconds.
135+ // / @param {number} params.numClients - The number of clients connected to the server.
136+ connect ( pClient, &CClient::CLPingTimeWithNumClientsReceived, [=] ( CHostAddress InetAddr, int iPingTime, int iNumClients ) {
137+ pRpcServer->BroadcastNotification (
138+ " jamulusclient/serverInfoReceived" ,
139+ QJsonObject{ { " address" , InetAddr.toString () }, { " pingTime" , iPingTime }, { " numClients" , iNumClients } } );
140+ } );
141+
97142 // / @rpc_notification jamulusclient/disconnected
98143 // / @brief Emitted when the client is disconnected from the server.
99144 // / @param {object} params - No parameters (empty object).
100145 connect ( pClient, &CClient::Disconnected, [=]() { pRpcServer->BroadcastNotification ( " jamulusclient/disconnected" , QJsonObject{} ); } );
101146
147+ // / @rpc_notification jamulusclient/recorderState
148+ // / @brief Emitted when the client is connected to a server whose recorder state changes.
149+ // / @param {number} params.state - The recorder state.
150+ connect ( pClient, &CClient::RecorderStateReceived, [=] ( const ERecorderState newRecorderState ) {
151+ pRpcServer->BroadcastNotification ( " jamulusclient/recorderState" , QJsonObject{ { " state" , newRecorderState } } );
152+ } );
153+
154+ // / @rpc_method jamulusclient/pollServerList
155+ // / @brief Request list of servers in a directory.
156+ // / @param {string} params.directory - Socket address of directory to query. Example: anygenre1.jamulus.io:22124
157+ // / @result {string} result - "ok" or "error" if bad arguments.
158+ pRpcServer->HandleMethod ( " jamulusclient/pollServerList" , [=] ( const QJsonObject& params, QJsonObject& response ) {
159+ auto jsonDirectoryIp = params[" directory" ];
160+ if ( !jsonDirectoryIp.isString () )
161+ {
162+ response[" error" ] = CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, " Invalid params: directory is not a string" );
163+ return ;
164+ }
165+
166+ CHostAddress haDirectoryAddress;
167+ if ( NetworkUtil ().ParseNetworkAddress ( jsonDirectoryIp.toString (), haDirectoryAddress, false ) )
168+ {
169+ // send the request for the server list
170+ pClient->CreateCLReqServerListMes ( haDirectoryAddress );
171+ response[" result" ] = " ok" ;
172+ }
173+ else
174+ {
175+ response[" error" ] =
176+ CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, " Invalid params: directory is not a valid socket address" );
177+ }
178+
179+ response[" result" ] = " ok" ;
180+ } );
181+
102182 // / @rpc_method jamulus/getMode
103183 // / @brief Returns the current mode, i.e. whether Jamulus is running as a server or client.
104184 // / @param {object} params - No parameters (empty object).
@@ -126,16 +206,20 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare
126206 // / @result {string} result.name - The musician’s name.
127207 // / @result {string} result.skillLevel - The musician’s skill level (beginner, intermediate, expert, or null).
128208 // / @result {number} result.countryId - The musician’s country ID (see QLocale::Country).
209+ // / @result {string} result.country - The musician’s country.
129210 // / @result {string} result.city - The musician’s city.
130211 // / @result {number} result.instrumentId - The musician’s instrument ID (see CInstPictures::GetTable).
212+ // / @result {string} result.instrument - The musician’s instrument.
131213 // / @result {string} result.skillLevel - Your skill level (beginner, intermediate, expert, or null).
132214 pRpcServer->HandleMethod ( " jamulusclient/getChannelInfo" , [=] ( const QJsonObject& params, QJsonObject& response ) {
133215 QJsonObject result{
134216 // TODO: We cannot include "id" here is pClient->ChannelInfo is a CChannelCoreInfo which lacks that field.
135217 { " name" , pClient->ChannelInfo .strName },
136218 { " countryId" , pClient->ChannelInfo .eCountry },
219+ { " country" , QLocale::countryToString ( pClient->ChannelInfo .eCountry ) },
137220 { " city" , pClient->ChannelInfo .strCity },
138221 { " instrumentId" , pClient->ChannelInfo .iInstrument },
222+ { " instrument" , CInstPictures::GetName ( pClient->ChannelInfo .iInstrument ) },
139223 { " skillLevel" , SerializeSkillLevel ( pClient->ChannelInfo .eSkillLevel ) },
140224 };
141225 response[" result" ] = result;
0 commit comments