Embed: improved behavior when websocket disconnects
This commit is contained in:
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
|
@ -908,7 +908,7 @@ function MistVideo(streamName,options) {
|
||||||
//try again without a startCombo
|
//try again without a startCombo
|
||||||
delete MistVideo.options.startCombo;
|
delete MistVideo.options.startCombo;
|
||||||
MistVideo.unload("No compatible players found - retrying without startCombo.");
|
MistVideo.unload("No compatible players found - retrying without startCombo.");
|
||||||
MistVideo = mistPlay(MistVideo.stream,MistVideo.options);
|
mistPlay(MistVideo.stream,MistVideo.options);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
MistVideo.showError("No compatible player/source combo found.",{reload:true});
|
MistVideo.showError("No compatible player/source combo found.",{reload:true});
|
||||||
|
@ -966,6 +966,7 @@ function MistVideo(streamName,options) {
|
||||||
this.wasConnected = true;
|
this.wasConnected = true;
|
||||||
|
|
||||||
//report player status to MistServer
|
//report player status to MistServer
|
||||||
|
if (!MistVideo.reporting) {
|
||||||
MistVideo.reporting = {
|
MistVideo.reporting = {
|
||||||
stats: {
|
stats: {
|
||||||
set: function(key,value){
|
set: function(key,value){
|
||||||
|
@ -1007,7 +1008,7 @@ function MistVideo(streamName,options) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
report: function(d){
|
report: function(d){
|
||||||
socket.send(JSON.stringify(d));
|
MistVideo.socket.send(JSON.stringify(d));
|
||||||
},
|
},
|
||||||
reportStats: function(){
|
reportStats: function(){
|
||||||
var d = {};
|
var d = {};
|
||||||
|
@ -1138,6 +1139,7 @@ function MistVideo(streamName,options) {
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
socket.onclose = function(e){
|
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);
|
var time = ("player" in this && "api" in this.player ? this.player.api.currentTime : false);
|
||||||
|
|
||||||
this.unload(reason);
|
this.unload(reason);
|
||||||
MistVideo = mistPlay(this.stream,this.options);
|
var NewMistVideo = mistPlay(this.stream,this.options);
|
||||||
|
|
||||||
if ((time) && (this.info.type != "live")) {
|
if ((time) && (this.info.type != "live")) {
|
||||||
//after load, try to restore the video position
|
//after load, try to restore the video position
|
||||||
var f = function(){
|
var f = function(){
|
||||||
if (MistVideo.player && MistVideo.player.api) {
|
if (NewMistVideo.player && NewMistVideo.player.api) {
|
||||||
MistVideo.player.api.currentTime = time;
|
NewMistVideo.player.api.currentTime = time;
|
||||||
}
|
}
|
||||||
this.removeEventListener("initialized",f);
|
this.removeEventListener("initialized",f);
|
||||||
};
|
};
|
||||||
|
|
|
@ -333,14 +333,45 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
this.ws = new WebSocket(MistVideo.source.url);
|
this.ws = new WebSocket(MistVideo.source.url);
|
||||||
this.ws.binaryType = "arraybuffer";
|
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.ws.onopen = function(){
|
||||||
|
this.wasConnected = true;
|
||||||
resolve();
|
resolve();
|
||||||
};
|
};
|
||||||
this.ws.onerror = function(e){
|
this.ws.onerror = function(e){
|
||||||
MistVideo.showError("MP4 over WS: websocket error");
|
MistVideo.showError("MP4 over WS: websocket error");
|
||||||
}
|
};
|
||||||
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.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.listeners = {}; //kind of event listener list for websocket messages
|
||||||
this.ws.addListener = function(type,f){
|
this.ws.addListener = function(type,f){
|
||||||
|
|
Loading…
Add table
Reference in a new issue