director events

This commit is contained in:
Chris Ham
2018-11-07 00:41:28 -08:00
parent d01439cf15
commit fd75d11eec
4 changed files with 116 additions and 69 deletions

View File

@@ -1,4 +1,6 @@
const util = require('./util');
const util = require('./util'),
emitter = require('events').EventEmitter,
sysutil = require('util');
function FGFM(config) {
// Set up initial state
@@ -14,30 +16,36 @@ function FGFM(config) {
commercialPlaying: false
};
this.startingSoon = (autostartDelaySeconds) => {
emitter.call(this);
this.startingSoon = (streamStartDelaySeconds, showStartDelaySeconds) => {
// @TODO: Move these defaults to config
if (typeof streamStartDelaySeconds === 'undefined') {
streamStartDelaySeconds = 1;
}
if (typeof showStartDelaySeconds === 'undefined') {
showStartDelaySeconds = 300;
}
this.state.showStatus = 'STARTING_SOON';
// Set up the initial queue by randomly choosing the configured amount of vods included in shuffling
this.state.videoQueue = this.config.vods.alttp.filter(e => e.includeInShuffle === true).sort(util.randSort).slice(0, this.config.initialQueueSize);
// show the starting-soon scene
// Show the starting-soon scene
this.obs.switchToScene('starting-soon');
// restore volume
// Restore volume
this.obs.setVolume('headphones', 1.0);
// start the stream
this.obs.startStream();
// Start the stream
console.log(`The stream will start in ${streamStartDelaySeconds} seconds!`);
setTimeout(() => {this.obs.startStream().then(() => {this.emit('STREAM_STARTED')})}, streamStartDelaySeconds*1000);
if (typeof autostartDelaySeconds === 'undefined') {
autostartDelaySeconds = 300;
}
if (autostartDelaySeconds !== false) {
// @TODO: Actually show the countdown in the scene
console.log(`The show will start in ${autostartDelaySeconds} seconds!`);
setTimeout(this.startTheShow, autostartDelaySeconds*1000);
}
// @TODO: Actually show the countdown in the scene
console.log(`The show will start in ${showStartDelaySeconds} seconds!`);
setTimeout(this.startTheShow, showStartDelaySeconds*1000);
};
// Set up initial queue + start playback
@@ -53,6 +61,8 @@ function FGFM(config) {
this.obs.setVolume('headphones', 1.0);
this.state.showStatus = 'RUNNING';
this.emit('SHOW_STARTED');
};
this.endTheShow = (creditsDelaySeconds, endDelaySeconds) => {
@@ -65,14 +75,19 @@ function FGFM(config) {
}
console.log(`Credits will be shown in ${creditsDelaySeconds} seconds!`);
this.emit('SHOW_ENDING', creditsDelaySeconds);
let end = () => {
clearTimeout(this.state.videoTimer);
this.state.showStatus = 'ENDING';
// Hide current video, don't play next video
this.obs.hide(this.state.currentVideo.sceneItem, this.config.defaultSceneName)
clearTimeout(this.state.videoTimer);
this.obs.switchToScene('credits')
.then(() => {
this.emit('CREDITS_SHOWN', endDelaySeconds);
if (endDelaySeconds < 5) endDelaySeconds = 5;
console.log(`Stream will stop in ${endDelaySeconds} seconds`);
let fadeOutDelay = endDelaySeconds - 5;
@@ -96,6 +111,7 @@ function FGFM(config) {
setTimeout(() => {
this.obs.stopStream();
this.state.showStatus = 'ENDED';
this.emit('SHOW_ENDED');
}, endDelaySeconds*1000);
})
.catch(console.error);
@@ -287,12 +303,16 @@ function FGFM(config) {
this.pause = () => {
this.state.showStatus = 'PAUSED';
this.emit('SHOW_PAUSED');
};
this.resume = () => {
this.state.showStatus = 'RUNNING';
this.nextVideo();
this.emit('SHOW_RESUMED');
};
}
sysutil.inherits(FGFM, emitter);
module.exports = FGFM;