Embed: WebRTC improvements:
- make webrtc obey autoplay = false; when video is paused, disable autoplay and vise versa - silenced some unneccesary webrtc errors - webrtc: pause player on stop, so that "stream offline" message is shown - improved webrtc wrapper robustness - more webrtc don't autoplay when paused - when not yet connected during a seek, wait until connected and seek then
This commit is contained in:
parent
01b957d136
commit
214b584956
6 changed files with 51 additions and 10 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -943,6 +943,7 @@ function MistVideo(streamName,options) {
|
||||||
case "Stream status is invalid?!":
|
case "Stream status is invalid?!":
|
||||||
if ((MistVideo.player) && (MistVideo.player.api) && (!MistVideo.player.api.paused)) {
|
if ((MistVideo.player) && (MistVideo.player.api) && (!MistVideo.player.api.paused)) {
|
||||||
//something is (still) playing
|
//something is (still) playing
|
||||||
|
MistVideo.log(data.error,"error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
buttons = {polling:true};
|
buttons = {polling:true};
|
||||||
|
|
|
@ -900,6 +900,7 @@ MistSkins["default"] = {
|
||||||
//obey video states
|
//obey video states
|
||||||
MistUtil.event.addListener(video,"playing",function(){
|
MistUtil.event.addListener(video,"playing",function(){
|
||||||
button.setState("playing");
|
button.setState("playing");
|
||||||
|
MistVideo.options.autoplay = true;
|
||||||
},button);
|
},button);
|
||||||
MistUtil.event.addListener(video,"pause",function(){
|
MistUtil.event.addListener(video,"pause",function(){
|
||||||
button.setState("paused");
|
button.setState("paused");
|
||||||
|
@ -919,6 +920,7 @@ MistSkins["default"] = {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
MistVideo.player.api.pause();
|
MistVideo.player.api.pause();
|
||||||
|
MistVideo.options.autoplay = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -926,7 +928,10 @@ MistSkins["default"] = {
|
||||||
if (MistVideo.player.api) {
|
if (MistVideo.player.api) {
|
||||||
MistUtil.event.addListener(MistVideo.video,"click",function(){
|
MistUtil.event.addListener(MistVideo.video,"click",function(){
|
||||||
if (MistVideo.player.api.paused) { MistVideo.player.api.play(); }
|
if (MistVideo.player.api.paused) { MistVideo.player.api.play(); }
|
||||||
else if (!MistUtil.isTouchDevice()) { MistVideo.player.api.pause(); }
|
else if (!MistUtil.isTouchDevice()) {
|
||||||
|
MistVideo.player.api.pause();
|
||||||
|
MistVideo.options.autoplay = false;
|
||||||
|
}
|
||||||
},button);
|
},button);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -421,7 +421,7 @@ var MistUtil = {
|
||||||
sanitizeHost: function(host){
|
sanitizeHost: function(host){
|
||||||
var split = MistUtil.http.url.split(host);
|
var split = MistUtil.http.url.split(host);
|
||||||
var out = split.protocol + "//" + split.host + (split.port && (split.port != "") ? ":"+split.port : "") + (split.hash && (split.hash != "") ? "#"+split.hash : "") + (split.path ? (split.path.charAt(0) == "/" ? split.path : "/"+split.path) : "");
|
var out = split.protocol + "//" + split.host + (split.port && (split.port != "") ? ":"+split.port : "") + (split.hash && (split.hash != "") ? "#"+split.hash : "") + (split.path ? (split.path.charAt(0) == "/" ? split.path : "/"+split.path) : "");
|
||||||
console.log("converted",host,"to",out);
|
//console.log("converted",host,"to",out);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,20 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
MistUtil.event.addListener(video,"loadeddata",correctSubtitleSync);
|
MistUtil.event.addListener(video,"loadeddata",correctSubtitleSync);
|
||||||
MistUtil.event.addListener(video,"seeked",correctSubtitleSync);
|
MistUtil.event.addListener(video,"seeked",correctSubtitleSync);
|
||||||
|
|
||||||
|
if (!MistVideo.options.autoplay) {
|
||||||
|
MistUtil.event.addListener(video,"canplay",function(){
|
||||||
|
var onplay = MistUtil.event.addListener(video,"play",function(){
|
||||||
|
MistVideo.log("Pausing because autoplay is disabled");
|
||||||
|
var onpause = MistUtil.event.addListener(video,"pause",function(){
|
||||||
|
MistVideo.options.autoplay = false;
|
||||||
|
MistUtil.event.removeListener(onpause);
|
||||||
|
});
|
||||||
|
me.api.pause();
|
||||||
|
MistUtil.event.removeListener(onplay);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var seekoffset = 0;
|
var seekoffset = 0;
|
||||||
var hasended = false;
|
var hasended = false;
|
||||||
var currenttracks = [];
|
var currenttracks = [];
|
||||||
|
@ -84,10 +98,11 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
If a live stream ends, we receive an on_disconnect, but no on_stop
|
If a live stream ends, we receive an on_disconnect, but no on_stop
|
||||||
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();
|
|
||||||
},
|
},
|
||||||
on_answer_sdp: function (ev) {
|
on_answer_sdp: function (ev) {
|
||||||
if (!ev.result) {
|
if (!ev.result) {
|
||||||
|
@ -113,8 +128,8 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
MistUtil.event.send("durationchange",d,video);
|
MistUtil.event.send("durationchange",d,video);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currenttracks != ev.tracks) {
|
if ((ev.tracks) && (currenttracks != ev.tracks)) {
|
||||||
var tracks = MistUtil.tracks.parse(MistVideo.info.meta.tracks);
|
var tracks = MistVideo.info ? MistUtil.tracks.parse(MistVideo.info.meta.tracks) : [];
|
||||||
for (var i in ev.tracks) {
|
for (var i in ev.tracks) {
|
||||||
if (currenttracks.indexOf(ev.tracks[i]) < 0) {
|
if (currenttracks.indexOf(ev.tracks[i]) < 0) {
|
||||||
//find track type
|
//find track type
|
||||||
|
@ -169,6 +184,7 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
},
|
},
|
||||||
on_stop: function(){
|
on_stop: function(){
|
||||||
MistVideo.log("Websocket sent on_stop");
|
MistVideo.log("Websocket sent on_stop");
|
||||||
|
video.pause();
|
||||||
MistUtil.event.send("ended",null,video);
|
MistUtil.event.send("ended",null,video);
|
||||||
hasended = true;
|
hasended = true;
|
||||||
}
|
}
|
||||||
|
@ -247,7 +263,19 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
};
|
};
|
||||||
this.seek = function(seekTime){
|
this.seek = function(seekTime){
|
||||||
var p = new Promise(function(resolve,reject){
|
var p = new Promise(function(resolve,reject){
|
||||||
if (!thisWebRTCPlayer.isConnected || !thisWebRTCPlayer.signaling) { return reject("Failed seek: not connected"); }
|
if (!thisWebRTCPlayer.isConnected || !thisWebRTCPlayer.signaling) {
|
||||||
|
if (thisWebRTCPlayer.isConnecting) {
|
||||||
|
|
||||||
|
var listener = MistUtil.event.addListener(MistVideo.video,"loadstart",function(){
|
||||||
|
thisWebRTCPlayer.seek(seekTime);
|
||||||
|
MistUtil.event.removeListener(listener);
|
||||||
|
});
|
||||||
|
return reject("Not connected yet, will seek once connected");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return reject("Failed seek: not connected");
|
||||||
|
}
|
||||||
|
}
|
||||||
thisWebRTCPlayer.signaling.send({type: "seek", "seek_time": (seekTime == "live" ? "live" : seekTime*1e3)});
|
thisWebRTCPlayer.signaling.send({type: "seek", "seek_time": (seekTime == "live" ? "live" : seekTime*1e3)});
|
||||||
if ("seekPromise" in thisWebRTCPlayer.signaling) {
|
if ("seekPromise" in thisWebRTCPlayer.signaling) {
|
||||||
thisWebRTCPlayer.signaling.seekPromise.reject("Doing new seek");
|
thisWebRTCPlayer.signaling.seekPromise.reject("Doing new seek");
|
||||||
|
@ -368,8 +396,15 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
set: function(value){
|
set: function(value){
|
||||||
seekoffset = value - video.currentTime;
|
seekoffset = value - video.currentTime;
|
||||||
video.pause();
|
video.pause();
|
||||||
me.webrtc.seek(value);
|
var promise = me.webrtc.seek(value);
|
||||||
MistUtil.event.send("seeking",value,video);
|
MistUtil.event.send("seeking",value,video);
|
||||||
|
if (promise) {
|
||||||
|
promise.catch(function(e){
|
||||||
|
//do nothing
|
||||||
|
//keep this code because not handling this shows an error message in the console:
|
||||||
|
// (Uncaught (in promise) Failed seek: not connected)
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue