dizquetv/src/offline-player.js
vexorian b54b5d9112 * Fix Plex mobile apps spamming a new notification every time a video plays.
* Loading Screen.
* Minor log improvements.
* Minor defaults improvements.
* FFMPEG concat process to use 1 thread.
* Fix av1 bug when plex has to transcode the audio.
* /m3u8 endpoint
2020-08-14 23:31:28 -04:00

66 lines
2.0 KiB
JavaScript

/******************
* Offline player is for special screens, like the error
* screen or the Flex Fallback screen.
*
* This module has to follow the program-player contract.
* Asynchronous call to return a stream. Then the stream
* can be used to play the program.
**/
const EventEmitter = require('events');
const FFMPEG = require('./ffmpeg')
class OfflinePlayer {
constructor(error, context) {
this.context = context;
this.error = error;
if (context.isLoading === true) {
context.channel = JSON.parse( JSON.stringify(context.channel) );
context.channel.offlinePicture = `http://localhost:${process.env.PORT}/images/loading-screen.png`;
context.channel.offlineSoundtrack = undefined;
}
this.ffmpeg = new FFMPEG(context.ffmpegSettings, context.channel);
}
cleanUp() {
this.ffmpeg.kill();
}
async play() {
try {
let emitter = new EventEmitter();
let ffmpeg = this.ffmpeg;
let lineupItem = this.context.lineupItem;
let duration = lineupItem.streamDuration - lineupItem.start;
if (this.error) {
ffmpeg.spawnError(duration);
} else {
ffmpeg.spawnOffline(duration);
}
ffmpeg.on('data', (data) => {
emitter.emit('data', data);
});
ffmpeg.on('end', () => {
emitter.emit('end');
});
ffmpeg.on('close', () => {
emitter.emit('close');
});
ffmpeg.on('error', (err) => {
emitter.emit('error', err);
});
return emitter;
} catch(err) {
if (err instanceof Error) {
throw err;
} else {
throw Error("Error when attempting to play offline screen: " + JSON.stringify(err) );
}
}
}
}
module.exports = OfflinePlayer;