Browse Source

VideoWaiter should re-check availability of video if video gets unmuted

This fixes receiving videos to not be shown sometimes. Usually caused
when using a TURN server or MCU.
pull/415/head
Leon Klingele 8 years ago committed by Leon Klingele
parent
commit
5fa43f4a86
No known key found for this signature in database
GPG Key ID: 83AEC0FEBAA5D483
  1. 6
      static/js/directives/audiovideo.js
  2. 55
      static/js/services/videowaiter.js

6
static/js/directives/audiovideo.js

@ -146,7 +146,7 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/ @@ -146,7 +146,7 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/
var video = clonedElement.find("video")[0];
$window.attachMediaStream(video, stream);
// Waiter callbacks also count as connected, as browser support (FireFox 25) is not setting state changes properly.
videoWaiter.wait(video, stream, function(withvideo) {
videoWaiter.wait(video, stream, function(withvideo, retriggered) {
if (scope.destroyed) {
console.log("Abort wait for video on destroyed scope.");
return;
@ -163,7 +163,9 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/ @@ -163,7 +163,9 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/
$scope.onlyaudio = true;
});
}
scope.$emit("active", currentcall);
if (!retriggered) {
scope.$emit("active", currentcall);
}
$scope.redraw();
}, function() {
if (scope.destroyed) {

55
static/js/services/videowaiter.js

@ -24,39 +24,61 @@ define(["underscore"], function(_) { @@ -24,39 +24,61 @@ define(["underscore"], function(_) {
return ["$window", function($window) {
var Waiter = function() {
var Waiter = function(video, stream, cb, err_cb) {
this.stop = false;
this.triggered = false;
this.count = 0;
this.retries = 100;
this.video = video;
this.stream = stream;
this.cb = cb;
this.err_cb = err_cb;
};
Waiter.prototype.trigger = function() {
var oldTriggered = this.triggered;
this.triggered = true;
return oldTriggered;
};
Waiter.prototype.error = function() {
var triggered = this.trigger();
if (this.err_cb) {
this.err_cb(this.video, this.stream, triggered);
}
};
Waiter.prototype.start = function(video, stream, cb, err_cb) {
Waiter.prototype.found = function(withvideo) {
var triggered = this.trigger();
this.cb(withvideo, triggered);
};
Waiter.prototype.start = function() {
if (this.stop) {
if (err_cb) {
err_cb(video, stream);
}
this.error();
return;
}
var videoTracks = stream && stream.getVideoTracks() || [];
var recheck = _.bind(this.start, this);
var videoTracks = this.stream && this.stream.getVideoTracks() || [];
//console.log("wait for video", videoTracks.length, video.currentTime, video.videoHeight, video);
if (videoTracks.length === 0 && this.count >= 10) {
cb(false, video, stream);
} else if (video.currentTime > 0 && video.videoHeight > 0) {
cb(true, video, stream);
this.found(false);
} else if (this.video.currentTime > 0 && this.video.videoHeight > 0) {
this.found(true);
} else {
if (videoTracks.length > 0 && this.count >= 10) {
var videoTrack = videoTracks[0];
if (videoTrack.enabled === true && videoTrack.muted === true) {
cb(false, video, stream);
videoTrack.onunmute = function() {
videoTrack.onunmute = undefined;
_.defer(recheck);
};
this.found(false);
return;
}
}
this.count++;
if (this.count < this.retries) {
$window.setTimeout(_.bind(this.start, this, video, stream, cb, err_cb), 100);
$window.setTimeout(recheck, 100);
} else {
if (err_cb) {
err_cb(video, stream);
}
this.error();
}
}
};
@ -67,9 +89,9 @@ define(["underscore"], function(_) { @@ -67,9 +89,9 @@ define(["underscore"], function(_) {
// videoWaiter wait
return {
wait: function(video, stream, cb, err_cb) {
var waiter = new Waiter();
var waiter = new Waiter(video, stream, cb, err_cb);
_.defer(function() {
waiter.start(video, stream, cb, err_cb);
waiter.start();
});
return waiter;
}
@ -77,5 +99,4 @@ define(["underscore"], function(_) { @@ -77,5 +99,4 @@ define(["underscore"], function(_) {
}]
});

Loading…
Cancel
Save