Skip to content

Commit

Permalink
Add support for OBS stream status and stream key update.
Browse files Browse the repository at this point in the history
  • Loading branch information
lamaral committed Sep 17, 2018
1 parent f99c88c commit 8af50a4
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
51 changes: 49 additions & 2 deletions packages/nodecg-utility-obs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class OBSUtility extends OBSWebSocket {
const sceneList = nodecg.Replicant(`${namespace}:sceneList`, {schemaPath: buildSchemaPath('sceneList')});
const transitioning = nodecg.Replicant(`${namespace}:transitioning`, {schemaPath: buildSchemaPath('transitioning')});
const studioMode = nodecg.Replicant(`${namespace}:studioMode`, {schemaPath: buildSchemaPath('studioMode')});
const streamStatus = nodecg.Replicant(`${namespace}:streamStatus`, {schemaPath: buildSchemaPath('streamStatus')});
const log = new nodecg.Logger(`${nodecg.bundleName}:${namespace}`);

// Expose convenient references to the Replicants.
Expand All @@ -49,7 +50,8 @@ class OBSUtility extends OBSWebSocket {
previewScene,
sceneList,
transitioning,
studioMode
studioMode,
streamStatus
};
this.log = log;
this.hooks = opts.hooks || {};
Expand Down Expand Up @@ -133,6 +135,39 @@ class OBSUtility extends OBSWebSocket {
callback();
});

nodecg.listenFor(`${namespace}:startStreaming`, (_data, callback = function () {}) => {
try {
this.StartStreaming();
} catch (error) {
log.error('Error starting the streaming:', error);
callback(error);
return;
}
callback();
});

nodecg.listenFor(`${namespace}:stopStreaming`, (_data, callback = function () {}) => {
try {
this.StopStreaming();
} catch (error) {
log.error('Error stopping the streaming:', error);
callback(error);
return;
}
callback();
});

nodecg.listenFor(`${namespace}:setStreamKey`, (key, callback = function () {}) => {
try {
this.SetStreamSettings({'settings': {'key': key}});
} catch (error) {
log.error('Error setting the stream key:', error);
callback(error);
return;
}
callback();
});

this.on('ConnectionClosed', () => {
this._reconnectToOBS();
});
Expand Down Expand Up @@ -169,6 +204,18 @@ class OBSUtility extends OBSWebSocket {
studioMode.value = data.newState;
});

this.on('StreamStatus', data => {
streamStatus.value = data.streaming;
});

this.on('StreamStarted', () => {
streamStatus.value = true;
});

this.on('StreamStopped', () => {
streamStatus.value = false;
});

setInterval(() => {
if (websocketConfig.value && websocketConfig.value.status === 'connected' && !this._connected) {
log.warn('Thought we were connected, but the automatic poll detected we were not. Correcting.');
Expand Down Expand Up @@ -370,4 +417,4 @@ function buildSchemaPath(schemaName) {
return path.resolve(__dirname, 'schemas', `${encodeURIComponent(schemaName)}.json`);
}

module.exports = OBSUtility;
module.exports = OBSUtility;
5 changes: 5 additions & 0 deletions packages/nodecg-utility-obs/schemas/streamStatus.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "boolean",
"default": false
}

0 comments on commit 8af50a4

Please sign in to comment.