Finished mediahandler placeholder, fixed most scheduler bugs with webrtc scheduling, started pushing iceServers w/ media object instead of clientmetadata.
This commit is contained in:
parent
b68d55b7ef
commit
3517a1499a
7 changed files with 72 additions and 12 deletions
|
|
@ -236,7 +236,7 @@ class connectedUser{
|
||||||
const chatBuffer = this.channel.chatBuffer.buffer;
|
const chatBuffer = this.channel.chatBuffer.buffer;
|
||||||
|
|
||||||
//Send off the metadata to our user's clients
|
//Send off the metadata to our user's clients
|
||||||
this.emit("clientMetadata", {user: userObj, flairList, queueLock, chatBuffer, streamType: chanDB.settings.streamType, iceServers: config.iceServers});
|
this.emit("clientMetadata", {user: userObj, flairList, queueLock, chatBuffer, streamType: chanDB.settings.streamType});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -333,6 +333,7 @@ class queue{
|
||||||
let title = "Livestream";
|
let title = "Livestream";
|
||||||
let filename = '/';
|
let filename = '/';
|
||||||
let streamURL = '/';
|
let streamURL = '/';
|
||||||
|
let rawLink = {combo: [['default', config.iceServers]]};
|
||||||
|
|
||||||
if(data != null && data.title != null){
|
if(data != null && data.title != null){
|
||||||
//If the title is too long
|
//If the title is too long
|
||||||
|
|
@ -386,6 +387,7 @@ class queue{
|
||||||
//Kill schedule timers to prevent items from starting during the stream
|
//Kill schedule timers to prevent items from starting during the stream
|
||||||
await this.stopScheduleTimers();
|
await this.stopScheduleTimers();
|
||||||
|
|
||||||
|
//If we're streaming via HLS
|
||||||
if(chanDB.settings.streamType == "livehls"){
|
if(chanDB.settings.streamType == "livehls"){
|
||||||
//Syntatic sugar because I'm lazy :P
|
//Syntatic sugar because I'm lazy :P
|
||||||
streamURL = chanDB.settings.streamURL;
|
streamURL = chanDB.settings.streamURL;
|
||||||
|
|
@ -406,6 +408,8 @@ class queue{
|
||||||
//Otherwise, hand over the filename
|
//Otherwise, hand over the filename
|
||||||
filename = filename[1];
|
filename = filename[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rawLink = {combo:[['default',streamURL]]};
|
||||||
}
|
}
|
||||||
|
|
||||||
//Create queued media object from stream URL and set it to nowPlaying
|
//Create queued media object from stream URL and set it to nowPlaying
|
||||||
|
|
@ -416,7 +420,7 @@ class queue{
|
||||||
streamURL,
|
streamURL,
|
||||||
chanDB.settings.streamType,
|
chanDB.settings.streamType,
|
||||||
0,
|
0,
|
||||||
streamURL,
|
rawLink,
|
||||||
new Date().getTime()
|
new Date().getTime()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -1266,7 +1270,7 @@ class queue{
|
||||||
}
|
}
|
||||||
|
|
||||||
//If we're ending an HLS Livestream
|
//If we're ending an HLS Livestream
|
||||||
if(wasPlaying.type == "livehls"){
|
if(wasPlaying.type == "livehls" || wasPlaying.type == "webrtc"){
|
||||||
//Redirect to the endLivestream function
|
//Redirect to the endLivestream function
|
||||||
return this.endLivestream(wasPlaying, chanDB)
|
return this.endLivestream(wasPlaying, chanDB)
|
||||||
}
|
}
|
||||||
|
|
@ -1574,7 +1578,7 @@ class queue{
|
||||||
const stoppedMedia = this.nowPlaying;
|
const stoppedMedia = this.nowPlaying;
|
||||||
|
|
||||||
//Ignore early end for livestreams
|
//Ignore early end for livestreams
|
||||||
if(this.nowPlaying.type != 'livehls'){
|
if(this.nowPlaying.type != 'livehls' && this.nowPlaying.type != 'webrtc'){
|
||||||
//Get difference between current time and start time and set as early end
|
//Get difference between current time and start time and set as early end
|
||||||
stoppedMedia.earlyEnd = (new Date().getTime() - stoppedMedia.startTime) / 1000;
|
stoppedMedia.earlyEnd = (new Date().getTime() - stoppedMedia.startTime) / 1000;
|
||||||
}
|
}
|
||||||
|
|
@ -1811,7 +1815,7 @@ class queue{
|
||||||
const now = new Date().getTime();
|
const now = new Date().getTime();
|
||||||
|
|
||||||
//If something was playing
|
//If something was playing
|
||||||
if(chanDB.media.nowPlaying != null && chanDB.media.nowPlaying.type != 'livehls'){
|
if(chanDB.media.nowPlaying != null && (chanDB.media.nowPlaying.type != 'livehls' && chanDB.media.nowPlaying.type != 'webrtc')){
|
||||||
//Rehydrate the currently playing item int oa queued media object
|
//Rehydrate the currently playing item int oa queued media object
|
||||||
const wasPlaying = chanDB.media.nowPlaying.rehydrate();
|
const wasPlaying = chanDB.media.nowPlaying.rehydrate();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -153,9 +153,6 @@ class channel{
|
||||||
|
|
||||||
//Store streamType
|
//Store streamType
|
||||||
this.streamType = data.streamType;
|
this.streamType = data.streamType;
|
||||||
|
|
||||||
//Store URLs to known Internet Connectivitey Establishment servers.
|
|
||||||
this.iceServer = data.iceServers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -926,4 +926,60 @@ class hlsLiveStreamHandler extends hlsBase{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper handler for WebRTC Streams, calling back to webRTCHandler.js for heavy lifting
|
||||||
|
* @extends rawFileBase
|
||||||
|
*/
|
||||||
|
class WebRTCLivestreamHandler extends rawFileBase{
|
||||||
|
/**
|
||||||
|
/**
|
||||||
|
* Instantiates a new WebRTCMediaHandler
|
||||||
|
* @param {channel} client - Parent Client Management Object
|
||||||
|
* @param {player} player - Parent Canopy Player Object
|
||||||
|
* @param {Object} media - De-hydrated media object from server
|
||||||
|
*/
|
||||||
|
constructor(client, player, media){
|
||||||
|
//Call derived constructor
|
||||||
|
super(client, player, media, "webrtc");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internet Connectivity Establishment configuration
|
||||||
|
*/
|
||||||
|
this.iceConfig = {iceServers: new Map(media.rawLink.combo).get('default')};
|
||||||
|
|
||||||
|
this.defineListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
defineListeners(){
|
||||||
|
//Run derived method
|
||||||
|
super.defineListeners();
|
||||||
|
|
||||||
|
//Disable right clicking
|
||||||
|
this.video.addEventListener('contextmenu', (e)=>{e.preventDefault()});
|
||||||
|
}
|
||||||
|
|
||||||
|
start(){
|
||||||
|
//call derived start function
|
||||||
|
super.start();
|
||||||
|
|
||||||
|
//Lock the player
|
||||||
|
this.setPlayerLock(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
setVideoTitle(title){
|
||||||
|
//Add title as text content for security :P
|
||||||
|
this.player.title.innerText = `: ${utils.unescapeEntities(title)}`;
|
||||||
|
|
||||||
|
//Create glow span
|
||||||
|
const glowSpan = document.createElement('span');
|
||||||
|
//Fill glow span content
|
||||||
|
glowSpan.innerText = "🔴LIVE";
|
||||||
|
//Set glowspan class
|
||||||
|
glowSpan.classList.add('critical-danger-text');
|
||||||
|
|
||||||
|
//Inject glowspan into title in a way that allows it to be easily replaced
|
||||||
|
this.player.title.prepend(glowSpan);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -188,7 +188,7 @@ class queuePanel extends panelObj{
|
||||||
*/
|
*/
|
||||||
handleStart(data){
|
handleStart(data){
|
||||||
//If we're starting an HLS Livestream
|
//If we're starting an HLS Livestream
|
||||||
if(data.media != null && data.media.type == 'livehls'){
|
if(data.media != null && (data.media.type == 'livehls' || data.media.type == 'webrtc' )){
|
||||||
//Hide the 'goLive' controls
|
//Hide the 'goLive' controls
|
||||||
this.goLiveDiv.style.display = 'none';
|
this.goLiveDiv.style.display = 'none';
|
||||||
}
|
}
|
||||||
|
|
@ -282,7 +282,7 @@ class queuePanel extends panelObj{
|
||||||
client.socket.emit('getStreamType');
|
client.socket.emit('getStreamType');
|
||||||
|
|
||||||
//If we're not livestreaming
|
//If we're not livestreaming
|
||||||
if(client.player.mediaHandler.type != "livehls"){
|
if(client.player.mediaHandler.type != "livehls" && client.player.mediaHandler.type != "webrtc"){
|
||||||
//If the div is hidden
|
//If the div is hidden
|
||||||
if(this.goLiveDiv.style.display == 'none'){
|
if(this.goLiveDiv.style.display == 'none'){
|
||||||
//Show the div
|
//Show the div
|
||||||
|
|
@ -1188,7 +1188,7 @@ class queuePanel extends panelObj{
|
||||||
const staleEntry = this.queueContainer.querySelector('.queue-entry.live');
|
const staleEntry = this.queueContainer.querySelector('.queue-entry.live');
|
||||||
|
|
||||||
//If we're not livestreaming
|
//If we're not livestreaming
|
||||||
if(client.player.mediaHandler.type != "livehls"){
|
if(client.player.mediaHandler.type != "livehls" && client.player.mediaHandler.type != "webrtc"){
|
||||||
//If we have a stale entry
|
//If we have a stale entry
|
||||||
if(staleEntry != null){
|
if(staleEntry != null){
|
||||||
//Remove stale entry since we're no longer streaming
|
//Remove stale entry since we're no longer streaming
|
||||||
|
|
|
||||||
|
|
@ -188,6 +188,9 @@ class player{
|
||||||
}else if(data.media.type == "livehls"){
|
}else if(data.media.type == "livehls"){
|
||||||
//Create a new HLS Livestream Handler for it
|
//Create a new HLS Livestream Handler for it
|
||||||
this.mediaHandler = new hlsLiveStreamHandler(this.client, this, data.media);
|
this.mediaHandler = new hlsLiveStreamHandler(this.client, this, data.media);
|
||||||
|
}else if(data.media.type == "webrtc"){
|
||||||
|
//Create a new HLS Livestream Handler for it
|
||||||
|
this.mediaHandler = new WebRTCLivestreamHandler(this.client, this, data.media);
|
||||||
}else if(data.media.type == 'dm'){
|
}else if(data.media.type == 'dm'){
|
||||||
this.mediaHandler = new hlsDailymotionHandler(this.client, this, data.media);
|
this.mediaHandler = new hlsDailymotionHandler(this.client, this, data.media);
|
||||||
//Otherwise, if we have a raw-file compatible source
|
//Otherwise, if we have a raw-file compatible source
|
||||||
|
|
|
||||||
|
|
@ -412,7 +412,7 @@ class livestreamPreferences{
|
||||||
|
|
||||||
handleTypeUpdate(data){
|
handleTypeUpdate(data){
|
||||||
//If the stream type is HLS
|
//If the stream type is HLS
|
||||||
if(data.streamType == "livehls"){
|
if(data.streamType == "livehls" || data.streamType == "webrtc"){
|
||||||
//Ensure the hls button is checked
|
//Ensure the hls button is checked
|
||||||
this.hlsButton.checked = true;
|
this.hlsButton.checked = true;
|
||||||
//Ensure the stream url input is enabled
|
//Ensure the stream url input is enabled
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue