Embed: mews: fix startup when tabbed out
This commit is contained in:
parent
94af64caa0
commit
53612aa092
2 changed files with 19 additions and 9 deletions
File diff suppressed because one or more lines are too long
|
@ -106,21 +106,27 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
|
|
||||||
//this function is called both when the websocket is ready and the media source is ready - both should be open to proceed
|
//this function is called both when the websocket is ready and the media source is ready - both should be open to proceed
|
||||||
function checkReady() {
|
function checkReady() {
|
||||||
|
//console.log("checkready",player.ws.readyState,player.ms.readyState);
|
||||||
if ((player.ws.readyState == player.ws.OPEN) && (player.ms.readyState == "open") && (player.sb)) {
|
if ((player.ws.readyState == player.ws.OPEN) && (player.ms.readyState == "open") && (player.sb)) {
|
||||||
callback(video);
|
callback(video);
|
||||||
if (MistVideo.options.autoplay) {
|
if (MistVideo.options.autoplay) {
|
||||||
player.api.play();
|
player.api.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.msoninit = []; //array of functions that will be executed once ms is open
|
||||||
this.msinit = function() {
|
this.msinit = function() {
|
||||||
return new Promise(function(resolve,reject){
|
return new Promise(function(resolve,reject){
|
||||||
//prepare mediasource
|
//prepare mediasource
|
||||||
player.ms = new MediaSource();
|
player.ms = new MediaSource();
|
||||||
video.src = URL.createObjectURL(player.ms);
|
video.src = URL.createObjectURL(player.ms);
|
||||||
player.ms.onsourceopen = function(){
|
player.ms.onsourceopen = function(){
|
||||||
|
for (var i in player.msoninit) {
|
||||||
|
player.msoninit[i]();
|
||||||
|
}
|
||||||
|
player.msoninit = [];
|
||||||
resolve();
|
resolve();
|
||||||
};
|
};
|
||||||
player.ms.onsourceclose = function(e){
|
player.ms.onsourceclose = function(e){
|
||||||
|
@ -174,9 +180,9 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
this.msinit().then(function(){
|
this.msinit().then(function(){
|
||||||
if (player.sb) {
|
if (player.sb) {
|
||||||
MistVideo.log("Not creating source buffer as one already exists.");
|
MistVideo.log("Not creating source buffer as one already exists.");
|
||||||
|
checkReady();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
checkReady();
|
|
||||||
});
|
});
|
||||||
this.onsbinit = [];
|
this.onsbinit = [];
|
||||||
this.sbinit = function(codecs){
|
this.sbinit = function(codecs){
|
||||||
|
@ -357,7 +363,7 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
if (player.onsbinit.length) {
|
if (player.onsbinit.length) {
|
||||||
player.onsbinit.shift()();
|
player.onsbinit.shift()();
|
||||||
}
|
}
|
||||||
//console.log("sb inited");
|
checkReady();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.wsconnect = function(){
|
this.wsconnect = function(){
|
||||||
|
@ -382,14 +388,13 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
};
|
};
|
||||||
this.ws.onclose = function(e){
|
this.ws.onclose = function(e){
|
||||||
MistVideo.log("MP4 over WS: websocket closed");
|
MistVideo.log("MP4 over WS: websocket closed");
|
||||||
if (this.wasConnected && (!MistVideo.destroyed) && (MistVideo.state == "Stream is online") && (!MistVideo.video.error)) {
|
if (this.wasConnected && (!MistVideo.destroyed) && (MistVideo.state == "Stream is online") && (!(MistVideo.video && MistVideo.video.error))) {
|
||||||
MistVideo.log("MP4 over WS: reopening websocket");
|
MistVideo.log("MP4 over WS: reopening websocket");
|
||||||
player.wsconnect().then(function(){
|
player.wsconnect().then(function(){
|
||||||
if (!player.sb) {
|
if (!player.sb) {
|
||||||
//retrieve codec info
|
//retrieve codec info
|
||||||
var f = function(msg){
|
var f = function(msg){
|
||||||
//got codec data, set up source buffer
|
//got codec data, set up source buffer
|
||||||
|
|
||||||
if (!player.sb) { player.sbinit(msg.data.codecs); }
|
if (!player.sb) { player.sbinit(msg.data.codecs); }
|
||||||
else { player.api.play(); }
|
else { player.api.play(); }
|
||||||
|
|
||||||
|
@ -856,10 +861,15 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
//retrieve codec info
|
//retrieve codec info
|
||||||
var f = function(msg){
|
var f = function(msg){
|
||||||
//got codec data, set up source buffer
|
//got codec data, set up source buffer
|
||||||
|
if (player.ms && player.ms.readyState == "open") {
|
||||||
player.sbinit(msg.data.codecs);
|
player.sbinit(msg.data.codecs);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
player.msoninit.push(function(){
|
||||||
|
player.sbinit(msg.data.codecs);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
checkReady();
|
|
||||||
player.ws.removeListener("codec_data",f);
|
player.ws.removeListener("codec_data",f);
|
||||||
};
|
};
|
||||||
this.ws.addListener("codec_data",f);
|
this.ws.addListener("codec_data",f);
|
||||||
|
|
Loading…
Add table
Reference in a new issue