Embed: don't trigger more errors when the stream has died
This commit is contained in:
parent
be7e44727f
commit
7a0b425fc4
4 changed files with 46 additions and 25 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -72,6 +72,7 @@ function MistVideo(streamName,options) {
|
||||||
start: function(callback,delay){
|
start: function(callback,delay){
|
||||||
var i = setTimeout(function(){
|
var i = setTimeout(function(){
|
||||||
delete MistVideo.timers.list[i];
|
delete MistVideo.timers.list[i];
|
||||||
|
if (MistVideo.destroyed) return;
|
||||||
callback();
|
callback();
|
||||||
},delay);
|
},delay);
|
||||||
this.list[i] = new Date(new Date().getTime() + delay);
|
this.list[i] = new Date(new Date().getTime() + delay);
|
||||||
|
@ -1017,7 +1018,9 @@ function MistVideo(streamName,options) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
report: function(d){
|
report: function(d){
|
||||||
MistVideo.socket.send(JSON.stringify(d));
|
if (MistVideo.socket.readyState == 1) {
|
||||||
|
MistVideo.socket.send(JSON.stringify(d));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
reportStats: function(){
|
reportStats: function(){
|
||||||
var d = {};
|
var d = {};
|
||||||
|
@ -1093,22 +1096,22 @@ function MistVideo(streamName,options) {
|
||||||
});
|
});
|
||||||
Object.defineProperty(d,"videoHeight",{
|
Object.defineProperty(d,"videoHeight",{
|
||||||
get: function(){
|
get: function(){
|
||||||
return MistVideo.video.videoHeight;
|
return MistVideo.video ? MistVideo.video.videoHeight : null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Object.defineProperty(d,"videoWidth",{
|
Object.defineProperty(d,"videoWidth",{
|
||||||
get: function(){
|
get: function(){
|
||||||
return MistVideo.video.videoWidth;
|
return MistVideo.video ? MistVideo.video.videoWidth : null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Object.defineProperty(d,"playerHeight",{
|
Object.defineProperty(d,"playerHeight",{
|
||||||
get: function(){
|
get: function(){
|
||||||
return MistVideo.video.clientHeight;
|
return MistVideo.video ? MistVideo.video.clientHeight : null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Object.defineProperty(d,"playerWidth",{
|
Object.defineProperty(d,"playerWidth",{
|
||||||
get: function(){
|
get: function(){
|
||||||
return MistVideo.video.clientWidth;
|
return MistVideo.video ? MistVideo.video.clientWidth : null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1354,6 +1357,7 @@ function MistVideo(streamName,options) {
|
||||||
}
|
}
|
||||||
if (this.socket) {
|
if (this.socket) {
|
||||||
if (this.reporting) {
|
if (this.reporting) {
|
||||||
|
this.reporting.reportStats();
|
||||||
this.reporting.report({unload:reason ? reason : null});
|
this.reporting.report({unload:reason ? reason : null});
|
||||||
}
|
}
|
||||||
this.socket.destroy();
|
this.socket.destroy();
|
||||||
|
|
|
@ -123,11 +123,11 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
resolve();
|
resolve();
|
||||||
};
|
};
|
||||||
player.ms.onsourceclose = function(e){
|
player.ms.onsourceclose = function(e){
|
||||||
console.error("ms close",e);
|
if (player.debugging) console.error("ms close",e);
|
||||||
send({type:"stop"}); //stop sending data please something went wrong
|
send({type:"stop"}); //stop sending data please something went wrong
|
||||||
};
|
};
|
||||||
player.ms.onsourceended = function(e){
|
player.ms.onsourceended = function(e){
|
||||||
console.error("ms ended",e);
|
if (player.debugging) console.error("ms ended",e);
|
||||||
|
|
||||||
//for debugging
|
//for debugging
|
||||||
|
|
||||||
|
@ -282,21 +282,34 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
player.sb.appendBuffer(data);
|
player.sb.appendBuffer(data);
|
||||||
}
|
}
|
||||||
catch(e){
|
catch(e){
|
||||||
if (e.name == "QuotaExceededError") {
|
switch (e.name) {
|
||||||
if (video.buffered.length) {
|
case "QuotaExceededError": {
|
||||||
if (video.currentTime - video.buffered.start(0) > 1) {
|
if (video.buffered.length) {
|
||||||
//clear as much from the buffer as we can
|
if (video.currentTime - video.buffered.start(0) > 1) {
|
||||||
MistVideo.log("Triggered QuotaExceededError: cleaning up "+(Math.round((video.currentTime - video.buffered.start(0) - 1)*10)/10)+"s");
|
//clear as much from the buffer as we can
|
||||||
player.sb._clean(1);
|
MistVideo.log("Triggered QuotaExceededError: cleaning up "+(Math.round((video.currentTime - video.buffered.start(0) - 1)*10)/10)+"s");
|
||||||
|
player.sb._clean(1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var bufferEnd = video.buffered.end(video.buffered.length-1);
|
||||||
|
MistVideo.log("Triggered QuotaExceededError but there is nothing to clean: skipping ahead "+(Math.round((bufferEnd - video.currentTime)*10)/10)+"s");
|
||||||
|
video.currentTime = bufferEnd;
|
||||||
|
}
|
||||||
|
player.sb._busy = false;
|
||||||
|
player.sb._append(data); //now try again
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else {
|
break;
|
||||||
var bufferEnd = video.buffered.end(video.buffered.length-1);
|
}
|
||||||
MistVideo.log("Triggered QuotaExceededError but there is nothing to clean: skipping ahead "+(Math.round((bufferEnd - video.currentTime)*10)/10)+"s");
|
case "InvalidStateError": {
|
||||||
video.currentTime = bufferEnd;
|
player.api.pause(); //playback is borked, so stop downloading more data
|
||||||
|
if (MistVideo.video.error) {
|
||||||
|
//Failed to execute 'appendBuffer' on 'SourceBuffer': The HTMLMediaElement.error attribute is not null
|
||||||
|
|
||||||
|
//the video element error is already triggering the showError()
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
player.sb._busy = false;
|
break;
|
||||||
player.sb._append(data); //now try again
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MistVideo.showError(e.message);
|
MistVideo.showError(e.message);
|
||||||
|
@ -371,7 +384,7 @@ 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")) {
|
if (this.wasConnected && (!MistVideo.destroyed) && (MistVideo.state == "Stream is online") && (!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) {
|
||||||
|
@ -680,8 +693,12 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
}
|
}
|
||||||
var data = new Uint8Array(e.data);
|
var data = new Uint8Array(e.data);
|
||||||
if (data) {
|
if (data) {
|
||||||
for (var i in player.monitor.bitCounter) {
|
//if (new Date().getTime() - MistVideo.bootMs > 15e3) { data.fill(0,0,Math.floor(data.length*0.1)); } //corrupt the data pl0x :D
|
||||||
player.monitor.bitCounter[i] += e.data.byteLength*8;
|
|
||||||
|
if (player.monitor && player.monitor.bitCounter) {
|
||||||
|
for (var i in player.monitor.bitCounter) {
|
||||||
|
player.monitor.bitCounter[i] += e.data.byteLength*8;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ((player.sb) && (!player.msgqueue)) {
|
if ((player.sb) && (!player.msgqueue)) {
|
||||||
if (player.sb.updating || player.sb.queue.length || player.sb._busy) {
|
if (player.sb.updating || player.sb.queue.length || player.sb._busy) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue