Reconnect at once. Do not wait 5 seconds. Add a connected flag to the root scope

Fixes #1854

See also #1853
This commit is contained in:
Oskar Hahn 2016-01-27 17:54:40 +01:00
parent d37b89a15a
commit 3b508303a1

View File

@ -36,7 +36,8 @@ angular.module('OpenSlidesApp.core', [
.factory('autoupdate', [ .factory('autoupdate', [
'DS', 'DS',
function (DS) { '$rootScope',
function (DS, $rootScope) {
var url = location.origin + "/sockjs"; var url = location.origin + "/sockjs";
var socket; var socket;
var Autoupdate = { var Autoupdate = {
@ -46,15 +47,20 @@ angular.module('OpenSlidesApp.core', [
var autoupdate = this; var autoupdate = this;
socket = this.socket = new SockJS(url); socket = this.socket = new SockJS(url);
this.socket.onmessage = function (event) { this.socket.onmessage = function (event) {
_.forEach(autoupdate.message_receivers, function (receiver) { _.forEach(autoupdate.message_receivers, function (receiver) {
receiver(event.data); receiver(event.data);
}); });
}; };
this.socket.onopen = function () {
$rootScope.connected = true;
};
this.socket.onclose = function () { this.socket.onclose = function () {
setTimeout(autoupdate.connect, 5000); $rootScope.connected = false;
autoupdate.connect()
}; };
}, },
on_message: function (receiver) { on_message: function (receiver) {
@ -65,6 +71,7 @@ angular.module('OpenSlidesApp.core', [
Autoupdate.connect(); Autoupdate.connect();
} }
}; };
$rootScope.connected = false;
Autoupdate.connect(); Autoupdate.connect();
return Autoupdate; return Autoupdate;
} }