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
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
d39947f539
Коммит
95da05a8c9
@@ -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;
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user