diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-04-01 11:39:13 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-01 11:39:13 -0400 |
commit | 95da05a8c97332d8eff90c7587ed17a41966c5f0 (patch) | |
tree | d50084481487988ad83deb5ab6af2be7d2a9f110 /webapp | |
parent | d39947f53933ee4beb4ed8ab614324edc36fba2d (diff) | |
download | chat-95da05a8c97332d8eff90c7587ed17a41966c5f0.tar.gz chat-95da05a8c97332d8eff90c7587ed17a41966c5f0.tar.bz2 chat-95da05a8c97332d8eff90c7587ed17a41966c5f0.zip |
PLT-5750 Add sequence number to websocket connections and events (#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
Diffstat (limited to 'webapp')
-rw-r--r-- | webapp/actions/websocket_actions.jsx | 7 | ||||
-rw-r--r-- | webapp/client/websocket_client.jsx | 13 |
2 files changed, 20 insertions, 0 deletions
diff --git a/webapp/actions/websocket_actions.jsx b/webapp/actions/websocket_actions.jsx index e36d11fde..e07e3e217 100644 --- a/webapp/actions/websocket_actions.jsx +++ b/webapp/actions/websocket_actions.jsx @@ -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); } diff --git a/webapp/client/websocket_client.jsx b/webapp/client/websocket_client.jsx index 35be5c3df..1cf97b788 100644 --- a/webapp/client/websocket_client.jsx +++ b/webapp/client/websocket_client.jsx @@ -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; } @@ -37,6 +39,8 @@ export default class WebSocketClient { this.connectionUrl = connectionUrl; this.conn.onopen = () => { + this.eventSequence = 0; + if (token) { this.sendMessage('authentication_challenge', {token}); } @@ -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); } }; @@ -125,6 +134,10 @@ export default class WebSocketClient { this.reconnectCallback = callback; } + setMissedEventCallback(callback) { + this.missedEventCallback = callback; + } + setErrorCallback(callback) { this.errorCallback = callback; } |