Embed: improved behavior when websocket disconnects
This commit is contained in:
parent
51147c3df5
commit
8e8017dfd9
4 changed files with 196 additions and 163 deletions
|
@ -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){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue