Embed: improved behavior when websocket disconnects

This commit is contained in:
Cat 2021-06-24 16:42:42 +02:00 committed by Thulinma
parent 51147c3df5
commit 8e8017dfd9
4 changed files with 196 additions and 163 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

@ -908,7 +908,7 @@ function MistVideo(streamName,options) {
//try again without a startCombo
delete MistVideo.options.startCombo;
MistVideo.unload("No compatible players found - retrying without startCombo.");
MistVideo = mistPlay(MistVideo.stream,MistVideo.options);
mistPlay(MistVideo.stream,MistVideo.options);
}
else {
MistVideo.showError("No compatible player/source combo found.",{reload:true});
@ -966,6 +966,7 @@ function MistVideo(streamName,options) {
this.wasConnected = true;
//report player status to MistServer
if (!MistVideo.reporting) {
MistVideo.reporting = {
stats: {
set: function(key,value){
@ -1007,7 +1008,7 @@ function MistVideo(streamName,options) {
}
},
report: function(d){
socket.send(JSON.stringify(d));
MistVideo.socket.send(JSON.stringify(d));
},
reportStats: function(){
var d = {};
@ -1138,6 +1139,7 @@ function MistVideo(streamName,options) {
}
};
}
};
socket.onclose = function(e){
@ -1384,13 +1386,13 @@ function MistVideo(streamName,options) {
var time = ("player" in this && "api" in this.player ? this.player.api.currentTime : false);
this.unload(reason);
MistVideo = mistPlay(this.stream,this.options);
var NewMistVideo = mistPlay(this.stream,this.options);
if ((time) && (this.info.type != "live")) {
//after load, try to restore the video position
var f = function(){
if (MistVideo.player && MistVideo.player.api) {
MistVideo.player.api.currentTime = time;
if (NewMistVideo.player && NewMistVideo.player.api) {
NewMistVideo.player.api.currentTime = time;
}
this.removeEventListener("initialized",f);
};

View file

@ -333,14 +333,45 @@ p.prototype.build = function (MistVideo,callback) {
this.ws = new WebSocket(MistVideo.source.url);
this.ws.binaryType = "arraybuffer";
this.ws.s = this.ws.send;
this.ws.send = function(){
if (this.readyState == 1) {
return this.s.apply(this,arguments);
}
return false;
};
this.ws.onopen = function(){
this.wasConnected = true;
resolve();
};
this.ws.onerror = function(e){
MistVideo.showError("MP4 over WS: websocket error");
}
};
this.ws.onclose = function(e){
MistVideo.log("MP4 over WS: websocket closed");
if (this.wasConnected && (!MistVideo.destroyed)) {
MistVideo.log("MP4 over WS: reopening websocket");
player.wsconnect().then(function(){
if (!player.sb) {
//retrieve codec info
var f = function(msg){
//got codec data, set up source buffer
if (!player.sb) { player.sbinit(msg.data.codecs); }
else { player.api.play(); }
player.ws.removeListener("codec_data",f);
};
player.ws.addListener("codec_data",f);
send({type:"request_codec_data",supported_codecs:MistVideo.source.supportedCodecs});
}
else {
player.api.play();
}
},function(){
Mistvideo.error("Lost connection to the Media Server");
});
}
};
this.ws.listeners = {}; //kind of event listener list for websocket messages
this.ws.addListener = function(type,f){