meme refinery
This commit is contained in:
49
lib/ghobs.js
49
lib/ghobs.js
@@ -11,7 +11,10 @@ function GHOBS(config) {
|
||||
.then(() => {
|
||||
console.log(`Success! We're connected to OBS!`);
|
||||
this.websocket.getCurrentScene().then(res => this.currentScene = res.name);
|
||||
this.websocket.onSwitchScenes(data => this.currentScene = data['scene-name']);
|
||||
this.websocket.onSwitchScenes(data => {
|
||||
console.log(`New Active Scene: ${data.sceneName}`);
|
||||
this.currentScene = data.sceneName;
|
||||
});
|
||||
resolve();
|
||||
})
|
||||
.catch(reject);
|
||||
@@ -28,19 +31,28 @@ function GHOBS(config) {
|
||||
// Shows a video in the given scene/item and then hides it and switches back to the original scene when finished
|
||||
this.playVideoInScene = (video, scene, callback) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
let originalScene = this.currentScene;
|
||||
let originalScene = this.currentScene || false;
|
||||
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}})
|
||||
// show the video scene item
|
||||
.then(data => this.websocket.setSceneItemProperties({"item": video.sceneItem, "scene-name": scene, "visible": true}))
|
||||
.then(data => {console.log(`Showing ${video.sceneItem}`); 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 => {
|
||||
resolve(setTimeout(() => {
|
||||
console.log(`Hiding ${video.sceneItem}`);
|
||||
this.websocket.setSceneItemProperties({"item": video.sceneItem, "scene-name": scene, "visible": false});
|
||||
this.websocket.setCurrentScene({"scene-name": originalScene});
|
||||
callback(data);
|
||||
if (originalScene) {
|
||||
console.log(`Switching scene back to ${originalScene}`);
|
||||
this.websocket.setCurrentScene({"scene-name": originalScene});
|
||||
}
|
||||
if (typeof callback !== 'undefined') {
|
||||
console.log('Triggering user callback');
|
||||
callback(data);
|
||||
}
|
||||
}, video.length*1000))
|
||||
});
|
||||
})
|
||||
@@ -65,6 +77,33 @@ function GHOBS(config) {
|
||||
this.hideActivity = () => {
|
||||
return this.websocket.setSceneItemProperties({"item": this.config.currentActivitySceneItemName, "scene-name": this.config.defaultSceneName, "visible": false});
|
||||
};
|
||||
|
||||
this.showRoomGrind = (playTime, callback) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.websocket.setSceneItemProperties({"item": "room-grind", "scene-name": this.config.defaultSceneName, "visible": true})
|
||||
.then(res => {
|
||||
this.showActivity("NOW SHOWING: TTAS Room Grind !ttas");
|
||||
resolve(setTimeout(() => {
|
||||
// after timeout, hide room-grind and call user callback
|
||||
this.websocket.setSceneItemProperties({"item": "room-grind", "scene-name": this.config.defaultSceneName, "visible": false});
|
||||
if (typeof callback !== 'undefined') callback();
|
||||
}, playTime*1000));
|
||||
})
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
||||
|
||||
this.setVisible = (item, scene, visible) => {
|
||||
return this.websocket.setSceneItemProperties({"item": item, "scene-name": scene, "visible": visible});
|
||||
};
|
||||
|
||||
this.show = (item, scene) => {
|
||||
return this.setVisible(item, scene, true);
|
||||
};
|
||||
|
||||
this.hide = (item, scene) => {
|
||||
return this.setVisible(item, scene, false);
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = GHOBS;
|
||||
|
||||
Reference in New Issue
Block a user