contact-js: made channel handle onChannelError

This commit is contained in:
Logan Allen 2020-04-14 18:16:44 -04:00
parent bfcaf6468e
commit 0145981542
2 changed files with 30 additions and 8 deletions

View File

@ -9,14 +9,7 @@ import { LocalReducer } from '/reducers/local.js';
class Store {
constructor() {
this.state = {
contacts: {},
groups: {},
associations: {},
permissions: {},
invites: {},
selectedGroups: []
};
this.state = this.initialState();
this.initialReducer = new InitialReducer();
this.groupUpdateReducer = new GroupUpdateReducer();
@ -28,6 +21,17 @@ class Store {
this.setState = () => {};
}
initialState() {
return {
contacts: {},
groups: {},
associations: {},
permissions: {},
invites: {},
selectedGroups: []
};
}
setStateHandler(setState) {
this.setState = setState;
}
@ -35,6 +39,11 @@ class Store {
handleEvent(data) {
let json = data.data;
if ('clear' in json && json.clear) {
this.setState(this.initialState());
return;
}
console.log(json);
this.initialReducer.reduce(json, this.state);
this.groupUpdateReducer.reduce(json, this.state);

View File

@ -13,11 +13,24 @@ export class Subscription {
start() {
if (api.authTokens) {
this.firstRoundSubscription();
window.urb.setOnChannelError(this.onChannelError.bind(this));
} else {
console.error("~~~ ERROR: Must set api.authTokens before operation ~~~");
}
}
onChannelError(err) {
console.error('event source error: ', err);
console.log('initiating new channel');
this.firstRoundSubscriptionComplete = false;
setTimeout(2000, () => {
store.handleEvent({
data: { clear : true}
});
this.start();
});
}
subscribe(path, app) {
api.bind(path, 'PUT', api.authTokens.ship, app,
this.handleEvent.bind(this),