Embed: remove forbidden modern code (blegh! filthy modern stuff brrr) from the webrtc wrapper

This commit is contained in:
Cat 2021-10-07 15:55:49 +02:00 committed by Thulinma
parent b6068f4627
commit 615fad6be9
10 changed files with 79 additions and 27 deletions

View file

@ -7,7 +7,7 @@ mistplayers.mews = {
},
isBrowserSupported: function (mimetype,source,MistVideo) {
if ((!("WebSocket" in window)) || (!("MediaSource" in window))) { return false; }
if ((!("WebSocket" in window)) || (!("MediaSource" in window)) || (!("Promise" in window))) { return false; }
//check for http/https mismatch
if (location.protocol.replace(/^http/,"ws") != MistUtil.http.url.split(source.url.replace(/^http/,"ws")).protocol) {
@ -379,7 +379,8 @@ p.prototype.build = function (MistVideo,callback) {
this.ws.s = this.ws.send;
this.ws.send = function(){
if (this.readyState == 1) {
return this.s.apply(this,arguments);
this.s.apply(this,arguments);
return true;
}
return false;
};
@ -885,8 +886,15 @@ p.prototype.build = function (MistVideo,callback) {
send({type:"request_codec_data",supported_codecs:MistVideo.source.supportedCodecs});
}.bind(this));
function send(cmd){
function send(cmd,retry){
if (!player.ws) { throw "No websocket to send to"; }
if (retry > 5) { throw "Too many retries, giving up"; }
if (player.ws.readyState < player.ws.OPEN) {
MistVideo.timers.start(function(){
send(cmd,++retry);
},500);
return;
}
if (player.ws.readyState >= player.ws.CLOSING) {
//throw "WebSocket has been closed already.";
MistVideo.log("MP4 over WS: reopening websocket");
@ -913,9 +921,11 @@ p.prototype.build = function (MistVideo,callback) {
return;
}
if (player.debugging) { console.log("ws send",cmd); }
player.ws.serverDelay.log(cmd.type);
player.ws.send(JSON.stringify(cmd));
if (!player.ws.send(JSON.stringify(cmd))) {
//not able to send, not sure why.. go back to retry
return send(cmd,++retry);
}
}
player.findBuffer = function (position) {
@ -1133,7 +1143,9 @@ p.prototype.build = function (MistVideo,callback) {
if (player.api.loop) {
player.api.currentTime = 0;
player.sb._do(function(){
player.sb.remove(0,Infinity);
try {
player.sb.remove(0,Infinity);
} catch (e) {}
});
}
});

View file

@ -3,7 +3,7 @@ mistplayers.videojs = {
mimes: ["html5/application/vnd.apple.mpegurl","html5/application/vnd.apple.mpegurl;version=7"],
priority: MistUtil.object.keys(mistplayers).length + 1,
isMimeSupported: function (mimetype) {
return (this.mimes.indexOf(mimetype) == -1 ? false : true);
return (MistUtil.array.indexOf(this.mimes,mimetype) == -1 ? false : true);
},
isBrowserSupported: function (mimetype,source,MistVideo) {
@ -82,6 +82,29 @@ p.prototype.build = function (MistVideo,callback) {
else {
vjsopts.controls = false;
}
//capture any errors generated before videojs is initialized and ignore them
var captureErrors = MistUtil.event.addListener(ele,"error",function(e){
e.stopImmediatePropagation();
var msg = e.message;
if (!msg && ele.error) {
if (("code" in ele.error) && (ele.error.code)) {
msg = "Code "+ele.error.code;
for (var i in ele.error) {
if (i == "code") { continue; }
if (ele.error[i] == ele.error.code) {
msg = i;
break;
}
}
}
else {
msg = JSON.stringify(ele.error);
}
}
MistVideo.log("Error captured and stopped because videojs has not yet loaded: "+msg);
});
//for android < 7, enable override native
function androidVersion(){
@ -99,6 +122,9 @@ p.prototype.build = function (MistVideo,callback) {
me.onready(function(){
MistVideo.log("Building videojs");
me.videojs = videojs(ele,vjsopts,function(){
//remove error grabbing
MistUtil.event.removeListener(captureErrors);
MistVideo.log("Videojs initialized");
if (MistVideo.info.type == "live") {
@ -111,7 +137,7 @@ p.prototype.build = function (MistVideo,callback) {
});
MistUtil.event.addListener(ele,"error",function(e){
if (e.target.error.message.indexOf("NS_ERROR_DOM_MEDIA_OVERFLOW_ERR") >= 0) {
if (e && e.target && e.target.error && e.target.error.message && (MistUtil.array.indexOf(e.target.error.message,"NS_ERROR_DOM_MEDIA_OVERFLOW_ERR") >= 0)) {
//there is a problem with a certain segment, try reloading
MistVideo.timers.start(function(){
MistVideo.log("Reloading player because of NS_ERROR_DOM_MEDIA_OVERFLOW_ERR");

View file

@ -602,15 +602,16 @@ p.prototype.build = function (MistVideo,callback) {
me.api.getStats = function(){
if (me.webrtc && me.webrtc.isConnected) {
return new Promise(function(resolve,reject) {
me.webrtc.peerConn.getStats().then((a) => {
me.webrtc.peerConn.getStats().then(function(a){
var r = {
audio: null,
video: null
};
for (let dictionary of a.values()) {
if (dictionary.type == "track") {
var obj = Object.fromEntries(a);
for (var i in obj) {
if (obj[i].type == "track") {
//average jitter buffer in seconds
r[dictionary.kind] = dictionary;
r[obj[i].kind] = obj[i];
}
}
resolve(r);