Skip to content

Commit 9c95bed

Browse files
committed
Remove connect/disconnect methods and refactor code
These methods unfortunately break the GUI if called Re-add ids Co-authored-by: Tony Mountifield <[email protected]> Apply stylistic changes Co-authored-by: mcfnord <[email protected]> Rename wrongly named method
1 parent ec57457 commit 9c95bed

File tree

3 files changed

+58
-114
lines changed

3 files changed

+58
-114
lines changed

docs/JSON-RPC.md

Lines changed: 32 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -129,57 +129,6 @@ Results:
129129
| result.version | string | The Jamulus version. |
130130

131131

132-
### jamulus/pollServerList
133-
134-
Request list of servers in a directory
135-
136-
Parameters:
137-
138-
| Name | Type | Description |
139-
| --- | --- | --- |
140-
| params.directory | string | socket address of directory to query, e.g. anygenre1.jamulus.io:22124. |
141-
142-
Results:
143-
144-
| Name | Type | Description |
145-
| --- | --- | --- |
146-
| result | string | "ok" or "error" if bad arguments. |
147-
148-
149-
### jamulusclient/connect
150-
151-
Disconnect client from server
152-
153-
Parameters:
154-
155-
| Name | Type | Description |
156-
| --- | --- | --- |
157-
| params.address | string | Server socket address (ip_addr:port). |
158-
159-
Results:
160-
161-
| Name | Type | Description |
162-
| --- | --- | --- |
163-
| result | string | Always "ok". |
164-
165-
166-
### jamulusclient/disconnect
167-
168-
Disconnect client from server
169-
170-
Parameters:
171-
172-
| Name | Type | Description |
173-
| --- | --- | --- |
174-
| params | object | No parameters (empty object). |
175-
176-
Results:
177-
178-
| Name | Type | Description |
179-
| --- | --- | --- |
180-
| result | string | Always "ok". |
181-
182-
183132
### jamulusclient/getChannelInfo
184133

185134
Returns the client's profile information.
@@ -197,9 +146,11 @@ Results:
197146
| result.id | number | The channel ID. |
198147
| result.name | string | The musician’s name. |
199148
| result.skillLevel | string | The musician’s skill level (beginner, intermediate, expert, or null). |
149+
| result.countryId | number | The musician’s country ID (see QLocale::Country). |
200150
| result.country | string | The musician’s country. |
201151
| result.city | string | The musician’s city. |
202-
| result.instrument | number | The musician’s instrument. |
152+
| result.instrumentId | number | The musician’s instrument ID (see CInstPictures::GetTable). |
153+
| result.instrument | string | The musician’s instrument. |
203154
| result.skillLevel | string | Your skill level (beginner, intermediate, expert, or null). |
204155

205156

@@ -237,6 +188,23 @@ Results:
237188
| result.clients | array | The client list. See jamulusclient/clientListReceived for the format. |
238189

239190

191+
### jamulusclient/pollServerList
192+
193+
Request list of servers in a directory.
194+
195+
Parameters:
196+
197+
| Name | Type | Description |
198+
| --- | --- | --- |
199+
| params.directory | string | Socket address of directory to query. Example: anygenre1.jamulus.io:22124 |
200+
201+
Results:
202+
203+
| Name | Type | Description |
204+
| --- | --- | --- |
205+
| result | string | "ok" or "error" if bad arguments. |
206+
207+
240208
### jamulusclient/sendChatText
241209

242210
Sends a chat text message.
@@ -495,8 +463,10 @@ Parameters:
495463
| params.clients[*].id | number | The channel ID. |
496464
| params.clients[*].name | string | The musician’s name. |
497465
| params.clients[*].skillLevel | string | The musician’s skill level (beginner, intermediate, expert, or null). |
466+
| params.clients[*].countryId | number | The musician’s country ID (see QLocale::Country). |
498467
| params.clients[*].country | string | The musician’s country. |
499468
| params.clients[*].city | string | The musician’s city. |
469+
| params.clients[*].instrumentId | number | The musician’s instrument ID (see CInstPictures::GetTable). |
500470
| params.clients[*].instrument | string | The musician’s instrument. |
501471

502472

@@ -524,13 +494,13 @@ Parameters:
524494

525495
### jamulusclient/recorderState
526496

527-
Emitted when the client is connected to a server who's recorder state changes.
497+
Emitted when the client is connected to a server whose recorder state changes.
528498

529499
Parameters:
530500

531501
| Name | Type | Description |
532502
| --- | --- | --- |
533-
| params.state | number | The recorder state |
503+
| params.state | number | The recorder state. |
534504

535505

536506
### jamulusclient/serverInfoReceived
@@ -541,9 +511,9 @@ Parameters:
541511

