Skip to content

Commit

Permalink
Merge pull request #56 from Kruiser8/develop
Browse files Browse the repository at this point in the history
KC v1.6.1
  • Loading branch information
Kruiser8 authored Oct 5, 2022
2 parents 7ae1977 + 154b035 commit 3b93b1c
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 37 deletions.
2 changes: 2 additions & 0 deletions js/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,8 @@ _Note: Messages are echo'd to all websocket-connected clients. This is useful fo
**Format** | `OBS Size <scene> <source> <width> <height>`
**Example** | `OBS Size BRB Webcam 1920 1080`

_Note: `OBS Position` is not recommended for repositioning sources within groups. Sources in a group are positioned relative to the group, not the scene. Repositioning a source within a group may cause the size of the group to change, changing the source's relative position, and leading to unexpected results._

##### Parameters
| | |
------------ | -------------
Expand Down
149 changes: 125 additions & 24 deletions js/obs/obs-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ function connectOBSWebsocket(address, password, obsHandler, onSwitchScenes, onTr
sourceName: source
}).then(data => {
return data.sceneItemId;
}).catch(err => {
}).catch(async err => {
if (err.code === 600) {
var group = await this.getSourceGroupName(scene, source);
if (group) {
return await this.getSceneItemId(group, source);
}
}
console.error(JSON.stringify(err));
});
}
Expand All @@ -70,7 +76,77 @@ function connectOBSWebsocket(address, password, obsHandler, onSwitchScenes, onTr
return item.sourceName;
}
};
}).catch(err => {
}).catch(async err => {
if (err.code === 602) {
return await this.call('GetGroupSceneItemList', {
sceneName: scene
}).then(data => {
for (var item of data.sceneItems) {
if (item.sceneItemId === sceneItemId) {
return item.sourceName;
}
};
}).catch(groupError => {
console.error(JSON.stringify(groupError));
});
} else {
console.error(JSON.stringify(err));
}
});
}

obs.getScenesForGroup = async function(group) {
return await this.call('GetSceneList').then(async data => {
var scenes = data.scenes.map(item => item.sceneName)
if (scenes.indexOf(group) !== -1) {
return [group];
}
var groupScenes = [];
for (var item of scenes) {
await this.call('GetSceneItemList', {
sceneName: item
}).then(sceneItems => {
for (var subitem of sceneItems.sceneItems) {
if (subitem.sourceName === group) {
groupScenes.push(item);
}
};
}).catch(sceneItemsError => {
console.error(JSON.stringify(sceneItemsError));
});
};
return groupScenes;
}).catch(groupError => {
console.error(JSON.stringify(groupError));
});
}

// Get the group the contains the provided source within the given scene
obs.getSourceGroupName = async function(scene, source) {
return await this.call('GetSceneItemList', {
sceneName: scene
}).then(async data => {
// Identify groups
for (var item of data.sceneItems) {
if (item.isGroup) {
// Get sources within group until match is found
var result = await this.call('GetGroupSceneItemList', {
sceneName: item.sourceName
}).then(data => {
for (var subitem of data.sceneItems) {
if (subitem.sourceName === source) {
return item.sourceName;
}
};
}).catch(groupError => {
console.error(JSON.stringify(groupError));
});
if (result) {
return result;
}
}
}
}).catch(async err => {
console.error(JSON.stringify(err));
});
}
Expand Down Expand Up @@ -118,7 +194,13 @@ function connectOBSWebsocket(address, password, obsHandler, onSwitchScenes, onTr
sceneItemId: await this.getSceneItemId(scene, source)
}).then(data => {
return data.sceneItemEnabled;
}).catch(err => {
}).catch(async err => {
if (err.code === 600) {
var group = await this.getSourceGroupName(scene, source);
if (group) {
return await this.getSourceVisibility(group, source);
}
}
console.error(JSON.stringify(err));
});
};
Expand All @@ -134,24 +216,23 @@ function connectOBSWebsocket(address, password, obsHandler, onSwitchScenes, onTr
};

