Skip to content

Commit 9eaf648

Browse files
authored
[HOTFIX] Check client readyState before sending pings (#605)
React Native WebSocket library throw an error when a message is sent through the socket while its state is still "CONNECTING". Fix this issue by preventing send pings until its "OPEN"
1 parent eec36a6 commit 9eaf648

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kuzzle-sdk",
3-
"version": "7.5.4",
3+
"version": "7.5.5",
44
"description": "Official Javascript SDK for Kuzzle",
55
"author": "The Kuzzle Team <[email protected]>",
66
"repository": {

src/protocols/WebSocket.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,15 @@ export default class WebSocketProtocol extends BaseProtocolRealtime {
102102
clearTimeout(this.pongTimeoutId);
103103
});
104104
}
105-
106105
this.client.onopen = () => {
107106
this.clientConnected();
108107
/**
109-
* Send pings to the server
108+
* Send pings to the server
110109
*/
111110
this.pingIntervalId = setInterval(() => {
112-
this.ping();
111+
if (this.client.readyState === 1) {
112+
this.ping();
113+
}
113114
this.pongTimeoutId = setTimeout(() => {
114115
const error: any = new Error('Connection lost.');
115116
error.status = 503;

src/protocols/abstract/Realtime.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export abstract class BaseProtocolRealtime extends KuzzleAbstractProtocol {
5252
this.state = 'connected';
5353
this.wasConnected = true;
5454
this.stopRetryingToConnect = false;
55+
5556
}
5657

5758
/**

0 commit comments

Comments
 (0)