Skip to content

Commit

Permalink
PLT-5750 Add sequence number to websocket connections and events (mat…
Browse files Browse the repository at this point in the history
…termost#5907)

* Add sequence number to websocket connections and events

* Copy pointer instead of pass by value and use int64 over uint64

* Add more logging to missed events
  • Loading branch information
jwilander authored Apr 1, 2017
1 parent 84d7f63 commit 474065d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions actions/websocket_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ export function initialize() {

WebSocketClient.setEventCallback(handleEvent);
WebSocketClient.setFirstConnectCallback(handleFirstConnect);
WebSocketClient.setReconnectCallback(() => reconnect(false));
WebSocketClient.setMissedEventCallback(() => {
if (global.window.mm_config.EnableDeveloper === 'true') {
Client.logClientError('missed websocket event seq=' + WebSocketClient.eventSequence);
}
reconnect(false);
});
WebSocketClient.setCloseCallback(handleClose);
WebSocketClient.initialize(connUrl);
}
Expand Down
13 changes: 13 additions & 0 deletions client/websocket_client.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ export default class WebSocketClient {
this.conn = null;
this.connectionUrl = null;
this.sequence = 1;
this.eventSequence = 0;
this.connectFailCount = 0;
this.eventCallback = null;
this.responseCallbacks = {};
this.firstConnectCallback = null;
this.reconnectCallback = null;
this.missedEventCallback = null;
this.errorCallback = null;
this.closeCallback = null;
}
Expand All @@ -37,6 +39,8 @@ export default class WebSocketClient {
this.connectionUrl = connectionUrl;

this.conn.onopen = () => {
this.eventSequence = 0;

if (token) {
this.sendMessage('authentication_challenge', {token});
}
Expand Down Expand Up @@ -108,6 +112,11 @@ export default class WebSocketClient {
Reflect.deleteProperty(this.responseCallbacks, msg.seq_reply);
}
} else if (this.eventCallback) {
if (msg.seq !== this.eventSequence && this.missedEventCallback) {
console.log('missed websocket event, act_seq=' + msg.seq + ' exp_seq=' + this.eventSequence); //eslint-disable-line no-console
this.missedEventCallback();
}
this.eventSequence = msg.seq + 1;
this.eventCallback(msg);
}
};
Expand All @@ -125,6 +134,10 @@ export default class WebSocketClient {
this.reconnectCallback = callback;
}

setMissedEventCallback(callback) {
this.missedEventCallback = callback;
}

setErrorCallback(callback) {
this.errorCallback = callback;
}
Expand Down

0 comments on commit 474065d

Please sign in to comment.