Skip to content

Commit

Permalink
Extend jamulusserver/getClients RPC method
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob-NY committed Nov 9, 2022
1 parent d2052e9 commit dbfb722
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 20 deletions.
8 changes: 8 additions & 0 deletions docs/JSON-RPC.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,20 @@ Results:

| Name | Type | Description |
| --- | --- | --- |
| result.connections | number | The number of active connections. |
| result.clients | array | The list of connected clients. |
| result.clients[*].id | number | The client’s channel id. |
| result.clients[*].address | string | The client’s address (ip:port). |
| 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[*].instrumentName | number | The text name of the instrument for this channel. |
| result.clients[*].city | string | The city name provided by the user for this channel. |
| result.clients[*].countryCode | number | The id of the country specified by the user for this channel (see QLocale::Country). |
| 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. |
| result.clients[*].skillLevelName | number | The skill level text name provided by the user for this channel. |


### jamulusserver/getRecorderStatus
Expand Down
10 changes: 6 additions & 4 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1469,16 +1469,18 @@ bool CServer::PutAudioData ( const CVector<uint8_t>& vecbyRecBuf, const int iNum
return bNewConnection;
}

void CServer::GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
CVector<QString>& vecsName,
CVector<int>& veciJitBufNumFrames,
CVector<int>& veciNetwFrameSizeFact )
void CServer::GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
CVector<QString>& vecsName,
CVector<int>& veciJitBufNumFrames,
CVector<int>& veciNetwFrameSizeFact,
CVector<CChannelCoreInfo>& vecChanInfo )
{
// init return values
vecHostAddresses.Init ( iMaxNumChannels );
vecsName.Init ( iMaxNumChannels );
veciJitBufNumFrames.Init ( iMaxNumChannels );
veciNetwFrameSizeFact.Init ( iMaxNumChannels );
vecChanInfo.Init ( iMaxNumChannels );

// check all possible channels
for ( int i = 0; i < iMaxNumChannels; i++ )
Expand Down
9 changes: 5 additions & 4 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,11 @@ class CServer : public QObject, public CServerSlots<MAX_NUM_CHANNELS>

int GetNumberOfConnectedClients();

void GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
CVector<QString>& vecsName,
CVector<int>& veciJitBufNumFrames,
CVector<int>& veciNetwFrameSizeFact );
void GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
CVector<QString>& vecsName,
CVector<int>& veciJitBufNumFrames,
CVector<int>& veciNetwFrameSizeFact,
CVector<CChannelCoreInfo>& vecChanInfo );

void CreateCLServerListReqVerAndOSMes ( const CHostAddress& InetAddr ) { ConnLessProtocol.CreateCLReqVersionAndOSMes ( InetAddr ); }

Expand Down
11 changes: 6 additions & 5 deletions src/serverdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,14 +681,15 @@ void CServerDlg::OnCLVersionAndOSReceived ( CHostAddress, COSUtil::EOpSystemType

void CServerDlg::OnTimer()
{
CVector<CHostAddress> vecHostAddresses;
CVector<QString> vecsName;
CVector<int> veciJitBufNumFrames;
CVector<int> veciNetwFrameSizeFact;
CVector<CHostAddress> vecHostAddresses;
CVector<QString> vecsName;
CVector<int> veciJitBufNumFrames;
CVector<int> veciNetwFrameSizeFact;
CVector<CChannelCoreInfo> vecChanInfo;

ListViewMutex.lock();
{
pServer->GetConCliParam ( vecHostAddresses, vecsName, veciJitBufNumFrames, veciNetwFrameSizeFact );
pServer->GetConCliParam ( vecHostAddresses, vecsName, veciJitBufNumFrames, veciNetwFrameSizeFact, vecChanInfo );

// we assume that all vectors have the same length
const int iNumChannels = vecHostAddresses.Size();
Expand Down
36 changes: 29 additions & 7 deletions src/serverrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,31 @@ CServerRpc::CServerRpc ( CServer* pServer, CRpcServer* pRpcServer, QObject* pare
/// @rpc_method jamulusserver/getClients
/// @brief Returns the list of connected clients along with details about them.
/// @param {object} params - No parameters (empty object).
/// @result {array} result.clients - The list of connected clients.
/// @result {number} result.connections - The number of active connections.
/// @result {array} result.clients - The list of connected clients.
/// @result {number} result.clients[*].id - The client’s channel id.
/// @result {string} result.clients[*].address - The client’s address (ip:port).
/// @result {string} result.clients[*].name - The client’s name.
/// @result {number} result.clients[*].jitterBufferSize - The client’s jitter buffer size.
/// @result {number} result.clients[*].channels - The number of audio channels of the client.
/// @result {number} result.clients[*].instrumentCode - The id of the instrument for this channel.
/// @result {number} result.clients[*].instrumentName - The text name of the instrument for this channel.
/// @result {string} result.clients[*].city - The city name provided by the user for this channel.
/// @result {number} result.clients[*].countryCode - The id of the country specified by the user for this channel (see QLocale::Country).
/// @result {number} result.clients[*].countryName - The text name of the country specified by the user for this channel (see QLocale::Country).
/// @result {number} result.clients[*].skillLevelCode - The skill level id provided by the user for this channel.
/// @result {number} result.clients[*].skillLevelName - The skill level text name provided by the user for this channel.
pRpcServer->HandleMethod ( "jamulusserver/getClients", [=] ( const QJsonObject& params, QJsonObject& response ) {
QJsonArray clients;
CVector<CHostAddress> vecHostAddresses;
CVector<QString> vecsName;
CVector<int> veciJitBufNumFrames;
CVector<int> veciNetwFrameSizeFact;
QJsonArray clients;
CVector<CHostAddress> vecHostAddresses;
CVector<QString> vecsName;
CVector<int> veciJitBufNumFrames;
CVector<int> veciNetwFrameSizeFact;
CVector<CChannelCoreInfo> vecChanInfo;

pServer->GetConCliParam ( vecHostAddresses, vecsName, veciJitBufNumFrames, veciNetwFrameSizeFact );
int connections = 0;

pServer->GetConCliParam ( vecHostAddresses, vecsName, veciJitBufNumFrames, veciNetwFrameSizeFact, vecChanInfo );

// we assume that all vectors have the same length
const int iNumChannels = vecHostAddresses.Size();
Expand All @@ -81,18 +92,29 @@ CServerRpc::CServerRpc ( CServer* pServer, CRpcServer* pRpcServer, QObject* pare
{
continue;
}

QJsonObject client{
{ "id", i },
{ "address", vecHostAddresses[i].toString ( CHostAddress::SM_IP_PORT ) },
{ "name", vecsName[i] },
{ "jitterBufferSize", veciJitBufNumFrames[i] },
{ "channels", pServer->GetClientNumAudioChannels ( i ) },
{ "instrumentCode", vecChanInfo[i].iInstrument },
{ "instrumentName", CInstPictures::GetName ( vecChanInfo[i].iInstrument ) },
{ "city", vecChanInfo[i].strCity },
{ "countryCode", vecChanInfo[i].eCountry },
{ "countryName", QLocale::countryToString ( vecChanInfo[i].eCountry ) },
{ "skillLevelCode", vecChanInfo[i].eSkillLevel },
{ "skillLevelName", SkillLevelToString ( vecChanInfo[i].eSkillLevel ) },
};
clients.append ( client );

++connections;
}

// create result object
QJsonObject result{
{ "connections", connections },
{ "clients", clients },
};
response["result"] = result;
Expand Down
21 changes: 21 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,27 @@ enum ESkillLevel
SL_PROFESSIONAL = 3
};

inline QString SkillLevelToString ( const int iSkill )
{
switch ( iSkill )
{
case SL_BEGINNER:
return QCoreApplication::translate ( "CServerDlg", "Beginner" );
break;

case SL_INTERMEDIATE:
return QCoreApplication::translate ( "CServerDlg", "Intermediate" );
break;

case SL_PROFESSIONAL:
return QCoreApplication::translate ( "CServerDlg", "Expert" );
break;

default:
return QString ( "" );
}
}

// define the GUI RGB colors for each skill level
#define RGBCOL_R_SL_NOT_SET 255
#define RGBCOL_G_SL_NOT_SET 255
Expand Down

0 comments on commit dbfb722

Please sign in to comment.