Skip to content

Commit cecdea1

Browse files
jrdclaude
andcommitted
JSON-RPC: add optional directory hole punch to jamulusclient/connect
Mirror the new --connectdirectory option on the RPC side: connect now accepts an optional "directory" param. When given, CClient::Connect hole-punches through that directory (CLM_REQ_SERVER_LIST) before connecting, so an RPC-driven client can reach a server behind a cloud firewall/NAT the same way the GUI directory list does. A non-string directory is rejected with invalid params; the server address is connected to verbatim and need not be listed by the directory. docs/JSON-RPC.md regenerated via tools/generate_json_rpc_docs.py. Relates to jamulussoftware/jamuluswebsite#1122 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent c1b6bb0 commit cecdea1

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

docs/JSON-RPC.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ Parameters:
139139
| --- | --- | --- |
140140
| params.address | string | Socket address of the server (host:port). |
141141
| params.serverName | string | Optional human readable server name used for display purposes. Defaults to the address. |
142+
| params.directory | string | Optional socket address of a directory to hole-punch through before connecting (host:port). Use for a server behind a cloud firewall/NAT that is registered with that directory; address is connected to verbatim and need not be listed by the directory. Example: anygenre1.jamulus.io:22124 |
142143

143144
Results:
144145

src/clientrpc.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ CClientRpc::CClientRpc ( CClient* pClient, CClientSettings* pSettings, CRpcServe
257257
/// notifications to follow its progress.
258258
/// @param {string} params.address - Socket address of the server (host:port).
259259
/// @param {string} params.serverName - Optional human readable server name used for display purposes. Defaults to the address.
260+
/// @param {string} params.directory - Optional socket address of a directory to hole-punch through before
261+
/// connecting (host:port). Use for a server behind a cloud firewall/NAT that is registered with that
262+
/// directory; address is connected to verbatim and need not be listed by the directory. Example:
263+
/// anygenre1.jamulus.io:22124
260264
/// @result {string} result - "ok" once the connection attempt has been initiated.
261265
pRpcServer->HandleMethod ( "jamulusclient/connect", [=] ( const QJsonObject& params, QJsonObject& response ) {
262266
auto jsonAddress = params["address"];
@@ -266,11 +270,19 @@ CClientRpc::CClientRpc ( CClient* pClient, CClientSettings* pSettings, CRpcServe
266270
return;
267271
}
268272

273+
auto jsonDirectory = params["directory"];
274+
if ( !jsonDirectory.isUndefined() && !jsonDirectory.isNull() && !jsonDirectory.isString() )
275+
{
276+
response["error"] = CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: directory is not a string" );
277+
return;
278+
}
279+
269280
auto jsonServerName = params["serverName"];
270281
const QString strAddress = NetworkUtil::FixAddress ( jsonAddress.toString() );
271282
const QString strServerName = jsonServerName.isString() ? jsonServerName.toString() : strAddress;
283+
const QString strDirectory = jsonDirectory.isString() ? NetworkUtil::FixAddress ( jsonDirectory.toString() ) : QString();
272284

273-
pClient->Connect ( strAddress, strServerName );
285+
pClient->Connect ( strAddress, strServerName, strDirectory );
274286

275287
response["result"] = "ok";
276288
} );

0 commit comments

Comments
 (0)