https://github.com/anthonygregis/slobs-websocket-js
Streamlabs OBS websocket controller built on obs-websocket-js
https://github.com/anthonygregis/slobs-websocket-js
obs obs-studio remote-control slobs slobs-websocket streamlabs websocket
Last synced: 6 months ago
JSON representation
Streamlabs OBS websocket controller built on obs-websocket-js
- Host: GitHub
- URL: https://github.com/anthonygregis/slobs-websocket-js
- Owner: anthonygregis
- License: gpl-3.0
- Created: 2021-09-06T11:59:40.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-09-09T14:06:29.000Z (over 4 years ago)
- Last Synced: 2025-07-09T15:04:29.649Z (6 months ago)
- Topics: obs, obs-studio, remote-control, slobs, slobs-websocket, streamlabs, websocket
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/slobs-websocket-js
- Size: 432 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# **slobs-websocket-js**
Streamlabs OBS websocket controller built on **[obs-websocket-js](https://github.com/obs-websocket-community-projects/obs-websocket-js)**
# **Installation**
```
# NPM Install
npm install slobs-websocket-js
# Yarn Install
yarn add slobs-websocket-js
```
# **Usage**
Untested in browser, currently supported in node.
### **Node Import Methods**
```javascript
// CommonJS
const SLOBSWebSocket = require("slobs-websocket-js");
```
### **Connecting**
- Address is optional `default: 127.0.0.1`
- Port is optional `default: 59650`
- Path is optional `default: api`
- Token is required
- Get this in `Settings -> Remote Control`, click the QR Code and show details
```javascript
const slobs = new SLOBSWebSocket();
slobs.connect({
address: "127.0.0.1",
port: 59650,
path: "api",
token: "l33t0k3n",
});
```
### **Requests**
All available requests can be found from checking the slobs-client [documentation](https://stream-labs.github.io/streamlabs-obs-api-docs/docs/index.html)
- Method is required and can be found from [slobs-client](https://stream-labs.github.io/streamlabs-obs-api-docs/docs/index.html)
- Params is required for specificing the service and for passing optional args
```javascript
slobs.send("method", { params }); // Returns a promise
slobs.sendCallback("method", { params }, callback); // Callback returns (err, data)
// Example
slobs.send("makeSceneActive", {
service: "ScenesService", // Service
args: ["fakeSceneId-1235-12351"], // Args (id)
});
```
### **Events**
When listening for events you currently need to include the service and method seperated by a period
```javascript
obs.on("Service.Method", (data) => callback(data));
```
### **Errors**
WebSocket errors besides the initial socket connection will be thrown as uncaught errors. All other errors can be caught using `.catch()` when sending request and by using the below example to catch any other error.
```javascript
obs.on("error", (err) => {
console.error("socket error:", err);
});
```
# **Example Usage**
```javascript
const SLOBSWebSocket = require("slobs-websocket-js");
const slobs = new SLOBSWebSocket();
slobs
.connect({
address: "127.0.0.1",
port: 59650,
path: "api",
token: "l33t0ken",
})
.then(() => {
console.log("Connected to SLOBS Websocket Server");
return slobs.send("sceneSwitched", {
resource: "ScenesService",
});
})
.then((data) => {
console.log(data);
})
.catch((err) => {
console.log(err);
});
slobs.on("ScenesService.sceneSwitched", (data) => {
console.log(`New Active Scene: ${data.name}`);
});
```