Fix autoupdate after auth

Remove data after logout
This commit is contained in:
Oskar Hahn 2016-01-09 17:32:33 +01:00
parent dba513c2fd
commit 5069649e14
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() {
.factory('autoupdate', [
'DS',
function (DS) {
var url = location.origin + "/sockjs";
var socket;
var Autoupdate = {
socket: null,
message_receivers: [],
connect: function() {
connect: function () {
var autoupdate = this;
this.socket = new SockJS(url);
socket = this.socket = new SockJS(url);
this.socket.onmessage = function(event) {
_.forEach(autoupdate.message_receivers, function(receiver) {
this.socket.onmessage = function (event) {
_.forEach(autoupdate.message_receivers, function (receiver) {
receiver(event.data);
});
};
this.socket.onclose = function() {
this.socket.onclose = function () {
setTimeout(autoupdate.connect, 5000);
};
},
on_message: function(receiver) {
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) {