All Projects → haganbmj → Obs Websocket Js

haganbmj / Obs Websocket Js

Licence: mit
Consumes https://github.com/Palakis/obs-websocket

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Obs Websocket Js

general-angular
Realtime Angular Admin/CRUD Front End App
Stars: ✭ 24 (-92.55%)
Mutual labels:  websocket-client
reactive-streams-for-java-developers
No description or website provided.
Stars: ✭ 16 (-95.03%)
Mutual labels:  websocket-client
Websocket Client
🔧 .NET/C# websocket client library
Stars: ✭ 297 (-7.76%)
Mutual labels:  websocket-client
Socketify
Raw TCP and UDP Sockets API on Desktop Browsers
Stars: ✭ 67 (-79.19%)
Mutual labels:  websocket-client
text
An experiment with WebSockets and the human condition.
Stars: ✭ 51 (-84.16%)
Mutual labels:  websocket-client
LazWebsockets
Websocket Server and Client Library written in Lazarus
Stars: ✭ 51 (-84.16%)
Mutual labels:  websocket-client
python-bittrex-websocket-aio
Python websocket for Bittrex (async).
Stars: ✭ 35 (-89.13%)
Mutual labels:  websocket-client
Websockets
Library for building WebSocket servers and clients in Python
Stars: ✭ 3,724 (+1056.52%)
Mutual labels:  websocket-client
EthernetWebServer
This is simple yet complete WebServer library for AVR, Portenta_H7, Teensy, SAM DUE, SAMD21/SAMD51, nRF52, STM32, RP2040-based, etc. boards running Ethernet shields. The functions are similar and compatible to ESP8266/ESP32 WebServer libraries to make life much easier to port sketches from ESP8266/ESP32. Coexisting now with `ESP32 WebServer` and…
Stars: ✭ 118 (-63.35%)
Mutual labels:  websocket-client
Ws
Simple to use, blazing fast and thoroughly tested WebSocket client and server for Node.js
Stars: ✭ 17,419 (+5309.63%)
Mutual labels:  websocket-client
gr-kiwisdr
KiwiSDR gnuradio source
Stars: ✭ 15 (-95.34%)
Mutual labels:  websocket-client
websocket-tester-react
A websocket client for testing and debugging websocket connection built with react.
Stars: ✭ 19 (-94.1%)
Mutual labels:  websocket-client
Node Slack Sdk
Slack Developer Kit for Node.js
Stars: ✭ 2,988 (+827.95%)
Mutual labels:  websocket-client
VPSocketIO
socket.io client objective-c
Stars: ✭ 18 (-94.41%)
Mutual labels:  websocket-client
Python Slack Sdk
Slack Developer Kit for Python
Stars: ✭ 3,307 (+927.02%)
Mutual labels:  websocket-client
bybit-api
Node.js connector for the Bybit APIs and WebSockets, with TypeScript & browser support.
Stars: ✭ 69 (-78.57%)
Mutual labels:  websocket-client
sywebsocket
WebSocket Server and Client
Stars: ✭ 16 (-95.03%)
Mutual labels:  websocket-client
Saea
SAEA.Socket is a high-performance IOCP framework TCP based on dotnet standard 2.0; Src contains its application test scenarios, such as websocket,rpc, redis driver, MVC WebAPI, lightweight message server, ultra large file transmission, etc. SAEA.Socket是一个高性能IOCP框架的 TCP,基于dotnet standard 2.0;Src中含有其应用测试场景,例如websocket、rpc、redis驱动、MVC WebAPI、轻量级消息服务器、超大文件传输等
Stars: ✭ 318 (-1.24%)
Mutual labels:  websocket-client
Websockex
An Elixir Websocket Client
Stars: ✭ 305 (-5.28%)
Mutual labels:  websocket-client
Beast
HTTP and WebSocket built on Boost.Asio in C++11
Stars: ✭ 3,241 (+906.52%)
Mutual labels:  websocket-client

obs-websocket-js

OBSWebSocket.JS allows Javascript-based connections to the Open Broadcaster plugin obs-websocket.

Download | Samples | Changelog

Installation

npm install obs-websocket-js --save

bower install obs-websocket-js --save

Typescript definitions are included in this package, and are automatically generated to match the latest obs-websocket release.

Usage

Instantiation

The web distributable exposes a global named OBSWebSocket.

<script type='text/javascript' src='./dist/obs-websocket.js'></script>

In node...

const OBSWebSocket = require('obs-websocket-js');

Create a new WebSocket connection using the following.

  • Address is optional; defaults to localhost with a port of 4444.
  • Password is optional.
const obs = new OBSWebSocket();
obs.connect({ address: 'localhost:4444', password: '[email protected]' });

Sending Requests

