Embed: Added websocket timeouts (stream info, mews, webrtc)

This commit is contained in:
Cat 2021-09-09 12:38:22 +02:00 committed by Thulinma
parent 854315afdd
commit f4fd56f170
6 changed files with 36 additions and 4 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1022,9 +1022,21 @@ function MistVideo(streamName,options) {
socket.die = false;
socket.destroy = function(){
this.die = true;
if (MistVideo.reporting) {
MistVideo.reporting.reportStats();
MistVideo.reporting = false;
}
this.onclose = function(){};
this.close();
};
//add a timeout: if the websocket does not connect, switch to http polling
socket.timeOut = MistVideo.timers.start(function(){
if (socket.readyState <= 1) {
//either it hasn't opened yet, or it is open but we've not received a message so this timer hasn't been removed yet
socket.destroy();
openWithGet();
}
},5e3);
socket.onopen = function(e){
this.wasConnected = true;
@ -1096,7 +1108,7 @@ function MistVideo(streamName,options) {
this.report(d);
}
MistVideo.timers.start(function(){
MistVideo.reporting.reportStats();
if (MistVideo.reporting) { MistVideo.reporting.reportStats(); }
},5e3);
},
init: function(){
@ -1224,6 +1236,11 @@ function MistVideo(streamName,options) {
var on_ended_show_state = false;
var on_waiting_show_state = false;
socket.addEventListener("message",function(e){
if (socket.timeOut) {
MistVideo.timers.stop(socket.timeOut);
socket.timeOut = false;
}
var data = JSON.parse(e.data);
if (!data) { MistVideo.showError("Error while parsing stream status stream. Obtained: "+e.data.toString(),{reload:true}); }

View file

@ -406,6 +406,13 @@ p.prototype.build = function (MistVideo,callback) {
});
}
};
this.ws.timeOut = MistVideo.timers.start(function(){
if (player.ws.readyState == 0) {
MistVideo.log("MP4 over WS: socket timeout - try next combo");
MistVideo.nextCombo();
}
},5e3);
this.ws.listeners = {}; //kind of event listener list for websocket messages
this.ws.addListener = function(type,f){
if (!(type in this.listeners)) { this.listeners[type] = []; }

View file

@ -436,6 +436,14 @@ p.prototype.build = function (MistVideo,callback) {
onEvent({type: "on_connected"});
};
this.ws.timeOut = MistVideo.timers.start(function(){
if (MistVideo.player.webrtc.signaling.ws.readyState == 0) {
MistVideo.log("WebRTC: socket timeout - try next combo");
MistVideo.nextCombo();
}
},5e3);
this.ws.onmessage = function(e) {
try {
var cmd = JSON.parse(e.data);