Question

JSON-RPC Curl CMD Line Example

  • 8 December 2019
  • 6 replies
  • 135 views

Good Morning,

After looking through a great deal of the prior tickets and online documentation, I have hit a roadblock and hope you can help.

I have been using the SLOBS client example at https://stream-labs.github.io/streamlabs-obs-api-docs/ and connecting to my SLOBS.

As you know, this creates a sort of remote control for OBS, which has been awesome in tandem with mouse click macros to show/hide sources.

The problem is that adding/subtracting even one source in SLOBS becomes a logistical nightmare due to these macros, resulting in the need to remap the x/y coordinates on on all my scripts.

As a result, I am looking for a cleaner way to incorporate a simple show/hide source request. This led me to the idea of passing the JSONRPC on the command line to SLOBS via curl or wscat. I see that this is possible using jsonrpc 2.0 via websocket.

Can you provide an example of a basic JSONRPC show/hide request passed on the command line using curl or wscat?

Here is the exact JSONRPC request I would want to pass:

{
    "jsonrpc": "2.0",
    "id": 10,
    "method": "setVisibility",
    "params": {
        "resource": "SceneItem[\"scene_c3174f1b-22cf-4e16-bf04-0080181185b3\",\"49ad2dcf-999a-42da-9cbe-2ea3a5568d65\",\"ffmpeg_source_39cae32c-013d-4bf0-ae40-a78796d47793\"]",
        "args": [true]
    }
}

Passing this data should make the sceneitem in question visible, showing the source!

If I can receive just ONE example of what this looks like, I can do this with any other source which will make me very, very happy. I might even be willing to part with my first born.

My SLOBS is running on the local machine and the command will also be passed via a cmd prompt on the same local machine. As a result, it appears the current documentation states that auth isn’t necessary.

Thank you so much for your consideration! If you can assist me with this problem, I can personally guarantee that the digital deity of PC gaming, Lord GabeN, will shed his graphical grace upon thee.

Sincerely,

Kardinal Zyn


This topic has been closed for comments

6 replies

Good Afternoon,

 

Seven to eight days ago, I created a topic here regarding JSON-RPC, CURL and WSCAT. It is now gone and there was no answer given or explanation for the take down.

I understand that you don’t comment on workings of the API, but so many folks here are asking for concrete examples of how to connect to SLOBS using websocket/json-rpc… The API documentations is really good about what information to pass, but we all are looking for an example of how to connect/send this information to SLOBS! Please - Any program is fine - command line in windows preferred - but please can you provide at least ONE example of passing a json-rpc to SLOBS?

Thanks in advance!

Remember, Lord Gaben smiles upon those who do good for their fellow gamers! ^_~

-Kardinal Zyn

 

Userlevel 6

Hey there @KardinalZyn Sorry about that, I think the forum’s mod tools detected your previous message as spam. Anyway, I’ll try to get you an example (no guarantee tho).

I stumbled upon this looking for help, going to add some info for people needing help. I’ve scraped info together, but I’m still pretty fresh with this, so feel free to correct me anyone!

From what I’m seeing part of the confusion is that in Windows, it’s generally called a socket, not a pipe? Or something like that. It sounds like things get mixed up between Windows and Linux terminology. Regardless it looks like searching for help with sockets though produces results that work, whereas searching for help with Windows pipes doesn’t.

I can’t speak to Windows Command Line as well, but I looked up some resources that should help. Resources on this are either scarce, or I’m using the wrong terms.

Linux Command Linehttps://unix.stackexchange.com/questions/336876/simple-shell-script-to-send-socket-message

Windows Powershell: https://serverfault.com/questions/629682/send-text-string-to-a-socket-in-windows

I’m trying to find a Windows CMD method without Powershell, but I haven’t had any luck. :( Regardless, I hope this helps set you and other programmers on the right track.

Here’s an answer in Node.js to connect to the local SLOBS program that I was looking for when I stumbled here, and I suspect will help others as well:

Node.js full steps (on Windows 10):

  1. Go to “Streamlabs OBS > Settings > Remote Control”
  2. Click “Click to reveal”. Windows may ask for permissions; you must grant them for this to work.
  3. Go to this link: https://stream-labs.github.io/streamlabs-obs-api-docs/
  4. Click “Connect” at the top-right corner.
  5. OPTIONAL: confirm that the pipe is open by going to 127.0.0.1:59650/api in your browser, or by running the command netstat -aon in the command line (there’s a better command but I forget) and looking for 127.0.0.1:59650. In either case, it means the pipe is open.

The Node.js code is below:

// NET documentation: https://nodejs.org/api/net.html
const NET = require('net');

// Connect to the SLOBS pipe
const PIPE = NET.connect('\\\\.\\pipe\\slobs', function() {
console.log('Successfully connected to SLOBS pipe');
});

// Whenever something is sent to the SLOBS pipe
PIPE.on('data', function(data) {
var json = JSON.parse(data);
switch(json.id){
case 1:
break;
case 2:
console.log('ran getScenes');
console.log(json);
break;
// ...
default:
console.log('Command not recognized!');
break;
}
});

// Send data to the SLOBS pipe
PIPE.write(JSON.stringify({
"jsonrpc": "2.0", // Lets the pipe know what it's receiving
"id": 2, // This lets you identify the call back up in PIPE.on()
"method": "getScenes", // The method, kinda like a function
"params": {
"resource": "ScenesService" // The method's parameters
}
})); // Note: callback for socket.write doesn't actually return the data. You have to use the PIPE.on('data',...) function for that. That's what the

 

Note: I just found out that if the connection fails, you have to return to “Streamlabs OBS > Settings > Remote Control” and click on the blurred-out code. I think this is only required after restarting Streamlabs, but I’m gonna keep an eye on it.

Also, the final JS comment in my original post was supposed to be 

// Note: callback for socket.write doesn't actually return the data. You have to use the PIPE.on('data',...) function for that. That's what the id is for; to track your commands and responses.

 

Userlevel 5

Hey all,

For all dev related queries, we are limited to referring you to https://dev.streamlabs.com/ and github. 

For further assistance, please join us on discord or submit a ticket.

Tickets: https://support.streamlabs.com/hc/en-us/requests/new

Thanks!