542512
| Name | Type | Description |
543513
| --- | --- | --- |
544-
| params.address | string | The server socket address |
545-
| params.pingtime | number | The round-trip ping time in ms |
546-
| params.numClients | number | The quantity of clients connected to the server |
514+
| params.address | string | The server socket address. |
515+
| params.pingtime | number | The round-trip ping time, in milliseconds. |
516+
| params.numClients | number | The number of clients connected to the server. |
547517

548518

549519
### jamulusclient/serverListReceived
@@ -555,9 +525,10 @@ Parameters:
555525
| Name | Type | Description |
556526
| --- | --- | --- |
557527
| params.servers | array | The server list. |
558-
| params.servers[*].address | string | Socket address (ip_address:port) |
559-
| params.servers[*].name | string | Server name |
560-
| params.servers[*].country | string | Server country |
561-
| params.servers[*].city | string | Server city |
528+
| params.servers[*].address | string | Socket address (ip_address:port). |
529+
| params.servers[*].name | string | Server name. |
530+
| params.servers[*].countryId | number | Server country ID (see QLocale::Country). |
531+
| params.servers[*].country | string | Server country. |
532+
| params.servers[*].city | string | Server city. |
562533

563534

src/client.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,10 @@ class CClient : public QObject
286286
Channel.GetBufErrorRates ( vecErrRates, dLimit, dMaxUpLimit );
287287
}
288288

289+
//### TODO: BEGIN ###//
290+
// Refactor this to use signal/slot mechanism. https://github.com/jamulussoftware/jamulus/pull/3479/files#r1976382416
289291
CProtocol* getConnLessProtocol() { return &ConnLessProtocol; }
292+
//### TODO: END ###//
290293

291294
// settings
292295
CChannelCoreInfo ChannelInfo;

src/clientrpc.cpp

