Skip to content

Commit

Permalink
Merge pull request #715 from Jocke4f/fix_665_obs_nested_sources
Browse files Browse the repository at this point in the history
Added support for nested OBS scenes for websocket5
  • Loading branch information
josephdadams authored Aug 18, 2024
2 parents 6104d5c + 90bf441 commit d105f4c
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 41 deletions.
89 changes: 59 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"jspack": "^0.0.4",
"node-emberplus": "^3.0.5",
"obs-websocket-js": "npm:obs-websocket-js@^4.0.3",
"obs-websocket-js-5": "npm:obs-websocket-js@^5.0.2",
"obs-websocket-js-5": "npm:obs-websocket-js@^5.0.6",
"osc": "^2.4.3",
"rate-limiter-flexible": "^2.3.7",
"reflect-metadata": "^0.1.13",
Expand Down
52 changes: 42 additions & 10 deletions src/sources/OBS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,19 +422,19 @@ export class OBSSource extends TallyInput {
});

this.obsClient5.on("CurrentPreviewSceneChanged", (data) => {
this.scenes5.forEach((scene) => {
if(scene !== data.sceneName) this.removeBusFromAddress(scene, "preview");
});
this.setBussesForAddress(data.sceneName, ["preview"]);
this.sendTallyData();
this.removeBusFromAllAddresses("preview");
this.addBusToAddress(data.sceneName, "preview");
this.processSceneChange5(data.sceneName, "preview");

//this.sendTallyData();
});

this.obsClient5.on("CurrentProgramSceneChanged", (data) => {
this.scenes5.forEach((scene) => {
if(scene !== data.sceneName) this.removeBusFromAddress(scene, "program");
});
this.setBussesForAddress(data.sceneName, ["program"]);
this.sendTallyData();
this.removeBusFromAllAddresses("program");
this.addBusToAddress(data.sceneName, "program");
this.processSceneChange5(data.sceneName, "program");

// this.sendTallyData();
});

this.obsClient5.on("CurrentSceneCollectionChanged", (data) => {
Expand Down Expand Up @@ -585,9 +585,11 @@ export class OBSSource extends TallyInput {
}
if(scene === data.currentPreviewSceneName) {
this.setBussesForAddress(scene, ["preview"]);
this.processSceneChange5(scene, "preview");
}
if(scene === data.currentProgramSceneName) {
this.setBussesForAddress(scene, ["program"]);
this.processSceneChange5(scene, "program")
}
if(scene != data.currentPreviewSceneName && scene != data.currentProgramSceneName) {
this.setBussesForAddress(scene, []);
Expand All @@ -598,6 +600,7 @@ export class OBSSource extends TallyInput {
});
}


/** Adds a bus to the scene, nested scenes and scene sources.
* @param sceneName - Name of the scene.
* @param sources - List of scene sources (SceneItem).
Expand All @@ -618,6 +621,35 @@ export class OBSSource extends TallyInput {
this.addBusToAddress(sceneName, bus);
}


/** Adds a bus for the scene, nested scenes and scene sources.
* @param sceneName - Name of the scene.
* @param bus - Bus to assign (preview/program).
*/
private processSceneChange5(sceneName: string, bus: string): void {
// No support for specific handling for Groups since Group usage is discouraged in OBS, see https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#getsceneitemlist
this.obsClient5.call("GetSceneItemList", { sceneName: sceneName}).then((sceneItems) => {

let sceneSources = 0;
for (let i = 0; i < sceneItems.sceneItems.length; i++) {
// All scene source items to the bus
// Should a check be done for audio input if they are enabled?
this.addBusToAddress(sceneItems.sceneItems[i].sourceName as string, bus);
if (sceneItems.sceneItems[i].sourceType == "OBS_SOURCE_TYPE_INPUT") {
sceneSources++;
} else if (sceneItems.sceneItems[i].sourceType == "OBS_SOURCE_TYPE_SCENE") {
// Nested scene, dig deeper...
this.processSceneChange5(sceneItems.sceneItems[i].sourceName as string, bus);
}
}

// If this scene doesn't contain a scene then we trigger this.sendTallyData().
// The check is done to keep uncessary updates to a minimum.
if (sceneSources == sceneItems.sceneItems.length) {this.sendTallyData();}
});
}


/** Adds audio input to addresses, to the "audioInputs" list and change tally bus if it's not muted. */
private addAudioInput(input): void {
if (this.obsProtocolVersion === 4) {
Expand Down

0 comments on commit d105f4c

Please sign in to comment.