Started work on HLS livestreaming
This commit is contained in:
parent
93265b7890
commit
c6de68b474
6 changed files with 193 additions and 29 deletions
|
|
@ -65,6 +65,7 @@ module.exports = class{
|
|||
socket.on("clear", (data) => {this.deleteRange(socket, data)});
|
||||
socket.on("move", (data) => {this.moveMedia(socket, data)});
|
||||
socket.on("lock", () => {this.toggleLock(socket)});
|
||||
socket.on("goLive", (data) => {this.goLive(socket, data)});
|
||||
}
|
||||
|
||||
//--- USER FACING QUEUEING FUNCTIONS ---
|
||||
|
|
@ -128,32 +129,16 @@ module.exports = class{
|
|||
}
|
||||
|
||||
async stopMedia(socket){
|
||||
//Get the current channel from the database
|
||||
const chanDB = await channelModel.findOne({name: socket.chan});
|
||||
try{
|
||||
//Get the current channel from the database
|
||||
const chanDB = await channelModel.findOne({name: socket.chan});
|
||||
|
||||
//Permcheck to make sure the user can fuck w/ the queue
|
||||
if((!this.locked && await chanDB.permCheck(socket.user, 'scheduleMedia')) || await chanDB.permCheck(socket.user, 'scheduleAdmin')){
|
||||
|
||||
//If we're not currently playing anything
|
||||
if(this.nowPlaying == null){
|
||||
//If an originating socket was provided for this request
|
||||
if(socket != null){
|
||||
//Yell at the user for being an asshole
|
||||
loggerUtils.socketErrorHandler(socket, "No media playing!", "queue");
|
||||
}
|
||||
|
||||
//Ignore it
|
||||
return false;
|
||||
//Permcheck to make sure the user can fuck w/ the queue
|
||||
if((!this.locked && await chanDB.permCheck(socket.user, 'scheduleMedia')) || await chanDB.permCheck(socket.user, 'scheduleAdmin')){
|
||||
await this.stop();
|
||||
}
|
||||
|
||||
//Stop playing
|
||||
const stoppedMedia = this.nowPlaying;
|
||||
|
||||
//Get difference between current time and start time and set as early end
|
||||
stoppedMedia.earlyEnd = (new Date().getTime() - stoppedMedia.startTime) / 1000;
|
||||
|
||||
//End the media
|
||||
this.end();
|
||||
}catch(err){
|
||||
return loggerUtils.socketExceptionHandler(socket, err);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -249,7 +234,90 @@ module.exports = class{
|
|||
}
|
||||
}
|
||||
|
||||
async goLive(socket, data){
|
||||
//Grab the channel from DB
|
||||
const chanDB = await channelModel.findOne({name:this.channel.name});
|
||||
|
||||
let title = "Livestream";
|
||||
|
||||
if(data != null && data.title != null){
|
||||
//If the title is too long
|
||||
if(!validator.isLength(data.title, {max:30})){
|
||||
//Bitch, moan, complain...
|
||||
loggerUtils.socketErrorHandler(socket, "Title too long!", "validation");
|
||||
//and ignore it!
|
||||
return;
|
||||
}
|
||||
|
||||
//Set title
|
||||
title = validator.escape(validator.trim(data.title));
|
||||
|
||||
//If we've got no title
|
||||
if(title == null || title == ''){
|
||||
title = "Livestream";
|
||||
}
|
||||
}
|
||||
|
||||
//If we couldn't find the channel
|
||||
if(chanDB == null){
|
||||
//FUCK
|
||||
throw loggerUtils.exceptionSmith(`Unable to find channel document ${this.channel.name} while queue item!`, "queue");
|
||||
}
|
||||
|
||||
//Kill schedule timers to prevent items from starting during the stream
|
||||
await this.stopScheduleTimers();
|
||||
|
||||
//Syntatic sugar because I'm lazy :P
|
||||
const streamURL = chanDB.settings.streamURL;
|
||||
|
||||
//Pull filename from streamURL
|
||||
let filename = streamURL.match(/^.+\..+\/(.+)$/);
|
||||
|
||||
//If we're streaming from the root of the domain
|
||||
if(filename == null){
|
||||
//Set filename to root
|
||||
filename = '/';
|
||||
}else{
|
||||
//Otherwise, hand over the filename
|
||||
filename = filename[1];
|
||||
}
|
||||
|
||||
//Create queued media object from stream URL and set it to nowPlaying
|
||||
this.nowPlaying = new queuedMedia(
|
||||
title,
|
||||
filename,
|
||||
streamURL,
|
||||
streamURL,
|
||||
"livehls",
|
||||
0,
|
||||
streamURL,
|
||||
new Date().getTime()
|
||||
);
|
||||
|
||||
//Broadcast new media object to users
|
||||
this.sendMedia();
|
||||
}
|
||||
|
||||
//--- INTERNAL USE ONLY QUEUEING FUNCTIONS ---
|
||||
async stopScheduleTimers(){
|
||||
//End any currently playing media media
|
||||
await this.end();
|
||||
|
||||
//Clear sync timer
|
||||
clearTimeout(this.syncTimer);
|
||||
//Clear next timer
|
||||
clearTimeout(this.nextTimer);
|
||||
//Clear the pre-switch timer
|
||||
clearTimeout(this.preSwitchTimer);
|
||||
|
||||
//Null out the sync timer
|
||||
this.syncTimer = null;
|
||||
//Null out the next playing item timer
|
||||
this.nextTimer = null;
|
||||
//Null out the pre-switch timer
|
||||
this.preSwitchTimer = null;
|
||||
}
|
||||
|
||||
getStart(start){
|
||||
//Pull current time
|
||||
const now = new Date().getTime();
|
||||
|
|
@ -421,8 +489,11 @@ module.exports = class{
|
|||
//If we got a bad request
|
||||
if(media == null){
|
||||
try{
|
||||
//DO everything ourselves since we don't have a fance end() function to do it
|
||||
chanDB = await channelModel.findOne({name:this.channel.name});
|
||||
//If we wheren't handed a channel
|
||||
if(chanDB == null){
|
||||
//DO everything ourselves since we don't have a fance end() function to do it
|
||||
chanDB = await channelModel.findOne({name:this.channel.name});
|
||||
}
|
||||
|
||||
//If we couldn't find the channel
|
||||
if(chanDB == null){
|
||||
|
|
@ -781,13 +852,18 @@ module.exports = class{
|
|||
|
||||
async end(quiet = false, noArchive = false, volatile = false, chanDB){
|
||||
try{
|
||||
//If we're not playing anything
|
||||
if(this.nowPlaying == null){
|
||||
//Silently ignore the request
|
||||
return;
|
||||
}
|
||||
|
||||
//Call off any existing sync timer
|
||||
clearTimeout(this.syncTimer);
|
||||
|
||||
//Clear out the sync timer
|
||||
this.syncTimer = null;
|
||||
|
||||
|
||||
//Keep a copy of whats playing for later when we need to clear the DB
|
||||
const wasPlaying = this.nowPlaying;
|
||||
|
||||
|
|
@ -842,6 +918,40 @@ module.exports = class{
|
|||
}
|
||||
}
|
||||
|
||||
async stop(chanDB){
|
||||
//If we wheren't handed a channel
|
||||
if(chanDB == null){
|
||||
//DO everything ourselves since we don't have a fance end() function to do it
|
||||
chanDB = await channelModel.findOne({name:this.channel.name});
|
||||
}
|
||||
|
||||
//If we wheren't handed a channel
|
||||
if(chanDB == null){
|
||||
//Complain about the lack of a channel
|
||||
throw loggerUtils.exceptionSmith(`Channel not found!`, "queue");
|
||||
}
|
||||
|
||||
//If we're not currently playing anything
|
||||
if(this.nowPlaying == null){
|
||||
//If an originating socket was provided for this request
|
||||
if(socket != null){
|
||||
//Yell at the user for being an asshole
|
||||
throw loggerUtils.exceptionSmith(`No media playing`, "queue");
|
||||
}
|
||||
//Ignore it
|
||||
return false;
|
||||
}
|
||||
|
||||
//Stop playing
|
||||
const stoppedMedia = this.nowPlaying;
|
||||
|
||||
//Get difference between current time and start time and set as early end
|
||||
stoppedMedia.earlyEnd = (new Date().getTime() - stoppedMedia.startTime) / 1000;
|
||||
|
||||
//End the media
|
||||
this.end();
|
||||
}
|
||||
|
||||
getItemsBetweenEpochs(start, end){
|
||||
//Create an empty array to hold found items
|
||||
const foundItems = [];
|
||||
|
|
|
|||
|
|
@ -168,9 +168,10 @@ app.use('/tooltip', tooltipRouter);
|
|||
app.use('/api', apiRouter);
|
||||
|
||||
//Static File Server
|
||||
//Serve bootstrap icons
|
||||
//Serve client-side libraries
|
||||
app.use('/lib/bootstrap-icons',express.static(path.join(__dirname, '../node_modules/bootstrap-icons')));
|
||||
app.use('/lib/altcha',express.static(path.join(__dirname, '../node_modules/altcha/dist_external')));
|
||||
app.use('/lib/hls.js',express.static(path.join(__dirname, '../node_modules/hls.js/dist')));
|
||||
//Server public 'www' folder
|
||||
app.use(express.static(path.join(__dirname, '../www')));
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. %>
|
|||
<%- include('partial/scripts', {user}); %>
|
||||
<%# 3rd party code %>
|
||||
<script src="/socket.io/socket.io.min.js"></script>
|
||||
<script src="/lib/hls.js/hls.js"></script>
|
||||
<%# 1st party code %>
|
||||
<%# admin gunk %>
|
||||
<script src="/js/adminUtils.js"></script>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue