room vid automation

This commit is contained in:
Chris Ham
2018-09-26 21:37:45 -07:00
parent b9568c7362
commit fa9c40fb0f
6 changed files with 76 additions and 38 deletions

View File

@@ -12,7 +12,7 @@ function GHOBS(config) {
console.log(`Success! We're connected to OBS!`);
this.websocket.getCurrentScene().then(res => this.currentScene = res.name);
this.websocket.onSwitchScenes(data => {
console.log(`New Active Scene: ${data.sceneName}`);
//console.log(`New Active Scene: ${data.sceneName}`);
this.currentScene = data.sceneName;
});
resolve();
@@ -32,28 +32,51 @@ function GHOBS(config) {
this.playVideoInScene = (video, scene, callback) => {
return new Promise((resolve, reject) => {
let originalScene = this.currentScene || false;
console.log(`Changing scene from ${originalScene} to ${scene}`);
//console.log(`Changing scene from ${originalScene} to ${scene}`);
this.websocket.setCurrentScene({"scene-name": scene})
.then(res => {
// set the file path on the source
console.log(`Setting file path to: ${video.filePath}`);
this.websocket.setSourceSettings({"sourceName": video.sceneItem, "sourceSettings": {"local_file": video.filePath}})
//console.log(`Setting file path to: ${video.filePath}`);
let sourceSettings = {
"local_file": video.filePath,
"looping": (typeof video.loops !== 'undefined' && video.loops > 1)
};
sourceSettings.loop = sourceSettings.looping;
// @TODO support any sourceSetting
//
/*{ close_when_inactive: true,
local_file: 'Y:\\media\\videos\\ALttP\\my-vids\\room-vids\\11-mire\\38-wizzpot-rta-hook-610.mp4',
loop: true,
looping: false,
restart_on_activate: false,
speed_percent: 100 }*/
//this.websocket.getSourceSettings({"sourceName": video.sceneItem}).then(console.log);
this.websocket.setSourceSettings({"sourceName": video.sceneItem, "sourceSettings": sourceSettings})
// show the video scene item
.then(data => {console.log(`Showing ${video.sceneItem}`); this.websocket.setSceneItemProperties({"item": video.sceneItem, "scene-name": scene, "visible": true})})
.then(() => this.websocket.setSceneItemProperties({"item": video.sceneItem, "scene-name": scene, "visible": true}))
// when the video is over, hide it and trigger the user callback, but resolve promise immediately with the timer
.then(data => {
// adjust timeout length to allow the requested number of loops to complete
if (sourceSettings.loop === true) {
video.length *= video.loops;
console.log(`Video is set to loop, adjusted length to ${video.length}`);
}
resolve(setTimeout(() => {
console.log(`Hiding ${video.sceneItem}`);
//console.log(`Hiding ${video.sceneItem}`);
this.websocket.setSceneItemProperties({"item": video.sceneItem, "scene-name": scene, "visible": false});
if (originalScene) {
console.log(`Switching scene back to ${originalScene}`);
//console.log(`Switching scene back to ${originalScene}`);
this.websocket.setCurrentScene({"scene-name": originalScene});
}
if (typeof callback !== 'undefined') {
console.log('Triggering user callback');
//console.log('Triggering user callback');
callback(data);
}
}, video.length*1000))
}, parseInt(video.length*1000)))
});
})
.catch(reject);