obs.setSourceVisibility = async function(source, enabled, scene) {
if (scene) {
await this.call('SetSceneItemEnabled', {
'sceneItemId': await this.getSceneItemId(scene, source),
'sceneName': scene,
'sceneItemEnabled': enabled
}).catch(err => {
console.error(JSON.stringify(err));
});
} else {
let scene = await this.getCurrentScene();
await this.call('SetSceneItemEnabled', {
'sceneName': scene,
'sceneItemId': await this.getSceneItemId(scene, source),
'sceneItemEnabled': enabled
}).catch(err => {
console.error(JSON.stringify(err));
});
};
if (!scene) {
scene = await this.getCurrentScene();
}
await this.call('SetSceneItemEnabled', {
'sceneItemId': await this.getSceneItemId(scene, source),
'sceneName': scene,
'sceneItemEnabled': enabled
}).catch(async err => {
if (err.code === 600) {
var group = await this.getSourceGroupName(scene, source);
if (group) {
await this.setSourceVisibility(source, enabled, group);
return;
}
}
console.error(JSON.stringify(err));
});
};

obs.setFilterVisibility = async function(source, filter, enabled) {
Expand Down Expand Up @@ -307,7 +388,13 @@ function connectOBSWebsocket(address, password, obsHandler, onSwitchScenes, onTr
var data = await this.call('GetSceneItemTransform', {
'sceneName': scene,
'sceneItemId': await this.getSceneItemId(scene, source)
}).catch(err => {
}).catch(async err => {
if (err.code === 600) {
var group = await this.getSourceGroupName(scene, source);
if (group) {
return await this.getSceneItemTransform(group, source);
}
}
console.error(JSON.stringify(err));
});
return data;
Expand All @@ -331,7 +418,14 @@ function connectOBSWebsocket(address, password, obsHandler, onSwitchScenes, onTr
'positionX': x,
'positionY': y
}
}).catch(err => {
}).catch(async err => {
if (err.code === 600) {
var group = await this.getSourceGroupName(scene, source);
if (group) {
await this.setSceneItemPosition(group, source, x, y);
return;
}
}
console.error(JSON.stringify(err));
});
};
Expand Down Expand Up @@ -367,7 +461,14 @@ function connectOBSWebsocket(address, password, obsHandler, onSwitchScenes, onTr
'scaleX': scaleX,
'scaleY': scaleY
}
}).catch(err => {
}).catch(async err => {
if (err.code === 600) {
var group = await this.getSourceGroupName(scene, source);
if (group) {
await this.setSceneItemSize(group, source, scaleX, scaleY);
return;
}
}
console.error(JSON.stringify(err));
});
};
Expand Down
23 changes: 11 additions & 12 deletions js/obs/obsHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,19 +258,22 @@ class OBSHandler extends Handler {
console.error("OBS onSourceVisibility: " + JSON.stringify(data));
}

var scene = data['sceneName'];
var item = await this.obs.getSceneItemName(scene, data['sceneItemId']);
var scenes = await this.obs.getScenesForGroup(data['sceneName']);
var item = await this.obs.getSceneItemName(data['sceneName'], data['sceneItemId']);
var visibility = data['sceneItemEnabled'];

var sourceTriggers = [];
if (scene in this.onSourceVis && item in this.onSourceVis[scene]) {
if (this.onSourceVis[scene][item].indexOf(visibility) !== -1) {
sourceTriggers.push(...this.onSourceVisTrigger[`${scene}|${item}|${String(visibility)}`]);
}
if (this.onSourceVis[scene][item].indexOf('toggle') !== -1) {
sourceTriggers.push(...this.onSourceVisTrigger[`${scene}|${item}|toggle`]);
for (var scene of scenes) {
if (scene in this.onSourceVis && item in this.onSourceVis[scene]) {
if (this.onSourceVis[scene][item].indexOf(visibility) !== -1) {
sourceTriggers.push(...this.onSourceVisTrigger[`${scene}|${item}|${String(visibility)}`]);
}
if (this.onSourceVis[scene][item].indexOf('toggle') !== -1) {
sourceTriggers.push(...this.onSourceVisTrigger[`${scene}|${item}|toggle`]);
}
}
}

if (sourceTriggers.length > 0) {
sourceTriggers.sort((a,b) => a-b);
sourceTriggers.forEach(triggerId => {
Expand Down Expand Up @@ -430,10 +433,6 @@ class OBSHandler extends Handler {
data = data || '';
await this.obs.broadcastCustomMessage(message, data);
break;
case 'settings':
var { source } = Parser.getInputs(triggerData, ['action', 'source'], false, 1);
let settings = await this.obs.getInputSettings(source);
return { settings: settings };
case 'size':
var { scene, item, width, height } = Parser.getInputs(triggerData, ['action', 'scene', 'item', 'width', 'height']);
if (scene === '{current}') {
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.6.0
v1.6.1

0 comments on commit 3b93b1c

Please sign in to comment.