Lines changed: 23 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare
5353
/// @param {number} params.clients[*].id - The channel ID.
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).
56+
/// @param {number} params.clients[*].countryId - The musician’s country ID (see QLocale::Country).
5657
/// @param {string} params.clients[*].country - The musician’s country.
5758
/// @param {string} params.clients[*].city - The musician’s city.
59+
/// @param {number} params.clients[*].instrumentId - The musician’s instrument ID (see CInstPictures::GetTable).
5860
/// @param {string} params.clients[*].instrument - The musician’s instrument.
5961
connect ( pClient, &CClient::ConClientListMesReceived, [=] ( CVector<CChannelInfo> vecChanInfo ) {
6062
QJsonArray arrChanInfo;
@@ -64,8 +66,10 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare
6466
{ "id", chanInfo.iChanID },
6567
{ "name", chanInfo.strName },
6668
{ "skillLevel", SerializeSkillLevel ( chanInfo.eSkillLevel ) },
69+
{ "countryId", chanInfo.eCountry },
6770
{ "country", QLocale::countryToString ( chanInfo.eCountry ) },
6871
{ "city", chanInfo.strCity },
72+
{ "instrumentId", chanInfo.iInstrument },
6973
{ "instrument", CInstPictures::GetName ( chanInfo.iInstrument ) },
7074
};
7175
arrChanInfo.append ( objChanInfo );
@@ -97,10 +101,11 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare
97101
/// @rpc_notification jamulusclient/serverListReceived
98102
/// @brief Emitted when the server list is received.
99103
/// @param {array} params.servers - The server list.
100-
/// @param {string} params.servers[*].address - Socket address (ip_address:port)
101-
/// @param {string} params.servers[*].name - Server name
102-
/// @param {string} params.servers[*].country - Server country
103-
/// @param {string} params.servers[*].city - Server city
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.
104109
connect ( pClient->getConnLessProtocol(),
105110
&CProtocol::CLServerListReceived,
106111
[=] ( CHostAddress /* unused */, CVector<CServerInfo> vecServerInfo ) {
@@ -110,6 +115,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare
110115
QJsonObject objServerInfo{
111116
{ "address", serverInfo.HostAddr.toString() },
112117
{ "name", serverInfo.strName },
118+
{ "countryId", serverInfo.eCountry },
113119
{ "country", QLocale::countryToString ( serverInfo.eCountry ) },
114120
{ "city", serverInfo.strCity },
115121
};
@@ -124,9 +130,9 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare
124130

125131
/// @rpc_notification jamulusclient/serverInfoReceived
126132
/// @brief Emitted when a server info is received.
127-
/// @param {string} params.address - The server socket address
128-
/// @param {number} params.pingtime - The round-trip ping time in ms
129-
/// @param {number} params.numClients - The quantity of clients connected to the server
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.
130136
connect ( pClient, &CClient::CLPingTimeWithNumClientsReceived, [=] ( CHostAddress InetAddr, int iPingTime, int iNumClients ) {
131137
pRpcServer->BroadcastNotification (
132138
"jamulusclient/serverInfoReceived",
@@ -139,15 +145,15 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare
139145
connect ( pClient, &CClient::Disconnected, [=]() { pRpcServer->BroadcastNotification ( "jamulusclient/disconnected", QJsonObject{} ); } );
140146

141147
/// @rpc_notification jamulusclient/recorderState
142-
/// @brief Emitted when the client is connected to a server who's recorder state changes.
143-
/// @param {number} params.state - The recorder state
148+
/// @brief Emitted when the client is connected to a server whose recorder state changes.
149+
/// @param {number} params.state - The recorder state.
144150
connect ( pClient, &CClient::RecorderStateReceived, [=] ( const ERecorderState newRecorderState ) {
145151
pRpcServer->BroadcastNotification ( "jamulusclient/recorderState", QJsonObject{ { "state", newRecorderState } } );
146152
} );
147153

148-
/// @rpc_method jamulus/pollServerList
149-
/// @brief Request list of servers in a directory
150-
/// @param {string} params.directory - socket address of directory to query, e.g. anygenre1.jamulus.io:22124.
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
151157
/// @result {string} result - "ok" or "error" if bad arguments.
152158
pRpcServer->HandleMethod ( "jamulusclient/pollServerList", [=] ( const QJsonObject& params, QJsonObject& response ) {
153159
auto jsonDirectoryIp = params["directory"];
@@ -173,46 +179,6 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare
173179
response["result"] = "ok";
174180
} );
175181

176-
/// @rpc_method jamulusclient/connect
177-
/// @brief Disconnect client from server
178-
/// @param {string} params.address - Server socket address (ip_addr:port).
179-
/// @result {string} result - Always "ok".
180-
pRpcServer->HandleMethod ( "jamulusclient/connect", [=] ( const QJsonObject& params, QJsonObject& response ) {
181-
auto jsonAddr = params["address"];
182-
if ( !jsonAddr.isString() )
183-
{
184-
response["error"] = CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: address is not a string" );
185-
return;
186-
}
187-
188-
if ( pClient->SetServerAddr ( jsonAddr.toString() ) )
189-
{
190-
if ( !pClient->IsRunning() )
191-
{
192-
pClient->Start();
193-
}
194-
response["result"] = "ok";
195-
}
196-
else
197-
{
198-
response["error"] = CRpcServer::CreateJsonRpcError ( 1, "Bad server address" );
199-
}
200-
} );
201-
202-
/// @rpc_method jamulusclient/disconnect
203-
/// @brief Disconnect client from server
204-
/// @param {object} params - No parameters (empty object).
205-
/// @result {string} result - Always "ok".
206-
pRpcServer->HandleMethod ( "jamulusclient/disconnect", [=] ( const QJsonObject& params, QJsonObject& response ) {
207-
if ( pClient->IsRunning() )
208-
{
209-
pClient->Stop();
210-
}
211-
212-
response["result"] = "ok";
213-
Q_UNUSED ( params );
214-
} );
215-
216182
/// @rpc_method jamulus/getMode
217183
/// @brief Returns the current mode, i.e. whether Jamulus is running as a server or client.
218184
/// @param {object} params - No parameters (empty object).
@@ -239,16 +205,20 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare
239205
/// @result {number} result.id - The channel ID.
240206
/// @result {string} result.name - The musician’s name.
241207
/// @result {string} result.skillLevel - The musician’s skill level (beginner, intermediate, expert, or null).
208+
/// @result {number} result.countryId - The musician’s country ID (see QLocale::Country).
242209
/// @result {string} result.country - The musician’s country.
243210
/// @result {string} result.city - The musician’s city.
244-
/// @result {number} result.instrument - The musician’s instrument.
211+
/// @result {number} result.instrumentId - The musician’s instrument ID (see CInstPictures::GetTable).
212+
/// @result {string} result.instrument - The musician’s instrument.
245213
/// @result {string} result.skillLevel - Your skill level (beginner, intermediate, expert, or null).
246214
pRpcServer->HandleMethod ( "jamulusclient/getChannelInfo", [=] ( const QJsonObject& params, QJsonObject& response ) {
247215
QJsonObject result{
248216
// TODO: We cannot include "id" here is pClient->ChannelInfo is a CChannelCoreInfo which lacks that field.
249217
{ "name", pClient->ChannelInfo.strName },
218+
{ "countryId", pClient->ChannelInfo.eCountry },
250219
{ "country", QLocale::countryToString ( pClient->ChannelInfo.eCountry ) },
251220
{ "city", pClient->ChannelInfo.strCity },
221+
{ "instrumentId", pClient->ChannelInfo.iInstrument },
252222
{ "instrument", CInstPictures::GetName ( pClient->ChannelInfo.iInstrument ) },
253223
{ "skillLevel", SerializeSkillLevel ( pClient->ChannelInfo.eSkillLevel ) },
254224
};

0 commit comments

Comments
 (0)