Embed: improvements to player behaviour when stream input is killed
This commit is contained in:
parent
8a67c43154
commit
fc0ad25778
4 changed files with 39 additions and 9 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -91,6 +91,7 @@ function MistVideo(streamName,options) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.errorListeners = [];
|
this.errorListeners = [];
|
||||||
|
this.resumeTime = false;
|
||||||
|
|
||||||
this.urlappend = function(url){
|
this.urlappend = function(url){
|
||||||
if (this.options.urlappend) {
|
if (this.options.urlappend) {
|
||||||
|
@ -280,6 +281,11 @@ function MistVideo(streamName,options) {
|
||||||
|
|
||||||
function onStreamInfo(d) {
|
function onStreamInfo(d) {
|
||||||
|
|
||||||
|
if ((MistVideo.player) && (MistVideo.player.api) && (MistVideo.player.api.unload)) {
|
||||||
|
MistVideo.log("Received new stream info while a player was already loaded: unloading player");
|
||||||
|
MistVideo.player.api.unload();
|
||||||
|
}
|
||||||
|
|
||||||
MistVideo.info = d;
|
MistVideo.info = d;
|
||||||
MistVideo.info.updated = new Date();
|
MistVideo.info.updated = new Date();
|
||||||
MistUtil.event.send("haveStreamInfo",d,MistVideo.options.target);
|
MistUtil.event.send("haveStreamInfo",d,MistVideo.options.target);
|
||||||
|
@ -373,7 +379,21 @@ function MistVideo(streamName,options) {
|
||||||
}
|
}
|
||||||
d.lastms = maxms;
|
d.lastms = maxms;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
//If this is VoD and was already playing, return to the previous time
|
||||||
|
//this is triggered when the MistInput is killed/crashes during playback
|
||||||
|
|
||||||
|
var time = MistVideo.resumeTime;
|
||||||
|
if (time) {
|
||||||
|
var f = function(){
|
||||||
|
if (MistVideo.player && MistVideo.player.api) {
|
||||||
|
MistVideo.player.api.currentTime = time;
|
||||||
|
}
|
||||||
|
this.removeEventListener("initialized",f);
|
||||||
|
};
|
||||||
|
MistUtil.event.addListener(MistVideo.options.target,"initialized",f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (MistVideo.choosePlayer()) {
|
if (MistVideo.choosePlayer()) {
|
||||||
|
@ -946,6 +966,9 @@ function MistVideo(streamName,options) {
|
||||||
switch (data.error) {
|
switch (data.error) {
|
||||||
case "Stream is offline":
|
case "Stream is offline":
|
||||||
MistVideo.info = false;
|
MistVideo.info = false;
|
||||||
|
if (MistVideo.player && MistVideo.player.api && MistVideo.player.api.currentTime) {
|
||||||
|
MistVideo.resumeTime = MistVideo.player.api.currentTime;
|
||||||
|
}
|
||||||
case "Stream is initializing":
|
case "Stream is initializing":
|
||||||
case "Stream is booting":
|
case "Stream is booting":
|
||||||
case "Stream is waiting for data":
|
case "Stream is waiting for data":
|
||||||
|
|
|
@ -100,10 +100,11 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
If MistOutWebRTC crashes, we receive an on_stop and then an on_disconnect
|
If MistOutWebRTC crashes, we receive an on_stop and then an on_disconnect
|
||||||
*/
|
*/
|
||||||
if (!hasended) {
|
if (!hasended) {
|
||||||
MistVideo.showError("Connection to media server ended unexpectedly.");
|
//MistVideo.showError("Connection to media server ended unexpectedly.");
|
||||||
video.pause();
|
video.pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//this.webrtc.signaling.ws.close();
|
||||||
},
|
},
|
||||||
on_answer_sdp: function (ev) {
|
on_answer_sdp: function (ev) {
|
||||||
if (!ev.result) {
|
if (!ev.result) {
|
||||||
|
@ -201,7 +202,6 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
var thisWebRTCPlayer = this;
|
var thisWebRTCPlayer = this;
|
||||||
|
|
||||||
this.on_event = function(ev) {
|
this.on_event = function(ev) {
|
||||||
//if (ev.type != "on_time") { console.log(ev); }
|
|
||||||
switch (ev.type) {
|
switch (ev.type) {
|
||||||
case "on_connected": {
|
case "on_connected": {
|
||||||
thisWebRTCPlayer.isConnected = true;
|
thisWebRTCPlayer.isConnected = true;
|
||||||
|
@ -229,6 +229,7 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.connect = function(callback){
|
this.connect = function(callback){
|
||||||
|
thisWebRTCPlayer.isConnecting = true;
|
||||||
|
|
||||||
//chrome on android has a bug where H264 is not available immediately after the tab is opened: https://bugs.chromium.org/p/webrtc/issues/detail?id=11620
|
//chrome on android has a bug where H264 is not available immediately after the tab is opened: https://bugs.chromium.org/p/webrtc/issues/detail?id=11620
|
||||||
//this workaround tries 5x with 100ms intervals before continuing
|
//this workaround tries 5x with 100ms intervals before continuing
|
||||||
|
@ -257,7 +258,6 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
checkH264(5).catch(function(){
|
checkH264(5).catch(function(){
|
||||||
MistVideo.log("Beware: this device does not seem to be able to play H264.");
|
MistVideo.log("Beware: this device does not seem to be able to play H264.");
|
||||||
}).finally(function(){
|
}).finally(function(){
|
||||||
thisWebRTCPlayer.isConnecting = true;
|
|
||||||
thisWebRTCPlayer.signaling = new WebRTCSignaling(thisWebRTCPlayer.on_event);
|
thisWebRTCPlayer.signaling = new WebRTCSignaling(thisWebRTCPlayer.on_event);
|
||||||
thisWebRTCPlayer.peerConn = new RTCPeerConnection();
|
thisWebRTCPlayer.peerConn = new RTCPeerConnection();
|
||||||
thisWebRTCPlayer.peerConn.ontrack = function(ev) {
|
thisWebRTCPlayer.peerConn.ontrack = function(ev) {
|
||||||
|
@ -373,6 +373,8 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
|
|
||||||
this.ws = new WebSocket(MistVideo.source.url.replace(/^http/,"ws"));
|
this.ws = new WebSocket(MistVideo.source.url.replace(/^http/,"ws"));
|
||||||
|
|
||||||
|
var ignoreopen = false;
|
||||||
|
|
||||||
this.ws.onopen = function() {
|
this.ws.onopen = function() {
|
||||||
onEvent({type: "on_connected"});
|
onEvent({type: "on_connected"});
|
||||||
};
|
};
|
||||||
|
@ -390,8 +392,11 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
/* See http://tools.ietf.org/html/rfc6455#section-7.4.1 */
|
/* See http://tools.ietf.org/html/rfc6455#section-7.4.1 */
|
||||||
this.ws.onclose = function(ev) {
|
this.ws.onclose = function(ev) {
|
||||||
switch (ev.code) {
|
switch (ev.code) {
|
||||||
|
case 1006: {
|
||||||
|
//MistVideo.showError("WebRTC websocket closed unexpectedly");
|
||||||
|
}
|
||||||
default: {
|
default: {
|
||||||
onEvent({type: "on_disconnected"});
|
onEvent({type: "on_disconnected", code: ev.code});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -407,7 +412,6 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
this.ws.send(JSON.stringify(cmd));
|
this.ws.send(JSON.stringify(cmd));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.webrtc = new WebRTCPlayer();
|
this.webrtc = new WebRTCPlayer();
|
||||||
|
|
||||||
this.api = {};
|
this.api = {};
|
||||||
|
@ -594,8 +598,10 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
//loop
|
//loop
|
||||||
MistUtil.event.addListener(video,"ended",function(){
|
MistUtil.event.addListener(video,"ended",function(){
|
||||||
if (me.api.loop) {
|
if (me.api.loop) {
|
||||||
|
if (MistVideo.state == "Stream is online") {
|
||||||
me.webrtc.connect();
|
me.webrtc.connect();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if ("decodingIssues" in MistVideo.skin.blueprints) {
|
if ("decodingIssues" in MistVideo.skin.blueprints) {
|
||||||
|
@ -625,6 +631,7 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
me.api.unload = function(){
|
me.api.unload = function(){
|
||||||
try {
|
try {
|
||||||
me.webrtc.stop();
|
me.webrtc.stop();
|
||||||
|
me.webrtc.signaling.ws.close();
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue