diff --git a/README.md b/README.md
index 1852d57..3b7e3f9 100644
--- a/README.md
+++ b/README.md
@@ -222,6 +222,7 @@ module.exports = function (nodecg) {
obs.replicants.sceneList.on('change', () => {/* ... */});
obs.replicants.transitioning.on('change', () => {/* ... */});
obs.replicants.studioMode.on('change', () => {/* ... */});
+ obs.replicants.streamStatus.on('change', () => {/* ... */});
};
```
@@ -279,6 +280,13 @@ A boolean that becomes `true` when OBS is in Studio Mode `false` when OBS isn't
Relevant Schemas:
- [`studioMode.json`](packages/nodecg-utility-obs/schemas/studioMode.json)
+#### `> nodecg.Replicant('obs:streamStatus')`
+
+A boolean that becomes `true` when OBS is streaming `false` when OBS isn't streaming.
+
+Relevant Schemas:
+ - [`streamStatus.json`](packages/nodecg-utility-obs/schemas/streamStatus.json)
+
#### `> nodecg.Replicant('_obs:namespaces')`
A special replicant that is shared between all instances/namespaces. It always uses the name `_obs:namespaces`,
@@ -367,6 +375,48 @@ nodecg.sendMessage('obs:transition', 'Fade').then(() => {
});
```
+#### `> nodecg.sendMessage('obs:startStreaming', callback)`
+
+Start streaming with OBS.
+
+##### Example
+
+```js
+nodecg.sendMessage('obs:startStreaming').then(() => {
+ console.log('successfully started streaming');
+}).catch(err => {
+ console.error('failed to start streaming:', err);
+});
+```
+
+#### `> nodecg.sendMessage('obs:stopStreaming', callback)`
+
+Stop streaming with OBS.
+
+##### Example
+
+```js
+nodecg.sendMessage('obs:stopStreaming').then(() => {
+ console.log('successfully stopped streaming');
+}).catch(err => {
+ console.error('failed to stop streaming:', err);
+});
+```
+
+#### `> nodecg.sendMessage('obs:setStreamKey', key, callback)`
+
+Set the OBS stream key.
+
+##### Example
+
+```js
+nodecg.sendMessage('obs:setStreamKey', 'a1b2c3d4-a1b2c3d4').then(() => {
+ console.log('successfully set stream key');
+}).catch(err => {
+ console.error('failed to set stream key:', err);
+});
+```
+
### API
`nodecg-obs` extends [`obs-websocket-js`](https://github.com/haganbmj/obs-websocket-js). Please
diff --git a/packages/nodecg-utility-obs/index.js b/packages/nodecg-utility-obs/index.js
index 1f08921..7f241e1 100644
--- a/packages/nodecg-utility-obs/index.js
+++ b/packages/nodecg-utility-obs/index.js
@@ -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.
@@ -49,7 +50,8 @@ class OBSUtility extends OBSWebSocket {
previewScene,
sceneList,
transitioning,
- studioMode
+ studioMode,
+ streamStatus
};
this.log = log;
this.hooks = opts.hooks || {};
@@ -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();
});
@@ -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.');
diff --git a/packages/nodecg-utility-obs/schemas/streamStatus.json b/packages/nodecg-utility-obs/schemas/streamStatus.json
new file mode 100644
index 0000000..73145ce
--- /dev/null
+++ b/packages/nodecg-utility-obs/schemas/streamStatus.json
@@ -0,0 +1,5 @@
+{
+ "$schema": "http://json-schema.org/draft-04/schema#",
+ "type": "boolean",
+ "default": false
+}