![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
obs-websocket-js
Advanced tools
OBSWebSocket.JS allows Javascript-based connections to the Open Broadcaster plugin obs-websocket.
Download | Samples | Changelog
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.
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.
localhost
with a port of 4444
.const obs = new OBSWebSocket();
obs.connect({ address: 'localhost:4444', password: '$up3rSecretP@ssw0rd' });
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.
obs-websocket
plugin.{args}
are optional. Note that both request-type
and message-id
will be bound automatically.callback(err, data)
is optional.obs.send('RequestName', {args}, callback(err, data)) returns Promise
// The following are additional supported requests.
obs.connect({ address: 'address', password: 'password' }, callback(err, data)) returns Promise
obs.disconnect();
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.
obs-websocket
plugin.obs.on('EventName', callback(data));
// The following are additional supported events.
obs.on('ConnectionOpened', callback(data));
obs.on('ConnectionClosed', callback(data));
obs.on('AuthenticationSuccess', callback(data));
obs.on('AuthenticationFailure', callback(data));
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:
.catch()
handler to every returned Promise.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);
});
See more examples in \samples
.
const OBSWebSocket = require('obs-websocket-js');
const obs = new OBSWebSocket();
obs.connect({
address: 'localhost:4444',
password: '$up3rSecretP@ssw0rd'
})
.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);
});
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.
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');
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);
});
To add your project to this list, submit a Pull Request.
FAQs
OBS Websocket API in Javascript, consumes @Palakis/obs-websocket
The npm package obs-websocket-js receives a total of 863 weekly downloads. As such, obs-websocket-js popularity was classified as not popular.
We found that obs-websocket-js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.