Skip to content

Commit

Permalink
JSON-RPC enhancements
Browse files Browse the repository at this point in the history
Adds method jamulusclient/recorderState.
Changes intrument code to instrument name (remote client may not have access to lookup table).
Fixes errors in docs.
  • Loading branch information
riban-bw committed Mar 25, 2024
1 parent 401c9f9 commit 6573b9c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
21 changes: 16 additions & 5 deletions docs/JSON-RPC.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). |


Expand Down Expand Up @@ -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. |


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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). |


18 changes: 14 additions & 4 deletions src/clientrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CChannelInfo> vecChanInfo ) {
QJsonArray arrChanInfo;
for ( const auto& chanInfo : vecChanInfo )
Expand All @@ -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 );
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -237,15 +247,15 @@ 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{
// TODO: We cannot include "id" here is pClient->ChannelInfo is a CChannelCoreInfo which lacks that field.
{ "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;
Expand Down

0 comments on commit 6573b9c

Please sign in to comment.