Embed: don't trigger more errors when the stream has died

This commit is contained in:
Cat 2021-09-13 14:27:25 +02:00 committed by Thulinma
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

View file

@ -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){
if (MistVideo.socket.readyState == 1) {
MistVideo.socket.send(JSON.stringify(d)); 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();

View file

@ -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,7 +282,8 @@ 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) {
case "QuotaExceededError": {
if (video.buffered.length) { if (video.buffered.length) {
if (video.currentTime - video.buffered.start(0) > 1) { if (video.currentTime - video.buffered.start(0) > 1) {
//clear as much from the buffer as we can //clear as much from the buffer as we can
@ -298,6 +299,18 @@ p.prototype.build = function (MistVideo,callback) {
player.sb._append(data); //now try again player.sb._append(data); //now try again
return; return;
} }
break;
}
case "InvalidStateError": {
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;
}
break;
}
} }
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,9 +693,13 @@ p.prototype.build = function (MistVideo,callback) {
} }
var data = new Uint8Array(e.data); var data = new Uint8Array(e.data);
if (data) { if (data) {
//if (new Date().getTime() - MistVideo.bootMs > 15e3) { data.fill(0,0,Math.floor(data.length*0.1)); } //corrupt the data pl0x :D
if (player.monitor && player.monitor.bitCounter) {
for (var i in player.monitor.bitCounter) { for (var i in player.monitor.bitCounter) {
player.monitor.bitCounter[i] += e.data.byteLength*8; 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) {
player.sb.queue.push(data); player.sb.queue.push(data);