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. 59
      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);

59
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,35 +45,39 @@ 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;
var last_receive = this.last_receive; this.last_receive_overdue = false;
if (this.connector.connected) {
if (last_receive !== null) { };
//console.log("api heartbeat", this.last_receive);
var now = new Date().getTime(); Api.prototype.heartbeat = function(timeout, timeout2) {
if (this.last_receive_overdue) {
if (now > last_receive + alive_check_timeout_2) { // Heartbeat emitter.
console.log("Reconnecting because alive timeout was reached."); var last_receive = this.last_receive;
this.last_receive_overdue = false; if (this.connector.connected) {
this.last_receive = null; if (last_receive !== null) {
this.connector.disconnect(true); //console.log("api heartbeat", this.last_receive);
} var now = new Date().getTime();
} else { if (this.last_receive_overdue) {
if (now > last_receive + alive_check_timeout) { if (now > last_receive + timeout2) {
//console.log("overdue 1"); console.log("Reconnecting because alive timeout was reached.");
this.last_receive_overdue = true; this.last_receive_overdue = false;
this.sendAlive(now); this.last_receive = null;
} this.connector.disconnect(true);
}
} else {
if (now > last_receive + timeout) {
//console.log("overdue 1");
this.last_receive_overdue = true;
this.sendAlive(now);
} }
} }
} else {
this.last_receive = null;
this.last_receive_overdue = false;
} }
}, this), 1000); } else {
this.last_receive = null; this.last_receive = null;
this.last_receive_overdue = false; this.last_receive_overdue = false;
}
}; };

Loading…
Cancel
Save