obs-websocket-js
Advanced tools
Comparing version 0.5.3 to 0.6.0
@@ -0,0 +0,0 @@ // Last Updated: May 05, 2017 |
@@ -21,4 +21,4 @@ const API = require('./API'); | ||
this.on(event, (err, data) => { | ||
this._doCallback(callback, err, data); | ||
this.on(event, data => { | ||
this._doCallback(callback, data); | ||
}); | ||
@@ -25,0 +25,0 @@ }; |
@@ -12,14 +12,12 @@ const Socket = require('./Socket'); | ||
class OBSWebSocket extends Socket { | ||
constructor() { | ||
super(); | ||
// Bind all event emissions from the socket such that they are marshaled an re-emit at the base OBSWebSocket scope. | ||
this.on('obs:internal:event', this._handleEvent); | ||
} | ||
// Internal generic Socket request method. Returns a promise, handles callbacks. | ||
// Generates a messageId internally and will override any passed in the args. | ||
// Note that the requestType here is pre-marshaling and currently must match exactly what the websocket plugin is expecting. | ||
/** | ||
* Internal generic Socket request method. Returns a promise, handles callbacks. | ||
* Generates a messageId internally and will override any passed in the args. | ||
* Note that the requestType here is pre-marshaling and currently must match exactly what the websocket plugin is expecting. | ||
* @param {String} requestType obs-websocket plugin expected request type. | ||
* @param {Object} [args={}] request arguments. | ||
* @param {Function} callback Optional. callback(err, data) | ||
* @return {Promise} Promise, passes the plugin response object. | ||
*/ | ||
send(requestType, args = {}, callback) { | ||
// TODO: Improve this to ensure args is an object, not a function or primitive or something. | ||
args = args || {}; | ||
@@ -52,2 +50,3 @@ | ||
// If we don't have a reason to fail fast, send the request to the socket. | ||
if (!rejectReason) { | ||
@@ -67,2 +66,3 @@ args['request-type'] = requestType; | ||
// If the socket call was unsuccessful or bypassed, simulate its resolution. | ||
if (rejectReason) { | ||
@@ -73,8 +73,2 @@ this.emit('obs:internal:message:id-' + messageId, rejectReason); | ||
} | ||
// TODO: Marshal to use the API defined eventType rather than the obs-websocket defined one. | ||
// Perform some logic them re-emit the event to the public name. | ||
_handleEvent(message) { | ||
this.emit(message.updateType, message); | ||
} | ||
} | ||
@@ -81,0 +75,0 @@ |
@@ -89,3 +89,3 @@ const WebSocket = require('ws'); | ||
} else if (message.updateType) { | ||
this.emit(message.updateType, err, data); | ||
this.emit(message.updateType, data); | ||
} else { | ||
@@ -92,0 +92,0 @@ logAmbiguousError(debug, 'Unrecognized Socket Message:', message); |
@@ -31,2 +31,3 @@ module.exports = { | ||
} | ||
delete this.init; | ||
@@ -33,0 +34,0 @@ return this; |
{ | ||
"name": "obs-websocket-js", | ||
"version": "0.5.3", | ||
"version": "0.6.0", | ||
"description": "OBS Websocket API in Javascript, consume @Palakis/obs-websocket", | ||
@@ -49,4 +49,4 @@ "main": "index.js", | ||
"homepage": "https://github.com/haganbmj/obs-websocket-js#readme", | ||
"sha": "b8631f03ce53a60bf7dadbc12528143cdcada50e", | ||
"timestamp": "2017-05-05 21:16:49+00:00", | ||
"sha": "4aac2c5418ad4b0f552c43c006afcc4c24677852", | ||
"timestamp": "2017-05-26 23:42:17+00:00", | ||
"eslintConfig": { | ||
@@ -53,0 +53,0 @@ "extends": "xo-space/esnext" |
@@ -63,3 +63,3 @@ # obs-websocket-js | ||
#### Receiving Events | ||
All events support the following two Syntax options where both `err` and `data` will contain the raw response from the WebSocket plugin. | ||
All events support the following two Syntax options where `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._ | ||
@@ -69,10 +69,10 @@ - EventName must exactly match what is defined by the [obs-websocket][link-obswebsocket] plugin. | ||
```js | ||
obs.on('EventName', callback(err, data)); | ||
obs.onEventName(callback(err, data)); | ||
obs.on('EventName', callback(data)); | ||
obs.onEventName(callback(data)); | ||
// The following are additional supported requests. | ||
obs.on('ConnectionOpened', callback(err, data)); | ||
obs.on('ConnectionClosed', callback(err, data)); | ||
obs.on('AuthenticationSuccess', callback(err, data)); | ||
obs.on('AuthenticationFailure', callback(err, data)); | ||
obs.on('ConnectionOpened', callback(data)); | ||
obs.on('ConnectionClosed', callback(data)); | ||
obs.on('AuthenticationSuccess', callback(data)); | ||
obs.on('AuthenticationFailure', callback(data)); | ||
``` | ||
@@ -109,3 +109,3 @@ | ||
obs.onSwitchScenes((err, data) => { | ||
obs.onSwitchScenes(data => { | ||
console.log('New Active Scene:', data.sceneName); | ||
@@ -112,0 +112,0 @@ }); |
Sorry, the diff of this file is too big to display
133381
3673