Avoid dispatching unneeded socket actions

This commit is contained in:
Ken-Håvard Lieng 2018-10-16 01:04:49 +02:00
parent 7fb0cd3e6a
commit 7658e3bde7
3 changed files with 14 additions and 4 deletions

File diff suppressed because one or more lines are too long

View File

@ -152,6 +152,10 @@ export default function handleSocket({
handlers[type](data);
}
if (type.charAt(0) === '_') {
return;
}
dispatch(action);
});
}

View File

@ -13,6 +13,7 @@ export default class Socket {
jitter: 0.25
});
this.handlers = [];
this.connected = false;
this.connect();
}
@ -26,6 +27,7 @@ export default class Socket {
}, this.connectTimeout);
this.ws.onopen = () => {
this.connected = true;
this.emit('_connected', true);
clearTimeout(this.timeoutConnect);
this.backoff.reset();
@ -33,7 +35,10 @@ export default class Socket {
};
this.ws.onclose = () => {
if (this.connected) {
this.connected = false;
this.emit('_connected', false);
}
clearTimeout(this.timeoutConnect);
clearTimeout(this.timeoutPing);
if (!this.closing) {
@ -57,6 +62,7 @@ export default class Socket {
if (msg.type === 'ping') {
this.send('pong');
return;
}
this.emit(msg.type, msg.data);