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 @@ -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) {
console.info("Video state active (assuming connected)", currentcall.id);

21
static/js/mediastream/api.js

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

Loading…
Cancel
Save