obs-websocket-js
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -82,3 +82,3 @@ ## Classes | ||
* [.onAuthenticationFailure()](#OBSWebSocket+onAuthenticationFailure) | ||
* [.onSceneSwitch()](#OBSWebSocket+onSceneSwitch) | ||
* [.onSceneSwitch(sceneName)](#OBSWebSocket+onSceneSwitch) | ||
* [.onSceneListChanged(response)](#OBSWebSocket+onSceneListChanged) | ||
@@ -152,3 +152,3 @@ * [.onStreamStarting()](#OBSWebSocket+onStreamStarting) | ||
### obsWebSocket.onSceneSwitch() | ||
### obsWebSocket.onSceneSwitch(sceneName) | ||
Triggered on Scene Change. | ||
@@ -158,2 +158,7 @@ | ||
**Category**: listener | ||
| Param | Type | | ||
| --- | --- | | ||
| sceneName | <code>string</code> | | ||
<a name="OBSWebSocket+onSceneListChanged"></a> | ||
@@ -453,3 +458,5 @@ | ||
| --- | --- | | ||
| obsVersion | <code>string</code> | | ||
| err | <code>object</code> | | ||
| data | <code>object</code> | | ||
| data.obsVersion | <code>string</code> | | ||
@@ -465,5 +472,7 @@ <a name="getAuthRequiredCb"></a> | ||
| --- | --- | | ||
| authRequired | <code>bool</code> | | ||
| [salt] | <code>string</code> | | ||
| [challenge] | <code>string</code> | | ||
| err | | | ||
| data | | | ||
| data.authRequired | <code>bool</code> | | ||
| [data.salt] | <code>string</code> | | ||
| [data.challenge] | <code>string</code> | | ||
@@ -479,3 +488,4 @@ <a name="getCurrentSceneCb"></a> | ||
| --- | --- | | ||
| scene | <code>[OBSScene](#OBSScene)</code> | | ||
| err | | | ||
| data | <code>[OBSScene](#OBSScene)</code> | | ||
@@ -491,4 +501,6 @@ <a name="getSceneListCb"></a> | ||
| --- | --- | --- | | ||
| currentScene | <code>string</code> | Name of the currently active scene. | | ||
| scenes | <code>[Array.<OBSScene>](#OBSScene)</code> | Array of [OBSScene](#OBSScene)s. | | ||
| err | | | | ||
| data | | | | ||
| data.currentScene | <code>string</code> | Name of the currently active scene. | | ||
| data.scenes | <code>[Array.<OBSScene>](#OBSScene)</code> | Array of [OBSScene](#OBSScene)s. | | ||
@@ -504,11 +516,13 @@ <a name="getStreamStatusCb"></a> | ||
| --- | --- | --- | | ||
| streaming | <code>bool</code> | | | ||
| recording | <code>bool</code> | | | ||
| previewOnly | <code>bool</code> | Always false. | | ||
| [bytesPerSec] | <code>int</code> | | | ||
| [strain] | <code>double</code> | | | ||
| [totalStreamTime] | <code>int</code> | | | ||
| [numTotalFrames] | <code>int</code> | | | ||
| [numDroppedFrames] | <code>int</code> | | | ||
| [fps] | <code>double</code> | | | ||
| err | | | | ||
| data | | | | ||
| data.streaming | <code>bool</code> | | | ||
| data.recording | <code>bool</code> | | | ||
| data.previewOnly | <code>bool</code> | Always false. | | ||
| [data.bytesPerSec] | <code>int</code> | | | ||
| [data.strain] | <code>double</code> | | | ||
| [data.totalStreamTime] | <code>int</code> | | | ||
| [data.numTotalFrames] | <code>int</code> | | | ||
| [data.numDroppedFrames] | <code>int</code> | | | ||
| [data.fps] | <code>double</code> | | | ||
@@ -524,4 +538,6 @@ <a name="getTransitionListCb"></a> | ||
| --- | --- | | ||
| currentTransition | <code>string</code> | | ||
| transitions | <code>Array.<string></code> | | ||
| err | | | ||
| data | | | ||
| data.currentTransition | <code>string</code> | | ||
| data.transitions | <code>Array.<string></code> | | ||
@@ -537,3 +553,5 @@ <a name="getCurrentTransitionCb"></a> | ||
| --- | --- | | ||
| name | <code>string</code> | | ||
| err | | | ||
| data | | | ||
| data.name | <code>string</code> | | ||
/*! | ||
* OBS WebSocket Javascript API (obs-websocket-js) v0.1.0 | ||
* Author: Brendan Hagan (haganbmj) | ||
* Repo: https://github.com/haganbmj/obs-websocket-js | ||
* Repo: git+https://github.com/haganbmj/obs-websocket-js.git | ||
*/ | ||
@@ -140,18 +140,27 @@ | ||
var message = JSON.parse(msg.data); | ||
var err = null; | ||
if (!message) | ||
return; | ||
var updateType = message['update-type']; | ||
var messageId = message['message-id']; | ||
if (message.status === 'error') { | ||
console.error(OBSWebSocket.CONSOLE_NAME, 'Error:', message.error); | ||
err = message.error; | ||
message = null; | ||
} | ||
var updateType = message['update-type']; | ||
if (updateType) { | ||
this._buildEventCallback(updateType, message); | ||
if (message) { | ||
this._buildEventCallback(updateType, message); | ||
} | ||
} else { | ||
var messageId = message['message-id']; | ||
var callback = this._responseCallbacks[messageId].callbackFunction; | ||
callback(message); | ||
if (callback) { | ||
callback(err, message); | ||
} | ||
delete this._responseCallbacks[messageId]; | ||
@@ -170,3 +179,2 @@ } | ||
this.getSceneList(function(sceneList) { | ||
console.log('debug', sceneList); | ||
self.onSceneListChanged(sceneList); | ||
@@ -368,2 +376,3 @@ }); | ||
* @category listener | ||
* @param sceneName {string} | ||
*/ | ||
@@ -474,3 +483,5 @@ OBSWebSocket.prototype.onSceneSwitch = function(sceneName) {}; // jshint ignore:line | ||
* @callback getVersionCb | ||
* @param obsVersion {string} | ||
* @param err {object} | ||
* @param data {object} | ||
* @param data.obsVersion {string} | ||
*/ | ||
@@ -485,5 +496,8 @@ /** | ||
OBSWebSocket.prototype.getVersion = function(callback) { | ||
function nestedCallback(message) { | ||
message['obsVersion'] = '1.0'; // TODO: Make this relevant. | ||
callback(message); | ||
function nestedCallback(err, data) { | ||
if (data) { | ||
data['obsStudioVersion'] = data['obs-studio-version']; | ||
data['obsWebSocketVersion'] = data['obs-websocket-version']; | ||
} | ||
callback(err, data); | ||
} | ||
@@ -496,5 +510,7 @@ this._sendRequest('GetVersion', {}, nestedCallback); | ||
* @callback getAuthRequiredCb | ||
* @param authRequired {bool} | ||
* @param salt {string=} | ||
* @param challenge {string=} | ||
* @param err | ||
* @param data | ||
* @param data.authRequired {bool} | ||
* @param data.salt {string=} | ||
* @param data.challenge {string=} | ||
*/ | ||
@@ -525,10 +541,11 @@ /** | ||
this._authHash(password, function(authResp) { | ||
self._sendRequest('Authenticate', { 'auth' : authResp }, function(message) { | ||
if (message.status === 'ok') { | ||
console.info(OBSWebSocket.CONSOLE_NAME, "Authentication Success."); | ||
self.onAuthenticationSuccess(); | ||
} else { | ||
console.error(OBSWebSocket.CONSOLE_NAME, "Authentication Failure.", message); | ||
self._sendRequest('Authenticate', { 'auth' : authResp }, function(err, data) { | ||
if (err) { | ||
console.error(OBSWebSocket.CONSOLE_NAME, "Authentication Failure.", err); | ||
self.onAuthenticationFailure(); | ||
return; | ||
} | ||
console.info(OBSWebSocket.CONSOLE_NAME, "Authentication Success."); | ||
self.onAuthenticationSuccess(); | ||
}); | ||
@@ -565,6 +582,8 @@ }); | ||
self.getAuthRequired(function(message) { | ||
if (message['authRequired']) { | ||
self._auth.salt = message['salt']; | ||
self._auth.challenge = message['challenge']; | ||
self.getAuthRequired(function(err, data) { | ||
if (err) { return; } | ||
if (data['authRequired']) { | ||
self._auth.salt = data['salt']; | ||
self._auth.challenge = data['challenge']; | ||
self.authenticate(password); | ||
@@ -596,3 +615,4 @@ } | ||
* @callback getCurrentSceneCb | ||
* @param scene {OBSScene} | ||
* @param err | ||
* @param data {OBSScene} | ||
*/ | ||
@@ -607,5 +627,8 @@ /** | ||
OBSWebSocket.prototype.getCurrentScene = function(callback) { | ||
function nestedCallback(message) { | ||
message = marshalOBSScene(message); | ||
callback(message); | ||
function nestedCallback(err, data) { | ||
if (data) { | ||
data = marshalOBSScene(data); | ||
} | ||
callback(err, data); | ||
} | ||
@@ -631,4 +654,6 @@ | ||
* @callback getSceneListCb | ||
* @param currentScene {string} - Name of the currently active scene. | ||
* @param scenes {Array.<OBSScene>} - Array of {@link OBSScene}s. | ||
* @param err | ||
* @param data | ||
* @param data.currentScene {string} - Name of the currently active scene. | ||
* @param data.scenes {Array.<OBSScene>} - Array of {@link OBSScene}s. | ||
*/ | ||
@@ -643,6 +668,8 @@ /** | ||
OBSWebSocket.prototype.getSceneList = function(callback) { | ||
function nestedCallback(message) { | ||
message['currentScene'] = message['current-scene']; | ||
message['scenes'] = Object.keys(message['scenes']).map(function(key) { return marshalOBSScene(message['scenes'][key]); }); | ||
callback(message); | ||
function nestedCallback(err, data) { | ||
if (data) { | ||
data['currentScene'] = data['current-scene']; | ||
data['scenes'] = Object.keys(data['scenes']).map(function(key) { return marshalOBSScene(data['scenes'][key]); }); | ||
} | ||
callback(err, data); | ||
} | ||
@@ -729,11 +756,13 @@ | ||
* @callback getStreamStatusCb | ||
* @param streaming {bool} | ||
* @param recording {bool} | ||
* @param previewOnly {bool} - Always false. | ||
* @param bytesPerSec {int=} | ||
* @param strain {double=} | ||
* @param totalStreamTime {int=} | ||
* @param numTotalFrames {int=} | ||
* @param numDroppedFrames {int=} | ||
* @param fps {double=} | ||
* @param err | ||
* @param data | ||
* @param data.streaming {bool} | ||
* @param data.recording {bool} | ||
* @param data.previewOnly {bool} - Always false. | ||
* @param data.bytesPerSec {int=} | ||
* @param data.strain {double=} | ||
* @param data.totalStreamTime {int=} | ||
* @param data.numTotalFrames {int=} | ||
* @param data.numDroppedFrames {int=} | ||
* @param data.fps {double=} | ||
*/ | ||
@@ -748,9 +777,12 @@ /** | ||
OBSWebSocket.prototype.getStreamStatus = function(callback) { | ||
function nestedCallback(message) { | ||
message['previewOnly'] = message['preview-only']; | ||
message['bytesPerSec'] = message['bytes-per-sec']; | ||
message['totalStreamTime'] = message['total-stream-time']; | ||
message['numTotalFrames'] = message['num-total-frames']; | ||
message['numDroppedFrames'] = message['num-dropped-frames']; | ||
callback(message); | ||
function nestedCallback(err, data) { | ||
if (data) { | ||
data['previewOnly'] = data['preview-only']; | ||
data['bytesPerSec'] = data['bytes-per-sec']; | ||
data['totalStreamTime'] = data['total-stream-time']; | ||
data['numTotalFrames'] = data['num-total-frames']; | ||
data['numDroppedFrames'] = data['num-dropped-frames']; | ||
} | ||
callback(err, data); | ||
} | ||
@@ -764,4 +796,6 @@ | ||
* @callback getTransitionListCb | ||
* @param currentTransition {string} | ||
* @param transitions {Array.<string>} | ||
* @param err | ||
* @param data | ||
* @param data.currentTransition {string} | ||
* @param data.transitions {Array.<string>} | ||
*/ | ||
@@ -776,5 +810,8 @@ /** | ||
OBSWebSocket.prototype.getTransitionList = function(callback) { | ||
function nestedCallback(message) { | ||
message['currentTransition'] = message['current-transition']; | ||
callback(message); | ||
function nestedCallback(err, data) { | ||
if (data) { | ||
data['currentTransition'] = data['current-transition']; | ||
} | ||
callback(err, data); | ||
} | ||
@@ -788,3 +825,5 @@ | ||
* @callback getCurrentTransitionCb | ||
* @param name {string} | ||
* @param err | ||
* @param data | ||
* @param data.name {string} | ||
*/ | ||
@@ -791,0 +830,0 @@ /** |
{ | ||
"name": "obs-websocket-js", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "OBS Websocket API in Javascript", | ||
@@ -37,2 +37,3 @@ "main": "index.js", | ||
"grunt-contrib-jshint": "^1.0.0", | ||
"grunt-contrib-watch": "^1.0.0", | ||
"grunt-jsdoc-to-markdown": "^2.0.0", | ||
@@ -39,0 +40,0 @@ "load-grunt-tasks": "^3.5.2" |
@@ -25,4 +25,4 @@ # obs-websocket-js | ||
// Send some requests by calling existing functions and passing callbacks. | ||
ws.getCurrentScene(function(message) { | ||
console.log(message); | ||
ws.getCurrentScene(function(err, data) { | ||
console.log(err, data); | ||
}); | ||
@@ -60,4 +60,8 @@ }; | ||
``` | ||
- Run grunt watch using the following. This will only update the distribution js file, not the markdown. | ||
```sh | ||
npm run grunt watch | ||
``` | ||
## Formatting Guidelines | ||
- 2 spaces rather than tabs. |
42345
726
66
7