diff --git a/README.md b/README.md index 5222f67..a2fbd69 100644 --- a/README.md +++ b/README.md @@ -231,6 +231,8 @@ previewScene.on('change', newVal => { If OBS is in "Studio" mode, this Replicant's `value` will be the current scene that is in Preview. +If OBS is **not** in "Studio" mode, this Replicant's `value` will be `null`. + Relevant Schemas: - [`previewScene.json`](packages/nodecg-utility-obs/schemas/previewScene.json) - [`types/obs_scene.json`](packages/nodecg-utility-obs/schemas/types/obs_scene.json) diff --git a/packages/nodecg-utility-obs/index.js b/packages/nodecg-utility-obs/index.js index 1a23c22..a7e6b7d 100644 --- a/packages/nodecg-utility-obs/index.js +++ b/packages/nodecg-utility-obs/index.js @@ -227,6 +227,11 @@ class OBSUtility extends OBSWebSocket { sources: res.sources }; }).catch(err => { + if (err.error === 'studio mode not enabled') { + this.replicants.previewScene.value = null; + return; + } + this.log.error('Error updating preview scene:', err); }); } diff --git a/packages/nodecg-utility-obs/test/test.js b/packages/nodecg-utility-obs/test/test.js index 9b897b0..3b04025 100644 --- a/packages/nodecg-utility-obs/test/test.js +++ b/packages/nodecg-utility-obs/test/test.js @@ -373,6 +373,16 @@ test('#_updatePreviewScene', async t => { t.deepEqual(t.context.obs.log.error.firstCall.args[1].message, 'boom'); }); +test('#_updatePreviewScene sets previewScene replicant to null when not in studio mode', async t => { + // Tell our #setPreviewScene stub to return a promise that rejects. + t.context.obs.getPreviewScene.rejects({error: 'studio mode not enabled'}); + + await t.context.obs._updatePreviewScene(); + + t.true(t.context.obs.getPreviewScene.calledOnce); + t.is(t.context.obs.replicants.previewScene.value, null); +}); + test('#_transition throws when not connected to OBS', t => { // eslint-disable-line ava/prefer-async-await t.plan(1);