Merge pull request #1806 from ostcar/fix_autoupdate_after_reload

Fix autoupdate after auth
This commit is contained in:
Norman Jäckel 2016-01-09 18:55:24 +01:00
commit 544efdb06e
2 changed files with 40 additions and 26 deletions

View File

@ -30,33 +30,42 @@ angular.module('OpenSlidesApp.core', [
DSHttpAdapterProvider.defaults.forceTrailingSlash = true;
}])
.factory('autoupdate', function() {
var url = location.origin + "/sockjs";
.factory('autoupdate', [
'DS',
function (DS) {
var url = location.origin + "/sockjs";
var socket;
var Autoupdate = {
socket: null,
message_receivers: [],
connect: function () {
var autoupdate = this;
socket = this.socket = new SockJS(url);
var Autoupdate = {
socket: null,
message_receivers: [],
connect: function() {
var autoupdate = this;
this.socket = new SockJS(url);
this.socket.onmessage = function(event) {
_.forEach(autoupdate.message_receivers, function(receiver) {
receiver(event.data);
});
};
this.socket.onmessage = function (event) {
_.forEach(autoupdate.message_receivers, function (receiver) {
receiver(event.data);
});
};
this.socket.onclose = function() {
setTimeout(autoupdate.connect, 5000);
};
},
on_message: function(receiver) {
this.message_receivers.push(receiver);
}
};
Autoupdate.connect();
return Autoupdate;
})
this.socket.onclose = function () {
setTimeout(autoupdate.connect, 5000);
};
},
on_message: function (receiver) {
this.message_receivers.push(receiver);
},
reconnect: function () {
socket.close();
DS.clear();
Autoupdate.connect();
}
};
Autoupdate.connect();
return Autoupdate;
}
])
.run(['DS', 'autoupdate', function(DS, autoupdate) {
autoupdate.on_message(function(data) {

View File

@ -8,8 +8,9 @@ angular.module('OpenSlidesApp.users', [])
'User',
'Group',
'loadGlobalData',
function(User, Group, loadGlobalData) {
var operatorChangeCallbacks = [];
'autoupdate',
function (User, Group, loadGlobalData, autoupdate) {
var operatorChangeCallbacks = [autoupdate.reconnect];
var operator = {
user: null,
perms: [],
@ -33,6 +34,10 @@ angular.module('OpenSlidesApp.users', [])
});
} else {
operator.user = null;
operator.perms = [];
_.forEach(operatorChangeCallbacks, function (callback) {
callback();
});
Group.find(1).then(function(group) {
operator.perms = group.permissions;
_.forEach(operatorChangeCallbacks, function (callback) {