@lowdefy/client-core 7.2.0 → 7.3.0
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.
|
@@ -89,6 +89,15 @@ function createWebSocketClient(lowdefy) {
|
|
|
89
89
|
function isIdle() {
|
|
90
90
|
return subscriptions.size === 0 && pendingPublishes.size === 0;
|
|
91
91
|
}
|
|
92
|
+
// The close event arrives after the closing handshake, when a new socket may
|
|
93
|
+
// already be connecting or open. A socket the client closes is finished
|
|
94
|
+
// with, so its events must not reach the client state that now belongs to
|
|
95
|
+
// the new socket.
|
|
96
|
+
function closeFinishedSocket() {
|
|
97
|
+
socket.onclose = null;
|
|
98
|
+
socket.onmessage = null;
|
|
99
|
+
socket.close();
|
|
100
|
+
}
|
|
92
101
|
function scheduleIdleClose() {
|
|
93
102
|
clearIdleTimer();
|
|
94
103
|
if (!isIdle()) {
|
|
@@ -97,15 +106,9 @@ function createWebSocketClient(lowdefy) {
|
|
|
97
106
|
// Grace period so rapid page navigation doesn't thrash connections.
|
|
98
107
|
idleTimer = setTimeout(()=>{
|
|
99
108
|
if (isIdle() && socket) {
|
|
100
|
-
// The close event arrives after the closing handshake, when a new
|
|
101
|
-
// socket may already be connecting or open. This socket is finished
|
|
102
|
-
// with, so its events must not reach the client state that now
|
|
103
|
-
// belongs to the new socket.
|
|
104
|
-
socket.onclose = null;
|
|
105
|
-
socket.onmessage = null;
|
|
106
109
|
clearTimeout(stableTimer);
|
|
107
110
|
reconnectingAfterCallerChange = false;
|
|
108
|
-
|
|
111
|
+
closeFinishedSocket();
|
|
109
112
|
socket = null;
|
|
110
113
|
openPromise = null;
|
|
111
114
|
}
|
|
@@ -134,26 +137,44 @@ function createWebSocketClient(lowdefy) {
|
|
|
134
137
|
clearTimeout(subscription.ackTimer);
|
|
135
138
|
subscription.ackTimer = null;
|
|
136
139
|
}
|
|
140
|
+
// A subscribe that gets no ack on an open socket means the socket is dead:
|
|
141
|
+
// the platform ended the connection and the browser has not seen the close
|
|
142
|
+
// yet. Waiting for that close would leave every feed silent for as long as
|
|
143
|
+
// it takes, so the socket is dropped now and handleClose reconnects with
|
|
144
|
+
// backoff, which resubscribes every feed.
|
|
145
|
+
function dropUnresponsiveSocket() {
|
|
146
|
+
closeFinishedSocket();
|
|
147
|
+
handleClose({
|
|
148
|
+
code: null
|
|
149
|
+
});
|
|
150
|
+
}
|
|
137
151
|
function handleAckTimeout(subscription) {
|
|
138
152
|
subscription.ackTimer = null;
|
|
139
153
|
const error = new ServiceError(`Subscribe to "${subscription.websocketId}" timed out.`, {
|
|
140
154
|
service: 'WebSocket'
|
|
141
155
|
});
|
|
142
|
-
if (subscription.pending) {
|
|
156
|
+
if (!subscription.pending) {
|
|
157
|
+
subscription.handlers.onError(error.message);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const { reject } = subscription.pending;
|
|
161
|
+
// A subscribe whose frame was never sent had no connection open within
|
|
162
|
+
// the timeout, so the feed is dropped.
|
|
163
|
+
if (type.isNone(subscription.requestId)) {
|
|
143
164
|
subscriptions.delete(subscription.websocketId);
|
|
144
|
-
// The server handles the frame late, or not yet, and would open the feed
|
|
145
|
-
// for a caller that has given up on it.
|
|
146
|
-
if (isSocketOpen()) {
|
|
147
|
-
socket.send(JSON.stringify({
|
|
148
|
-
type: 'unsubscribe',
|
|
149
|
-
websocketId: subscription.websocketId
|
|
150
|
-
}));
|
|
151
|
-
}
|
|
152
165
|
scheduleIdleClose();
|
|
153
|
-
|
|
166
|
+
reject(error);
|
|
154
167
|
return;
|
|
155
168
|
}
|
|
156
|
-
|
|
169
|
+
// The frame was sent on a connection that has died or is dying. The feed
|
|
170
|
+
// is kept, so the reconnect sends it again and its ack calls onConnected;
|
|
171
|
+
// the caller still hears that this subscribe timed out.
|
|
172
|
+
subscription.pending = null;
|
|
173
|
+
error.subscriptionKept = true;
|
|
174
|
+
if (isSocketOpen()) {
|
|
175
|
+
dropUnresponsiveSocket();
|
|
176
|
+
}
|
|
177
|
+
reject(error);
|
|
157
178
|
}
|
|
158
179
|
// Every path that removes a subscription from the map or answers its
|
|
159
180
|
// subscribe clears this timer, so a timer that fires always belongs to the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/client-core",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Lowdefy Client Core - the platform-free half of the Lowdefy client, shared by its renderers",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"dist/*"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@lowdefy/engine": "7.
|
|
37
|
-
"@lowdefy/errors": "7.
|
|
38
|
-
"@lowdefy/helpers": "7.
|
|
39
|
-
"@lowdefy/logger": "7.
|
|
36
|
+
"@lowdefy/engine": "7.3.0",
|
|
37
|
+
"@lowdefy/errors": "7.3.0",
|
|
38
|
+
"@lowdefy/helpers": "7.3.0",
|
|
39
|
+
"@lowdefy/logger": "7.3.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@swc/cli": "0.8.1",
|