Fix the autoupdate

This commit is contained in:
Oskar Hahn 2016-02-01 23:21:50 +01:00
parent a2d8b41d55
commit 09cbe8c9e4

View File

@ -43,6 +43,15 @@ angular.module('OpenSlidesApp.core', [
var recInterval = null; var recInterval = null;
$rootScope.connected = true; $rootScope.connected = true;
var Autoupdate = {
messageReceivers: [],
onMessage: function (receiver) {
this.messageReceivers.push(receiver);
},
reconnect: function () {
socket.close();
}
};
var newConnect = function () { var newConnect = function () {
socket = new SockJS(location.origin + "/sockjs"); socket = new SockJS(location.origin + "/sockjs");
clearInterval(recInterval); clearInterval(recInterval);
@ -56,25 +65,14 @@ angular.module('OpenSlidesApp.core', [
newConnect(); newConnect();
}, 1000); }, 1000);
}; };
};
var Autoupdate = {
messageReceivers: [],
connect: function () {
socket.onmessage = function (event) { socket.onmessage = function (event) {
_.forEach(Autoupdate.messageReceivers, function (receiver) { _.forEach(Autoupdate.messageReceivers, function (receiver) {
receiver(event.data); receiver(event.data);
}); });
}; };
},
on_message: function (receiver) {
this.messageReceivers.push(receiver);
},
reconnect: function () {
socket.close();
}
}; };
newConnect(); newConnect();
Autoupdate.connect();
return Autoupdate; return Autoupdate;
} }
]) ])
@ -168,7 +166,7 @@ angular.module('OpenSlidesApp.core', [
'autoupdate', 'autoupdate',
'dsEject', 'dsEject',
function (DS, autoupdate, dsEject) { function (DS, autoupdate, dsEject) {
autoupdate.on_message(function(data) { autoupdate.onMessage(function(data) {
// TODO: when MODEL.find() is called after this // TODO: when MODEL.find() is called after this
// a new request is fired. This could be a bug in DS // a new request is fired. This could be a bug in DS