diff --git a/docs/JSON-RPC.md b/docs/JSON-RPC.md index 3f82ced8b2..36cc18e087 100644 --- a/docs/JSON-RPC.md +++ b/docs/JSON-RPC.md @@ -1,5 +1,5 @@ -# Jamulus JSON-RPC Documentation +# Jamulus JSON-RPC Server Documentation -A JSON-RPC interface is available for both Jamulus client and server to allow programmatic access. -To use the JSON-RPC interface, run Jamulus with the `--jsonrpcport --jsonrpcsecretfile /file/with/a/secret.txt` options. +A JSON-RPC server can be added to both Jamulus client and Jamulus server to allow programmatic access. +To add the JSON-RPC server, run Jamulus with the `--jsonrpcport --jsonrpcsecretfile /file/with/a/secret.txt` options. This will start a JSON-RPC server on the specified port on the localhost. The file referenced by `--jsonrpcsecretfile` must contain a single line with a freely chosen string with at least 16 characters. @@ -29,6 +29,23 @@ The JSON-RPC server is based on the [JSON-RPC 2.0](https://www.jsonrpc.org/speci - A **response** from Jamulus to the consumer. - A **notification** from Jamulus to the consumer. +## Connect to a JSON-RPC server + +On Linux, you can connect to a JSON-RPC server using the `nc` CLI tool. + +On Windows, [you can download](https://nmap.org/ncat/) and use the `ncat` CLI tool. + +This snippet uses [jayson](https://www.npmjs.com/package/jayson) to connect using Node.js: + +``` +const jayson = require("jayson/promise"); +const client = new jayson.client.tcp({ host: "127.0.0.1", port: 22100 }); + +client.request('jamulusserver/getServerInfo', {}) +.then(console.log) +.catch(console.error) +``` + ## Example After opening a TCP connection to the JSON-RPC server, the connection must be authenticated: diff --git a/tools/generate_json_rpc_docs.py b/tools/generate_json_rpc_docs.py index 42ea437a62..070ab134d3 100755 --- a/tools/generate_json_rpc_docs.py +++ b/tools/generate_json_rpc_docs.py @@ -181,7 +181,7 @@ def to_markdown(self): items.sort(key=lambda item: item.name) PREAMBLE = """ -# Jamulus JSON-RPC Documentation +# Jamulus JSON-RPC Server Documentation -A JSON-RPC interface is available for both Jamulus client and server to allow programmatic access. -To use the JSON-RPC interface, run Jamulus with the `--jsonrpcport --jsonrpcsecretfile /file/with/a/secret.txt` options. +A JSON-RPC server can be added to both Jamulus client and Jamulus server to allow programmatic access. +To add the JSON-RPC server, run Jamulus with the `--jsonrpcport --jsonrpcsecretfile /file/with/a/secret.txt` options. This will start a JSON-RPC server on the specified port on the localhost. The file referenced by `--jsonrpcsecretfile` must contain a single line with a freely chosen string with at least 16 characters. @@ -211,6 +211,23 @@ def to_markdown(self): - A **response** from Jamulus to the consumer. - A **notification** from Jamulus to the consumer. +## Connect to a JSON-RPC server + +On Linux, you can connect to a JSON-RPC server using the `nc` CLI tool. + +On Windows, [you can download](https://nmap.org/ncat/) and use the `ncat` CLI tool. + +This snippet uses [jayson](https://www.npmjs.com/package/jayson) to connect using Node.js: + +``` +const jayson = require("jayson/promise"); +const client = new jayson.client.tcp({ host: "127.0.0.1", port: 22100 }); + +client.request('jamulusserver/getServerInfo', {}) +.then(console.log) +.catch(console.error) +``` + ## Example After opening a TCP connection to the JSON-RPC server, the connection must be authenticated: