obs-websocket-js
Advanced tools
Comparing version 4.0.3 to 5.0.0-alpha.0
138
package.json
{ | ||
"name": "obs-websocket-js", | ||
"version": "4.0.3", | ||
"version": "5.0.0-alpha.0", | ||
"description": "OBS Websocket API in Javascript, consumes @Palakis/obs-websocket", | ||
"author": "Brendan Hagan (haganbmj)", | ||
"author": "OBS Websocket Community", | ||
"license": "MIT", | ||
@@ -16,56 +16,79 @@ "repository": "obs-websocket-community-projects/obs-websocket-js", | ||
], | ||
"main": "lib/index.js", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"require": "./dist/json.cjs", | ||
"browser": "./dist/json.modern.js", | ||
"default": "./dist/msgpack.modern.js" | ||
}, | ||
"./json": { | ||
"require": "./dist/json.cjs", | ||
"default": "./dist/json.modern.js" | ||
}, | ||
"./msgpack": { | ||
"require": "./dist/msgpack.cjs", | ||
"default": "./dist/msgpack.modern.js" | ||
} | ||
}, | ||
"main": "dist/json.cjs", | ||
"module": "dist/json.module.js", | ||
"amdName": "OBSWebSocket", | ||
"jsdelivr": "dist/obs-ws.min.cjs", | ||
"unpkg": "dist/obs-ws.min.cjs", | ||
"types": "dist/json.d.ts", | ||
"engines": { | ||
"node": ">12.0" | ||
}, | ||
"files": [ | ||
"dist", | ||
"lib", | ||
"types/index.d.ts" | ||
"dist" | ||
], | ||
"types": "types/index.d.ts", | ||
"scripts": { | ||
"build": "npm-run-all build:*", | ||
"build:web": "rimraf dist && webpack", | ||
"prebuild:types": "tslint -c .travis/tslint.json -p .travis/tsconfig.json", | ||
"build:types": "cross-env-shell TS_NODE_PROJECT=.travis/tsconfig.json \"node $NODE_DEBUG_OPTION -r ts-node/register .travis/build-types.ts\"", | ||
"watch": "webpack --watch", | ||
"test": "npm-run-all test:*", | ||
"test:static": "eslint .", | ||
"test:ava": "npm run ava", | ||
"test:types": "dtslint types", | ||
"report": "nyc report --reporter=text-lcov", | ||
"node-coveralls": "npm run report | coveralls", | ||
"ava": "nyc ava --verbose", | ||
"static": "eslint ." | ||
"build": "npm-run-all clean build:*", | ||
"build:bundle": "microbundle -f modern,esm,cjs --no-compress src/{json,msgpack}.ts --generateTypes false", | ||
"build:types": "tsc --emitDeclarationOnly", | ||
"build:unpkg": "microbundle -f iife src/unpkg.ts -o dist/obs-ws.min.js --external none --generateTypes false", | ||
"clean": "rimraf dist", | ||
"dev": "npm run build:bundle -- --watch", | ||
"generate:obs-types": "node --loader=ts-node/esm scripts/build-types.ts", | ||
"lint": "eslint . --ext .cjs,.js,.ts", | ||
"prepare": "npm run build", | ||
"report": "c8 report", | ||
"test": "c8 ava", | ||
"test:watch": "ava --watch" | ||
}, | ||
"dependencies": { | ||
"debug": "^4.1.0", | ||
"@msgpack/msgpack": "^2.7.1", | ||
"crypto-js": "^4.1.1", | ||
"debug": "^4.3.2", | ||
"eventemitter3": "^4.0.7", | ||
"isomorphic-ws": "^4.0.1", | ||
"sha.js": "^2.4.9", | ||
"ws": "^7.2.0" | ||
"type-fest": "^2.3.2", | ||
"ws": "^8.2.2" | ||
}, | ||
"devDependencies": { | ||
"@types/got": "^9.6.9", | ||
"@types/lodash.deburr": "^4.1.6", | ||
"@types/node": "^10.17.6", | ||
"@types/prettier": "^1.19.0", | ||
"ava": "^3.2.0", | ||
"babili-webpack-plugin": "^0.1.2", | ||
"coveralls": "^3.0.9", | ||
"cross-env": "^6.0.3", | ||
"dtslint": "^2.0.2", | ||
"eslint": "^6.7.2", | ||
"eslint-config-xo-space": "^0.22.0", | ||
"eslint-plugin-ava": "^10.0.1", | ||
"got": "^9.6.0", | ||
"@istanbuljs/nyc-config-typescript": "^1.0.1", | ||
"@types/crypto-js": "^4.0.1", | ||
"@types/debug": "^4.1.5", | ||
"@types/eslint": "^8.2.1", | ||
"@types/ws": "^8.2.0", | ||
"@typescript-eslint/eslint-plugin": "^5.4.0", | ||
"@typescript-eslint/parser": "^5.4.0", | ||
"ava": "^4.0.0-rc.1", | ||
"c8": "^7.10.0", | ||
"coveralls": "^3.1.0", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^8.2.0", | ||
"eslint-config-xo": "^0.39.0", | ||
"eslint-config-xo-typescript": "^0.47.1", | ||
"eslint-plugin-ava": "^13.1.0", | ||
"eslint-plugin-jsdoc": "^37.2.0", | ||
"got": "^12.0.0", | ||
"lodash.deburr": "^4.1.0", | ||
"microbundle": "^0.14.2", | ||
"npm-run-all": "^4.1.5", | ||
"nyc": "^14.1.1", | ||
"prettier": "^1.19.1", | ||
"rimraf": "^3.0.0", | ||
"ts-node": "^8.5.4", | ||
"tslint": "5.20.1", | ||
"tslint-xo": "0.16.0", | ||
"typescript": "3.7.3", | ||
"uglifyjs-webpack-plugin": "^2.2.0", | ||
"webpack": "^4.41.2", | ||
"webpack-cli": "^3.3.10" | ||
"nyc": "^15.1.0", | ||
"rimraf": "^3.0.2", | ||
"source-map-support": "^0.5.21", | ||
"ts-node": "^10.4.0", | ||
"typescript": "^4.4.3" | ||
}, | ||
@@ -76,14 +99,21 @@ "bugs": { | ||
"homepage": "https://github.com/obs-websocket-community-projects/obs-websocket-js#readme", | ||
"eslintConfig": { | ||
"extends": "xo-space/esnext" | ||
}, | ||
"ava": { | ||
"files": [ | ||
"test/*.spec.js", | ||
"!setup/environment.js" | ||
"extensions": { | ||
"ts": "module" | ||
}, | ||
"nodeArguments": [ | ||
"--loader=ts-node/esm", | ||
"--experimental-specifier-resolution=node" | ||
], | ||
"concurrency": 1, | ||
"timeout": "10s", | ||
"verbose": true | ||
}, | ||
"c8": { | ||
"all": true, | ||
"reporter": [ | ||
"lcov" | ||
], | ||
"include": [ | ||
"src/**/*.ts" | ||
] | ||
} | ||
} |
369
README.md
# obs-websocket-js | ||
<p align="center"><i> | ||
OBSWebSocket.JS allows Javascript-based connections to the Open Broadcaster plugin <a href="https://github.com/Palakis/obs-websocket">obs-websocket</a>. | ||
obs-websocket-js allows Javascript-based connections to the Open Broadcaster Software plugin <a href="https://github.com/obsproject/obs-websocket">obs-websocket</a>. | ||
</i> | ||
@@ -13,144 +13,258 @@ <br> | ||
<p align="center"> | ||
<a href="https://travis-ci.com/haganbmj/obs-websocket-js"><img src="https://img.shields.io/travis/haganbmj/obs-websocket-js/master.svg?style=flat"></a> | ||
<a href="https://coveralls.io/github/haganbmj/obs-websocket-js?branch=master"><img src="https://coveralls.io/repos/github/haganbmj/obs-websocket-js/badge.svg?branch=master"></a> | ||
<a href="https://libraries.io/bower/obs-websocket-js"><img src="https://img.shields.io/bower/v/obs-websocket-js.svg?style=flat"></a> | ||
<a href="https://github.com/obs-websocket-community-projects/obs-websocket-js/actions"><img src="https://img.shields.io/github/checks-status/obs-websocket-community-projects/obs-websocket-js/master"></a> | ||
<a href="https://www.npmjs.com/package/obs-websocket-js"><img src="https://img.shields.io/npm/v/obs-websocket-js.svg?style=flat"></a> | ||
<a href="https://www.npmjs.com/package/obs-websocket-js"><img src="https://img.shields.io/npm/dt/obs-websocket-js.svg"></a> | ||
<img src="https://img.shields.io/npm/l/obs-websocket-js.svg"> | ||
<a href="https://greenkeeper.io/"><img src="https://badges.greenkeeper.io/obs-websocket-community-projects/obs-websocket-js.svg"></a> | ||
</p> | ||
<p align="center"><b> | ||
<a href="https://raw.githubusercontent.com/obs-websocket-community-projects/obs-websocket-js/gh-pages/dist/obs-websocket.js">Download</a> | | ||
<a href="https://github.com/obs-websocket-community-projects/obs-websocket-js/releases">Download</a> | | ||
<a href="https://github.com/obs-websocket-community-projects/obs-websocket-js/tree/master/samples">Samples</a> | | ||
<a href="https://github.com/obs-websocket-community-projects/obs-websocket-js/blob/gh-pages/CHANGELOG.md">Changelog</a> | ||
<a href="https://github.com/obs-websocket-community-projects/obs-websocket-js/releases">Changelog</a> | ||
</b></p> | ||
# Version Warning! | ||
> You are currently reading the documentation for upcoming v5. [For v4 documentation look here](https://github.com/obs-websocket-community-projects/obs-websocket-js/tree/v4) | ||
--- | ||
## Installation | ||
### Via package manager | ||
Using a package manager like npm / yarn is the recommended installation method when you're planning to use obs-websocket-js in node.js, building a web app that you'll bundle with webpack or rollup, or for using type definitions. | ||
```sh | ||
npm install obs-websocket-js --save | ||
# with npm | ||
npm install obs-websocket-js@next | ||
bower install obs-websocket-js --save | ||
# with yarn | ||
yarn add obs-websocket-js@next | ||
``` | ||
Typescript definitions are included in this package, and are automatically generated to match the latest `obs-websocket` release. | ||
> Until obs-websocket 5.0 is released, the client supporting 5.x is released under next tag | ||
## Usage | ||
#### Instantiation | ||
The web distributable exposes a global named `OBSWebSocket`. | ||
```html | ||
<script type='text/javascript' src='./dist/obs-websocket.js'></script> | ||
### Builds | ||
dist folder of the npm package includes 2 different builds to support [different message encodings supported by obs-websocket](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#connection-steps). | ||
| Connection Encoding | JSON | Msgpack | | ||
|---|---|---| | ||
Used by default | By web bundles | By node.js | ||
Manually opting into | `import OBSWebSocket from 'obs-web-socket/json'` | `import OBSWebSocket from 'obs-web-socket/msgpack'` | ||
Benefits | Easier debugging, smaller bundle | Connection uses less bandwidth | ||
Downsides | Connection uses more bandwidth | Harder to debug, bigger bundle size | ||
In addition each version has both modern and legacy builds. Modern bundlers will opt into modern build which uses [most modern JS features while also being supported by most modern browsers](https://github.com/developit/microbundle#-modern-mode-). If you need support for older browsers, make sure to configure your bundler to also transpile dependencies with babel or other such . | ||
### Creating an OBS Websocket client | ||
`OBSWebSocket` is available as the default export in ES Modules: | ||
```ts | ||
import OBSWebSocket from 'obs-websocket-js'; | ||
const obs = new OBSWebSocket(); | ||
``` | ||
In node... | ||
When using commonjs `require()` it is available under the `default` object key: | ||
```js | ||
const OBSWebSocket = require('obs-websocket-js'); | ||
```ts | ||
const {default: OBSWebSocket} = require('obs-websocket-js'); | ||
const OBSWebSocket = require('obs-websocket-js').default; | ||
const obs = new OBSWebSocket(); | ||
``` | ||
Create a new WebSocket connection using the following. | ||
- Address is optional; defaults to `localhost` with a port of `4444`. | ||
- Password is optional. | ||
### Connecting | ||
```js | ||
```ts | ||
connect(url = 'ws://127.0.0.1:4444', password?: string, identificationParams = {}): Promise | ||
``` | ||
To connect to obs-websocket server use the `connect` method. | ||
Parameter | Description | ||
---|--- | ||
`url`<br />`string (optional)` | Websocket URL to connect to, including protocol. (For example when connecting via a proxy that supports https use `wss://127.0.0.1:4444`) | ||
`password`<br />`string (optional)` | Password required to authenticate with obs-websocket server | ||
`identificationParams`<br />`object (optional)` | Object with parameters to send with the [Identify message](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#identify-opcode-1)<br />Use this to include RPC version to guarantee compatibility with server | ||
Returns promise that resolves to data from [Hello](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#hello-opcode-0) and [Identified](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#identified-opcode-2) messages or rejects with connection error (either matching obs-websocket [WebSocketCloseCode](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#websocketclosecode) or with code -1 when non-compatible server is detected). | ||
```ts | ||
import OBSWebSocket, {EventSubscription} from 'obs-websocket-js'; | ||
const obs = new OBSWebSocket(); | ||
obs.connect({ address: 'localhost:4444', password: '$up3rSecretP@ssw0rd' }); | ||
// connect to obs-websocket running on localhost with same port | ||
await obs.connect(); | ||
// Connect to obs-ws running on 192.168.0.4 | ||
await obs.connect('ws://192.168.0.4:4444'); | ||
// Connect to localhost with password | ||
await obs.connect('ws://127.0.0.1:4444', 'super-sekret'); | ||
// Connect expecting RPC version 1 | ||
await obs.connect('ws://127.0.0.1:4444', undefined, {rpcVersion: 1}); | ||
// Connect with request for high-volume event | ||
await obs.connect('ws://127.0.0.1:4444', undefined, { | ||
eventSubscriptions: EventSubscription.All | EventSubscription.InputVolumeMeters, | ||
rpcVersion: 1 | ||
}); | ||
// A complete example | ||
try { | ||
const { | ||
obsWebSocketVersion, | ||
negotiatedRpcVersion | ||
} = await obs.connect('ws://192.168.0.4:4444', 'password', { | ||
rpcVersion: 1 | ||
}); | ||
console.log(`Connected to server ${obsWebSocketVersion} (using RPC ${negotiatedRpcVersion})`) | ||
} catch (error) { | ||
console.error('Failed to connect', error.code, error.message); | ||
} | ||
``` | ||
#### 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][link-obswebsocket] 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`][link-obswebsocket] 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`. | ||
### Reidentify | ||
```js | ||
// Promise API | ||
obs.send('RequestName', {args}) // returns Promise | ||
```ts | ||
reidentify(data: {}): Promise | ||
``` | ||
// Callback API | ||
obs.sendCallback('RequestName', {args}, callback(err, data)) // no return value | ||
To update session parameters set by initial identification use `reidentify` method. | ||
// The following are additional supported requests. | ||
obs.connect({ address: 'address', password: 'password' }) // returns Promise | ||
obs.disconnect(); | ||
Parameter | Description | ||
---|--- | ||
`data`<br />`object` | Object with parameters to send with the [Reidentify message](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#reidentify-opcode-3) | ||
Returns promise that resolves when the server has acknowledged the request | ||
```ts | ||
await obs.reidentify({ | ||
eventSubscriptions: EventSubscription.General | EventSubscription.InputShowStateChanged | ||
}); | ||
``` | ||
#### 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][link-obswebsocket] 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`][link-obswebsocket] plugin. | ||
### Disconnecting | ||
```js | ||
const callback = (data) => { | ||
console.log(data); | ||
}; | ||
```ts | ||
disconnect(): Promise | ||
``` | ||
obs.on('EventName', (data) => callback(data)); | ||
Disconnects from obs-websocket server. This keeps any registered event listeners. | ||
// 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)); | ||
Returns promise that resolves when connection is closed | ||
```ts | ||
await obs.disconnect(); | ||
``` | ||
#### 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. | ||
### Sending Requests | ||
```js | ||
// You must add this handler to avoid uncaught exceptions. | ||
obs.on('error', err => { | ||
console.error('socket error:', err); | ||
```ts | ||
call(requestType: string, requestData?: object): Promise | ||
``` | ||
Sending requests to obs-websocket is done via `call` method. | ||
Parameter | Description | ||
---|--- | ||
`requestType`<br />`string` | Request type ([see obs-websocket documentation](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#requests)) | ||
`requestData`<br />`object (optional)` | Request data ([see obs-websocket documentation for the request](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#requests)) | ||
Returns promise that resolves with response data (if applicable) or rejects with error from obs-websocket. | ||
```ts | ||
// Request without data | ||
const {currentProgramSceneName} = await obs.call('GetCurrentProgramScene'); | ||
// Request with data | ||
await obs.call('SetCurrentProgramScene', {sceneName: 'Gameplay'}); | ||
// Both together now | ||
const {inputMuted} = obs.call('ToggleInputMute', {inputName: 'Camera'}); | ||
``` | ||
### Receiving Events | ||
```ts | ||
on(event: string, handler: Function) | ||
once(event: string, handler: Function) | ||
off(event: string, handler: Function) | ||
addListener(event: string, handler: Function) | ||
removeListener(event: string, handler: Function) | ||
``` | ||
To listen for events emitted by obs-websocket use the event emitter API methods. | ||
Parameter | Description | ||
---|--- | ||
`event`<br />`string` | Event type ([see obs-websocket documentation](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#events)) | ||
`handler`<br />`Function` | Function that is called when event is sent by the server. Recieves data as the first argument ([see obs-websocket documentation for the event](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#events)) | ||
```ts | ||
function onCurrentSceneChanged(event) { | ||
console.log('Current scene changed to', event.sceneName) | ||
} | ||
obs.on('CurrentSceneChanged', onCurrentSceneChanged); | ||
obs.once('ExitStarted', () => { | ||
console.log('OBS started shutdown'); | ||
// Just for example, not necessary should you want to reuse this instance by re-connect() | ||
obs.off('CurrentSceneChanged', onCurrentSceneChanged); | ||
}); | ||
``` | ||
#### Example | ||
See more examples in [`\samples`](samples). | ||
```js | ||
const OBSWebSocket = require('obs-websocket-js'); | ||
> Internally [eventemitter3](https://github.com/primus/eventemitter3) is used and it's documentation can be referenced for advanced usage | ||
const obs = new OBSWebSocket(); | ||
obs.connect({ | ||
address: 'localhost:4444', | ||
password: '$up3rSecretP@ssw0rd' | ||
}) | ||
.then(() => { | ||
console.log(`Success! We're connected & authenticated.`); | ||
#### Internal events | ||
return obs.send('GetSceneList'); | ||
}) | ||
.then(data => { | ||
console.log(`${data.scenes.length} Available Scenes!`); | ||
In addition to obs-websocket events, following events are emitted by obs-websocket-js client itself: | ||
data.scenes.forEach(scene => { | ||
if (scene.name !== data.currentScene) { | ||
console.log(`Found a different scene! Switching to Scene: ${scene.name}`); | ||
* `ConnectionOpened` - When connection has opened (no data) | ||
* `ConnectionClosed` - When connection closed (called with `OBSWebSocketError` object) | ||
* `ConnectionError` - When connection closed due to an error (generally above is more useful) | ||
* `Hello` - When server has sent Hello message (called with [Hello data](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#hello-opcode-0)) | ||
* `Identified` - When client has connected and identified (called with [Identified](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#identified-opcode-2) data) | ||
obs.send('SetCurrentScene', { | ||
'scene-name': scene.name | ||
}); | ||
} | ||
}); | ||
}) | ||
.catch(err => { // Promise convention dicates you have a catch on every chain. | ||
console.log(err); | ||
}); | ||
## Typescript Support | ||
obs.on('SwitchScenes', data => { | ||
console.log(`New Active Scene: ${data.sceneName}`); | ||
This library is written in typescript and typescript definitions are published with the package. Each package is released with typescript defintions matching the currently released version of obs-websocket. This data can be reused from `OBSEventTypes`, `OBSRequestTypes` and `OBSResponseTypes` named exports, though in most cases function parameters will enforce the typings correctly. | ||
```ts | ||
import OBSWebSocket, {OBSEventTypes, OBSRequestTypes, OBSResponseTypes} from 'obs-websocket-js'; | ||
function onProfileChanged(event: OBSEventTypes['CurrentProfileChanged']) { | ||
event.profileName | ||
} | ||
obs.on('CurrentProfileChanged', onProfileChanged); | ||
obs.on('VendorEvent', ({vendorName, eventType, eventData}) => { | ||
if (vendorName !== 'fancy-plugin') { | ||
return; | ||
} | ||
}); | ||
// You must add this handler to avoid uncaught exceptions. | ||
obs.on('error', err => { | ||
console.error('socket error:', err); | ||
const req: OBSRequestTypes['SetSceneName'] = { | ||
sceneName: 'old-and-busted', | ||
newSceneName: 'new-hotness' | ||
}; | ||
obs.call('SetSceneName', req); | ||
obs.call('SetInputMute', { | ||
inputName: 'loud noises', | ||
inputMuted: true | ||
}); | ||
``` | ||
#### Debugging | ||
## Debugging | ||
To enable debug logging, set the `DEBUG` environment variable: | ||
@@ -183,49 +297,10 @@ | ||
For more information, see the [`debug`][link-debug] documentation. | ||
For more information, see the [`debug`](https://github.com/visionmedia/debug) package documentation. | ||
## Upgrading from 1.x to 2.x | ||
In order to better decouple the javascript library from the [obs-websocket][link-obswebsocket] 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. | ||
## Upgrading | ||
```js | ||
// No longer supported. | ||
obs.getVersion(); | ||
obs.onSwitchScenes(); | ||
* Upgrading from 4.x to 5.x (available soon) | ||
* [Upgrading from 2.x to 3.x](https://github.com/obs-websocket-community-projects/obs-websocket-js/tree/v4#upgrading-from-2x-to-3x) | ||
* [Upgrading from 1.x to 2.x](https://github.com/obs-websocket-community-projects/obs-websocket-js/tree/v4#upgrading-from-1x-to-2x) | ||
// 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: | ||
```js | ||
// 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. | ||
```js | ||
// 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** | ||
@@ -236,22 +311,2 @@ _To add your project to this list, submit a Pull Request._ | ||
## [Contributing Guidelines][link-contributing] | ||
[badge-build-status]: https://img.shields.io/travis/haganbmj/obs-websocket-js/master.svg?style=flat "Travis Status" | ||
[badge-tag]: https://img.shields.io/github/tag/haganbmj/obs-websocket-js.svg?style=flat "Latest Tag" | ||
[badge-release]: https://img.shields.io/github/release/obs-websocket-community-projects/obs-websocket-js.svg?style=flat "Latest Release" | ||
[badge-coveralls]: https://coveralls.io/repos/github/haganbmj/obs-websocket-js/badge.svg?branch=master "Coveralls Status" | ||
[badge-npm-downloads]: https://img.shields.io/npm/dt/obs-websocket-js.svg "NPM Downloads" | ||
[link-obswebsocket]: https://github.com/Palakis/obs-websocket "OBS WebSocket Plugin" | ||
[link-Travis-CI]: https://travis-ci.com/obs-websocket-community-projects/obs-websocket-js "Travis CI" | ||
[link-Coveralls]: https://coveralls.io/github/obs-websocket-community-projects/obs-websocket-js?branch=master "Coveralls" | ||
[link-releases]: https://github.com/obs-websocket-community-projects/obs-websocket-js/releases "obs-websocket-js Releases" | ||
[link-tags]: https://github.com/obs-websocket-community-projects/obs-websocket-js/tags "obs-websocket-js Tags" | ||
[link-download]: https://raw.githubusercontent.com/obs-websocket-community-projects/obs-websocket-js/gh-pages/dist/obs-websocket.js "Download" | ||
[link-documentation]: https://github.com/obs-websocket-community-projects/obs-websocket-js/blob/gh-pages/DOCUMENTATION.md "Documentation" | ||
[link-samples]: https://github.com/obs-websocket-community-projects/obs-websocket-js/tree/master/samples "Samples" | ||
[link-changelog]: https://github.com/obs-websocket-community-projects/obs-websocket-js/blob/gh-pages/CHANGELOG.md "Changelog" | ||
[link-contributing]: .github/CONTRIBUTING.md "Contributing" | ||
[link-debug]: https://github.com/visionmedia/debug "Debug Documentation" | ||
## [Contributing Guidelines](.github/CONTRIBUTING.md) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
660808
23
5519
310
Yes
7
1
+ Added@msgpack/msgpack@^2.7.1
+ Addedcrypto-js@^4.1.1
+ Addedeventemitter3@^4.0.7
+ Addedtype-fest@^2.3.2
+ Added@msgpack/msgpack@2.8.0(transitive)
+ Addedcrypto-js@4.2.0(transitive)
+ Addedeventemitter3@4.0.7(transitive)
+ Addedtype-fest@2.19.0(transitive)
+ Addedws@8.18.0(transitive)
- Removedsha.js@^2.4.9
- Removedinherits@2.0.4(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsha.js@2.4.11(transitive)
- Removedws@7.5.10(transitive)
Updateddebug@^4.3.2
Updatedws@^8.2.2