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

55
static/js/services/videowaiter.js

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

Loading…
Cancel
Save