From 3b508303a1e93c421de40921de282a72eb819d89 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Wed, 27 Jan 2016 17:54:40 +0100 Subject: [PATCH] Reconnect at once. Do not wait 5 seconds. Add a connected flag to the root scope Fixes #1854 See also #1853 --- openslides/core/static/js/core/base.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/openslides/core/static/js/core/base.js b/openslides/core/static/js/core/base.js index 83c970df6..57a0b8a3d 100644 --- a/openslides/core/static/js/core/base.js +++ b/openslides/core/static/js/core/base.js @@ -36,7 +36,8 @@ angular.module('OpenSlidesApp.core', [ .factory('autoupdate', [ 'DS', - function (DS) { + '$rootScope', + function (DS, $rootScope) { var url = location.origin + "/sockjs"; var socket; var Autoupdate = { @@ -46,15 +47,20 @@ angular.module('OpenSlidesApp.core', [ var autoupdate = this; socket = this.socket = new SockJS(url); - this.socket.onmessage = function (event) { _.forEach(autoupdate.message_receivers, function (receiver) { receiver(event.data); }); }; + this.socket.onopen = function () { + $rootScope.connected = true; + }; + this.socket.onclose = function () { - setTimeout(autoupdate.connect, 5000); + $rootScope.connected = false; + autoupdate.connect() + }; }, on_message: function (receiver) { @@ -65,6 +71,7 @@ angular.module('OpenSlidesApp.core', [ Autoupdate.connect(); } }; + $rootScope.connected = false; Autoupdate.connect(); return Autoupdate; }