stayge-ws-client-sdk 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/deploy.patch.sh +3 -0
- package/dist/react/index.js +13 -8
- package/dist/react/index.mjs +13 -8
- package/dist/react-native/index.js +13 -8
- package/dist/react-native/index.mjs +13 -8
- package/package.json +1 -1
- package/src/core/WebSocketClientImpl.ts +15 -10
package/deploy.patch.sh
ADDED
package/dist/react/index.js
CHANGED
|
@@ -40,6 +40,7 @@ var WebSocketClientImpl = class {
|
|
|
40
40
|
connect() {
|
|
41
41
|
this.ws = new WebSocket(this.url);
|
|
42
42
|
this.ws.onopen = () => {
|
|
43
|
+
console.log("WebSocketClient:onopen");
|
|
43
44
|
this.isConnected = true;
|
|
44
45
|
this.reconnectAttempts = 0;
|
|
45
46
|
if (this.onConnectCallback) {
|
|
@@ -47,8 +48,8 @@ var WebSocketClientImpl = class {
|
|
|
47
48
|
}
|
|
48
49
|
};
|
|
49
50
|
this.ws.onerror = (error) => {
|
|
50
|
-
console.error("
|
|
51
|
-
this.
|
|
51
|
+
console.error("WebSocketClient:onerror", error);
|
|
52
|
+
this.disconnect();
|
|
52
53
|
};
|
|
53
54
|
this.ws.onmessage = (event) => {
|
|
54
55
|
if (this.onMessageCallback) {
|
|
@@ -56,24 +57,26 @@ var WebSocketClientImpl = class {
|
|
|
56
57
|
const message = JSON.parse(event.data);
|
|
57
58
|
this.onMessageCallback(message);
|
|
58
59
|
} catch (error) {
|
|
59
|
-
console.error("
|
|
60
|
+
console.error("WebSocketClient:onmessage", error);
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
};
|
|
63
64
|
this.ws.onclose = () => {
|
|
64
|
-
console.error("
|
|
65
|
+
console.error("WebSocketClient:onclose");
|
|
66
|
+
if (this.onDisconnectCallback) {
|
|
67
|
+
this.onDisconnectCallback();
|
|
68
|
+
}
|
|
65
69
|
this.reconnect();
|
|
66
70
|
};
|
|
67
71
|
}
|
|
68
72
|
disconnect() {
|
|
73
|
+
console.log("WebSocketClient:disconnect");
|
|
69
74
|
this.ws?.close();
|
|
70
75
|
this.ws = null;
|
|
71
76
|
this.isConnected = false;
|
|
72
|
-
if (this.onDisconnectCallback) {
|
|
73
|
-
this.onDisconnectCallback();
|
|
74
|
-
}
|
|
75
77
|
}
|
|
76
78
|
subscribe(topic) {
|
|
79
|
+
console.log("WebSocketClient:subscribe");
|
|
77
80
|
const message = {
|
|
78
81
|
clientId: this.clientId,
|
|
79
82
|
type: "subscribe",
|
|
@@ -82,11 +85,13 @@ var WebSocketClientImpl = class {
|
|
|
82
85
|
this.ws?.send(JSON.stringify(message));
|
|
83
86
|
}
|
|
84
87
|
unsubscribe(topic) {
|
|
88
|
+
console.log("WebSocketClient:unsubscribe");
|
|
85
89
|
const message = {
|
|
86
90
|
clientId: this.clientId,
|
|
87
91
|
type: "unsubscribe",
|
|
88
92
|
topic
|
|
89
93
|
};
|
|
94
|
+
this.ws?.send(JSON.stringify(message));
|
|
90
95
|
}
|
|
91
96
|
onConnect(callback) {
|
|
92
97
|
this.onConnectCallback = callback;
|
|
@@ -98,11 +103,11 @@ var WebSocketClientImpl = class {
|
|
|
98
103
|
this.onMessageCallback = callback;
|
|
99
104
|
}
|
|
100
105
|
reconnect() {
|
|
106
|
+
console.log("WebSocketClient:reconnect");
|
|
101
107
|
if (this.isConnected && this.onDisconnectCallback) {
|
|
102
108
|
this.onDisconnectCallback();
|
|
103
109
|
}
|
|
104
110
|
this.isConnected = false;
|
|
105
|
-
console.log("Reconnecting...");
|
|
106
111
|
const delay = Math.min(1e3 * Math.pow(2, this.reconnectAttempts), 1e4);
|
|
107
112
|
this.reconnectAttempts++;
|
|
108
113
|
setTimeout(() => {
|
package/dist/react/index.mjs
CHANGED
|
@@ -14,6 +14,7 @@ var WebSocketClientImpl = class {
|
|
|
14
14
|
connect() {
|
|
15
15
|
this.ws = new WebSocket(this.url);
|
|
16
16
|
this.ws.onopen = () => {
|
|
17
|
+
console.log("WebSocketClient:onopen");
|
|
17
18
|
this.isConnected = true;
|
|
18
19
|
this.reconnectAttempts = 0;
|
|
19
20
|
if (this.onConnectCallback) {
|
|
@@ -21,8 +22,8 @@ var WebSocketClientImpl = class {
|
|
|
21
22
|
}
|
|
22
23
|
};
|
|
23
24
|
this.ws.onerror = (error) => {
|
|
24
|
-
console.error("
|
|
25
|
-
this.
|
|
25
|
+
console.error("WebSocketClient:onerror", error);
|
|
26
|
+
this.disconnect();
|
|
26
27
|
};
|
|
27
28
|
this.ws.onmessage = (event) => {
|
|
28
29
|
if (this.onMessageCallback) {
|
|
@@ -30,24 +31,26 @@ var WebSocketClientImpl = class {
|
|
|
30
31
|
const message = JSON.parse(event.data);
|
|
31
32
|
this.onMessageCallback(message);
|
|
32
33
|
} catch (error) {
|
|
33
|
-
console.error("
|
|
34
|
+
console.error("WebSocketClient:onmessage", error);
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
};
|
|
37
38
|
this.ws.onclose = () => {
|
|
38
|
-
console.error("
|
|
39
|
+
console.error("WebSocketClient:onclose");
|
|
40
|
+
if (this.onDisconnectCallback) {
|
|
41
|
+
this.onDisconnectCallback();
|
|
42
|
+
}
|
|
39
43
|
this.reconnect();
|
|
40
44
|
};
|
|
41
45
|
}
|
|
42
46
|
disconnect() {
|
|
47
|
+
console.log("WebSocketClient:disconnect");
|
|
43
48
|
this.ws?.close();
|
|
44
49
|
this.ws = null;
|
|
45
50
|
this.isConnected = false;
|
|
46
|
-
if (this.onDisconnectCallback) {
|
|
47
|
-
this.onDisconnectCallback();
|
|
48
|
-
}
|
|
49
51
|
}
|
|
50
52
|
subscribe(topic) {
|
|
53
|
+
console.log("WebSocketClient:subscribe");
|
|
51
54
|
const message = {
|
|
52
55
|
clientId: this.clientId,
|
|
53
56
|
type: "subscribe",
|
|
@@ -56,11 +59,13 @@ var WebSocketClientImpl = class {
|
|
|
56
59
|
this.ws?.send(JSON.stringify(message));
|
|
57
60
|
}
|
|
58
61
|
unsubscribe(topic) {
|
|
62
|
+
console.log("WebSocketClient:unsubscribe");
|
|
59
63
|
const message = {
|
|
60
64
|
clientId: this.clientId,
|
|
61
65
|
type: "unsubscribe",
|
|
62
66
|
topic
|
|
63
67
|
};
|
|
68
|
+
this.ws?.send(JSON.stringify(message));
|
|
64
69
|
}
|
|
65
70
|
onConnect(callback) {
|
|
66
71
|
this.onConnectCallback = callback;
|
|
@@ -72,11 +77,11 @@ var WebSocketClientImpl = class {
|
|
|
72
77
|
this.onMessageCallback = callback;
|
|
73
78
|
}
|
|
74
79
|
reconnect() {
|
|
80
|
+
console.log("WebSocketClient:reconnect");
|
|
75
81
|
if (this.isConnected && this.onDisconnectCallback) {
|
|
76
82
|
this.onDisconnectCallback();
|
|
77
83
|
}
|
|
78
84
|
this.isConnected = false;
|
|
79
|
-
console.log("Reconnecting...");
|
|
80
85
|
const delay = Math.min(1e3 * Math.pow(2, this.reconnectAttempts), 1e4);
|
|
81
86
|
this.reconnectAttempts++;
|
|
82
87
|
setTimeout(() => {
|
|
@@ -40,6 +40,7 @@ var WebSocketClientImpl = class {
|
|
|
40
40
|
connect() {
|
|
41
41
|
this.ws = new WebSocket(this.url);
|
|
42
42
|
this.ws.onopen = () => {
|
|
43
|
+
console.log("WebSocketClient:onopen");
|
|
43
44
|
this.isConnected = true;
|
|
44
45
|
this.reconnectAttempts = 0;
|
|
45
46
|
if (this.onConnectCallback) {
|
|
@@ -47,8 +48,8 @@ var WebSocketClientImpl = class {
|
|
|
47
48
|
}
|
|
48
49
|
};
|
|
49
50
|
this.ws.onerror = (error) => {
|
|
50
|
-
console.error("
|
|
51
|
-
this.
|
|
51
|
+
console.error("WebSocketClient:onerror", error);
|
|
52
|
+
this.disconnect();
|
|
52
53
|
};
|
|
53
54
|
this.ws.onmessage = (event) => {
|
|
54
55
|
if (this.onMessageCallback) {
|
|
@@ -56,24 +57,26 @@ var WebSocketClientImpl = class {
|
|
|
56
57
|
const message = JSON.parse(event.data);
|
|
57
58
|
this.onMessageCallback(message);
|
|
58
59
|
} catch (error) {
|
|
59
|
-
console.error("
|
|
60
|
+
console.error("WebSocketClient:onmessage", error);
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
};
|
|
63
64
|
this.ws.onclose = () => {
|
|
64
|
-
console.error("
|
|
65
|
+
console.error("WebSocketClient:onclose");
|
|
66
|
+
if (this.onDisconnectCallback) {
|
|
67
|
+
this.onDisconnectCallback();
|
|
68
|
+
}
|
|
65
69
|
this.reconnect();
|
|
66
70
|
};
|
|
67
71
|
}
|
|
68
72
|
disconnect() {
|
|
73
|
+
console.log("WebSocketClient:disconnect");
|
|
69
74
|
this.ws?.close();
|
|
70
75
|
this.ws = null;
|
|
71
76
|
this.isConnected = false;
|
|
72
|
-
if (this.onDisconnectCallback) {
|
|
73
|
-
this.onDisconnectCallback();
|
|
74
|
-
}
|
|
75
77
|
}
|
|
76
78
|
subscribe(topic) {
|
|
79
|
+
console.log("WebSocketClient:subscribe");
|
|
77
80
|
const message = {
|
|
78
81
|
clientId: this.clientId,
|
|
79
82
|
type: "subscribe",
|
|
@@ -82,11 +85,13 @@ var WebSocketClientImpl = class {
|
|
|
82
85
|
this.ws?.send(JSON.stringify(message));
|
|
83
86
|
}
|
|
84
87
|
unsubscribe(topic) {
|
|
88
|
+
console.log("WebSocketClient:unsubscribe");
|
|
85
89
|
const message = {
|
|
86
90
|
clientId: this.clientId,
|
|
87
91
|
type: "unsubscribe",
|
|
88
92
|
topic
|
|
89
93
|
};
|
|
94
|
+
this.ws?.send(JSON.stringify(message));
|
|
90
95
|
}
|
|
91
96
|
onConnect(callback) {
|
|
92
97
|
this.onConnectCallback = callback;
|
|
@@ -98,11 +103,11 @@ var WebSocketClientImpl = class {
|
|
|
98
103
|
this.onMessageCallback = callback;
|
|
99
104
|
}
|
|
100
105
|
reconnect() {
|
|
106
|
+
console.log("WebSocketClient:reconnect");
|
|
101
107
|
if (this.isConnected && this.onDisconnectCallback) {
|
|
102
108
|
this.onDisconnectCallback();
|
|
103
109
|
}
|
|
104
110
|
this.isConnected = false;
|
|
105
|
-
console.log("Reconnecting...");
|
|
106
111
|
const delay = Math.min(1e3 * Math.pow(2, this.reconnectAttempts), 1e4);
|
|
107
112
|
this.reconnectAttempts++;
|
|
108
113
|
setTimeout(() => {
|
|
@@ -14,6 +14,7 @@ var WebSocketClientImpl = class {
|
|
|
14
14
|
connect() {
|
|
15
15
|
this.ws = new WebSocket(this.url);
|
|
16
16
|
this.ws.onopen = () => {
|
|
17
|
+
console.log("WebSocketClient:onopen");
|
|
17
18
|
this.isConnected = true;
|
|
18
19
|
this.reconnectAttempts = 0;
|
|
19
20
|
if (this.onConnectCallback) {
|
|
@@ -21,8 +22,8 @@ var WebSocketClientImpl = class {
|
|
|
21
22
|
}
|
|
22
23
|
};
|
|
23
24
|
this.ws.onerror = (error) => {
|
|
24
|
-
console.error("
|
|
25
|
-
this.
|
|
25
|
+
console.error("WebSocketClient:onerror", error);
|
|
26
|
+
this.disconnect();
|
|
26
27
|
};
|
|
27
28
|
this.ws.onmessage = (event) => {
|
|
28
29
|
if (this.onMessageCallback) {
|
|
@@ -30,24 +31,26 @@ var WebSocketClientImpl = class {
|
|
|
30
31
|
const message = JSON.parse(event.data);
|
|
31
32
|
this.onMessageCallback(message);
|
|
32
33
|
} catch (error) {
|
|
33
|
-
console.error("
|
|
34
|
+
console.error("WebSocketClient:onmessage", error);
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
};
|
|
37
38
|
this.ws.onclose = () => {
|
|
38
|
-
console.error("
|
|
39
|
+
console.error("WebSocketClient:onclose");
|
|
40
|
+
if (this.onDisconnectCallback) {
|
|
41
|
+
this.onDisconnectCallback();
|
|
42
|
+
}
|
|
39
43
|
this.reconnect();
|
|
40
44
|
};
|
|
41
45
|
}
|
|
42
46
|
disconnect() {
|
|
47
|
+
console.log("WebSocketClient:disconnect");
|
|
43
48
|
this.ws?.close();
|
|
44
49
|
this.ws = null;
|
|
45
50
|
this.isConnected = false;
|
|
46
|
-
if (this.onDisconnectCallback) {
|
|
47
|
-
this.onDisconnectCallback();
|
|
48
|
-
}
|
|
49
51
|
}
|
|
50
52
|
subscribe(topic) {
|
|
53
|
+
console.log("WebSocketClient:subscribe");
|
|
51
54
|
const message = {
|
|
52
55
|
clientId: this.clientId,
|
|
53
56
|
type: "subscribe",
|
|
@@ -56,11 +59,13 @@ var WebSocketClientImpl = class {
|
|
|
56
59
|
this.ws?.send(JSON.stringify(message));
|
|
57
60
|
}
|
|
58
61
|
unsubscribe(topic) {
|
|
62
|
+
console.log("WebSocketClient:unsubscribe");
|
|
59
63
|
const message = {
|
|
60
64
|
clientId: this.clientId,
|
|
61
65
|
type: "unsubscribe",
|
|
62
66
|
topic
|
|
63
67
|
};
|
|
68
|
+
this.ws?.send(JSON.stringify(message));
|
|
64
69
|
}
|
|
65
70
|
onConnect(callback) {
|
|
66
71
|
this.onConnectCallback = callback;
|
|
@@ -72,11 +77,11 @@ var WebSocketClientImpl = class {
|
|
|
72
77
|
this.onMessageCallback = callback;
|
|
73
78
|
}
|
|
74
79
|
reconnect() {
|
|
80
|
+
console.log("WebSocketClient:reconnect");
|
|
75
81
|
if (this.isConnected && this.onDisconnectCallback) {
|
|
76
82
|
this.onDisconnectCallback();
|
|
77
83
|
}
|
|
78
84
|
this.isConnected = false;
|
|
79
|
-
console.log("Reconnecting...");
|
|
80
85
|
const delay = Math.min(1e3 * Math.pow(2, this.reconnectAttempts), 1e4);
|
|
81
86
|
this.reconnectAttempts++;
|
|
82
87
|
setTimeout(() => {
|
package/package.json
CHANGED
|
@@ -23,16 +23,18 @@ export class WebSocketClientImpl implements WebSocketClient {
|
|
|
23
23
|
this.ws = new WebSocket(this.url);
|
|
24
24
|
|
|
25
25
|
this.ws.onopen = () => {
|
|
26
|
+
console.log("WebSocketClient:onopen");
|
|
26
27
|
this.isConnected = true;
|
|
27
28
|
this.reconnectAttempts = 0;
|
|
29
|
+
|
|
28
30
|
if (this.onConnectCallback) {
|
|
29
31
|
this.onConnectCallback();
|
|
30
32
|
}
|
|
31
33
|
};
|
|
32
34
|
|
|
33
35
|
this.ws.onerror = (error) => {
|
|
34
|
-
console.error("
|
|
35
|
-
this.
|
|
36
|
+
console.error("WebSocketClient:onerror", error);
|
|
37
|
+
this.disconnect();
|
|
36
38
|
};
|
|
37
39
|
|
|
38
40
|
this.ws.onmessage = (event) => {
|
|
@@ -41,28 +43,30 @@ export class WebSocketClientImpl implements WebSocketClient {
|
|
|
41
43
|
const message = JSON.parse(event.data) as MessageFromServer;
|
|
42
44
|
this.onMessageCallback(message);
|
|
43
45
|
} catch (error) {
|
|
44
|
-
console.error("
|
|
46
|
+
console.error("WebSocketClient:onmessage", error);
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
};
|
|
48
50
|
|
|
49
51
|
this.ws.onclose = () => {
|
|
50
|
-
console.error("
|
|
52
|
+
console.error("WebSocketClient:onclose");
|
|
53
|
+
if (this.onDisconnectCallback) {
|
|
54
|
+
this.onDisconnectCallback();
|
|
55
|
+
}
|
|
56
|
+
|
|
51
57
|
this.reconnect();
|
|
52
58
|
};
|
|
53
59
|
}
|
|
54
60
|
|
|
55
61
|
disconnect() {
|
|
62
|
+
console.log("WebSocketClient:disconnect");
|
|
56
63
|
this.ws?.close();
|
|
57
64
|
this.ws = null;
|
|
58
65
|
this.isConnected = false;
|
|
59
|
-
|
|
60
|
-
if (this.onDisconnectCallback) {
|
|
61
|
-
this.onDisconnectCallback();
|
|
62
|
-
}
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
subscribe(topic: string) {
|
|
69
|
+
console.log("WebSocketClient:subscribe");
|
|
66
70
|
const message: MessageToServer = {
|
|
67
71
|
clientId: this.clientId,
|
|
68
72
|
type: "subscribe",
|
|
@@ -72,11 +76,13 @@ export class WebSocketClientImpl implements WebSocketClient {
|
|
|
72
76
|
}
|
|
73
77
|
|
|
74
78
|
unsubscribe(topic: string) {
|
|
79
|
+
console.log("WebSocketClient:unsubscribe");
|
|
75
80
|
const message: MessageToServer = {
|
|
76
81
|
clientId: this.clientId,
|
|
77
82
|
type: "unsubscribe",
|
|
78
83
|
topic,
|
|
79
84
|
};
|
|
85
|
+
this.ws?.send(JSON.stringify(message));
|
|
80
86
|
}
|
|
81
87
|
|
|
82
88
|
onConnect(callback: () => void) {
|
|
@@ -92,14 +98,13 @@ export class WebSocketClientImpl implements WebSocketClient {
|
|
|
92
98
|
}
|
|
93
99
|
|
|
94
100
|
private reconnect() {
|
|
101
|
+
console.log("WebSocketClient:reconnect");
|
|
95
102
|
if (this.isConnected && this.onDisconnectCallback) {
|
|
96
103
|
this.onDisconnectCallback();
|
|
97
104
|
}
|
|
98
105
|
|
|
99
106
|
this.isConnected = false;
|
|
100
107
|
|
|
101
|
-
console.log("Reconnecting...");
|
|
102
|
-
|
|
103
108
|
// exponential backoff
|
|
104
109
|
const delay = Math.min(1000 * Math.pow(2, this.reconnectAttempts), 10000);
|
|
105
110
|
this.reconnectAttempts++;
|