All requests support the following two Syntax options where both err and data will contain the raw response from the WebSocket plugin.
Note that all response objects will supply both the original obs-websocket response items in their original format (ex: 'response-item'), but also camelCased (ex: 'responseItem') for convenience.

  • RequestName must exactly match what is defined by the obs-websocket plugin.
  • {args} are optional. Note that both request-type and message-id will be bound automatically.
  • To use callbacks instead of promises, use the sendCallback method instead of send.
// Promise API
obs.send('RequestName', {args}) // returns Promise

// Callback API
obs.sendCallback('RequestName', {args}, callback(err, data)) // no return value

// The following are additional supported requests.
obs.connect({ address: 'address', password: 'password' }) // returns Promise
obs.disconnect();

Receiving Events

For all events, data will contain the raw response from the WebSocket plugin.
Note that all response objects will supply both the original obs-websocket response items in their original format (ex: 'response-item'), but also camelCased (ex: 'responseItem') for convenience.

  • EventName must exactly match what is defined by the obs-websocket plugin.
const callback = (data) => {
	console.log(data);
};

obs.on('EventName', (data) => callback(data));

// The following are additional supported events.
obs.on('ConnectionOpened', (data) => callback(data));
obs.on('ConnectionClosed', (data) => callback(data));
obs.on('AuthenticationSuccess', (data) => callback(data));
obs.on('AuthenticationFailure', (data) => callback(data));

Handling Errors

By default, certain types of WebSocket errors will be thrown as uncaught exceptions. To ensure that you are handling every error, you must do the following:

  1. Add a .catch() handler to every returned Promise.
  2. Add a error event listener to the OBSWebSocket object. By default only errors on the initial socket connection will be caught. Any subsequent errors will be emit here and will be considered uncaught without this handler.
// You must add this handler to avoid uncaught exceptions.
obs.on('error', err => {
    console.error('socket error:', err);
});

Example

See more examples in \samples.

const OBSWebSocket = require('obs-websocket-js');

const obs = new OBSWebSocket();
obs.connect({
        address: 'localhost:4444',
        password: '[email protected]'
    })
    .then(() => {
        console.log(`Success! We're connected & authenticated.`);

        return obs.send('GetSceneList');
    })
    .then(data => {
        console.log(`${data.scenes.length} Available Scenes!`);

        data.scenes.forEach(scene => {
            if (scene.name !== data.currentScene) {
                console.log(`Found a different scene! Switching to Scene: ${scene.name}`);

                obs.send('SetCurrentScene', {
                    'scene-name': scene.name
                });
            }
        });
    })
    .catch(err => { // Promise convention dicates you have a catch on every chain.
        console.log(err);
    });

obs.on('SwitchScenes', data => {
    console.log(`New Active Scene: ${data.sceneName}`);
});

// You must add this handler to avoid uncaught exceptions.
obs.on('error', err => {
    console.error('socket error:', err);
});

Debugging

To enable debug logging, set the DEBUG environment variable:

# Enables debug logging for all modules of osb-websocket-js
DEBUG=obs-websocket-js:*

# on Windows
set DEBUG=obs-websocket-js:*

If you have multiple libraries or application which use the DEBUG environment variable, they can be joined with commas:

DEBUG=foo,bar:*,obs-websocket-js:*

# on Windows
set DEBUG=foo,bar:*,obs-websocket-js:*

Browser debugging uses localStorage

localStorage.debug = 'obs-websocket-js:*';

localStorage.debug = 'foo,bar:*,obs-websocket-js:*';

For more information, see the debug documentation.

Upgrading from 1.x to 2.x

In order to better decouple the javascript library from the obs-websocket plugin the decision has been made to no longer provide method definitions for request/event methods. You are responsible for aligning your method calls with the plugin version that you would like to support.

// No longer supported.
obs.getVersion();
obs.onSwitchScenes();

// Supported.
obs.send('GetVersion');
obs.on('SwitchScenes');

Upgrading from 2.x to 3.x

  • The es5 build is no longer provided. If you're in an environment which must run ES5-compatible code, continue using the latest 2.x release.

  • The Callback API has been separated from the Promise API. If you use callbacks in your send invocations, you will need to update them to use the new sendCallback method:

    // No longer supported!
    obs.send('StartStreaming', (error) => {
      // Code here...
    });
    
    // Use this instead:
    obs.sendCallback('StartStreaming', (error) => {
      // Code here...
    });
    
  • The connect method no longer accepts a callback. Use the promise it returns instead.

    // No longer supported!
    obs.connect({address: 'localhost: 4444'}, (error) => {
      // Code here...
    });
    
    // Use this instead:
    obs.connect({address: 'localhost: 4444'}).then(() => {
      console.log('connected');
    }).catch((error) => {
      console.error(error);
    });
    

Projects Using obs-websocket-js

To add your project to this list, submit a Pull Request.

Contributing Guidelines

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].