Browse Source

Moved heartbeat time to controller.

pull/156/merge
Simon Eisenmann 11 years ago
parent
commit
f992f50d49
  1. 5
      static/js/controllers/mediastreamcontroller.js
  2. 21
      static/js/mediastream/api.js

5
static/js/controllers/mediastreamcontroller.js

@ -580,6 +580,11 @@ define(['jquery', 'underscore', 'angular', 'bigscreen', 'moment', 'sjcl', 'moder
} }
}); });
// Start heartbeat timer.
$window.setInterval(function() {
mediaStream.api.heartbeat(5000, 11500)
}, 1000);
$scope.$on("active", function(event, currentcall) { $scope.$on("active", function(event, currentcall) {
console.info("Video state active (assuming connected)", currentcall.id); console.info("Video state active (assuming connected)", currentcall.id);

21
static/js/mediastream/api.js

@ -22,9 +22,6 @@
"use strict"; "use strict";
define(['jquery', 'underscore', 'ua-parser'], function($, _, uaparser) { define(['jquery', 'underscore', 'ua-parser'], function($, _, uaparser) {
var alive_check_timeout = 5000;
var alive_check_timeout_2 = 10000;
var Api = function(version, connector) { var Api = function(version, connector) {
this.version = version; this.version = version;
this.id = null; this.id = null;
@ -48,22 +45,29 @@ define(['jquery', 'underscore', 'ua-parser'], function($, _, uaparser) {
this.received(data); this.received(data);
}, this)); }, this));
// Trigger alive heartbeat when nothing is received for a while. // Heartbeat support.
this.heartbeat = window.setInterval(_.bind(function() { this.last_receive = null;
this.last_receive_overdue = false;
};
Api.prototype.heartbeat = function(timeout, timeout2) {
// Heartbeat emitter.
var last_receive = this.last_receive; var last_receive = this.last_receive;
if (this.connector.connected) { if (this.connector.connected) {
if (last_receive !== null) { if (last_receive !== null) {
//console.log("api heartbeat", this.last_receive); //console.log("api heartbeat", this.last_receive);
var now = new Date().getTime(); var now = new Date().getTime();
if (this.last_receive_overdue) { if (this.last_receive_overdue) {
if (now > last_receive + alive_check_timeout_2) { if (now > last_receive + timeout2) {
console.log("Reconnecting because alive timeout was reached."); console.log("Reconnecting because alive timeout was reached.");
this.last_receive_overdue = false; this.last_receive_overdue = false;
this.last_receive = null; this.last_receive = null;
this.connector.disconnect(true); this.connector.disconnect(true);
} }
} else { } else {
if (now > last_receive + alive_check_timeout) { if (now > last_receive + timeout) {
//console.log("overdue 1"); //console.log("overdue 1");
this.last_receive_overdue = true; this.last_receive_overdue = true;
this.sendAlive(now); this.sendAlive(now);
@ -74,9 +78,6 @@ define(['jquery', 'underscore', 'ua-parser'], function($, _, uaparser) {
this.last_receive = null; this.last_receive = null;
this.last_receive_overdue = false; this.last_receive_overdue = false;
} }
}, this), 1000);
this.last_receive = null;
this.last_receive_overdue = false;
}; };

Loading…
Cancel
Save