@liveblocks/client 0.15.1 → 0.15.5

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/lib/esm/index.js CHANGED
@@ -34,6 +34,17 @@ var OpType = /* @__PURE__ */ ((OpType2) => {
34
34
  OpType2[OpType2["CreateRegister"] = 8] = "CreateRegister";
35
35
  return OpType2;
36
36
  })(OpType || {});
37
+ var WebsocketCloseCodes = /* @__PURE__ */ ((WebsocketCloseCodes2) => {
38
+ WebsocketCloseCodes2[WebsocketCloseCodes2["CLOSE_ABNORMAL"] = 1006] = "CLOSE_ABNORMAL";
39
+ WebsocketCloseCodes2[WebsocketCloseCodes2["INVALID_MESSAGE_FORMAT"] = 4e3] = "INVALID_MESSAGE_FORMAT";
40
+ WebsocketCloseCodes2[WebsocketCloseCodes2["NOT_ALLOWED"] = 4001] = "NOT_ALLOWED";
41
+ WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_MESSAGES_PER_SECONDS"] = 4002] = "MAX_NUMBER_OF_MESSAGES_PER_SECONDS";
42
+ WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_CONCURRENT_CONNECTIONS"] = 4003] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS";
43
+ WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP"] = 4004] = "MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP";
44
+ WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM"] = 4005] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM";
45
+ WebsocketCloseCodes2[WebsocketCloseCodes2["CLOSE_WITHOUT_RETRY"] = 4999] = "CLOSE_WITHOUT_RETRY";
46
+ return WebsocketCloseCodes2;
47
+ })(WebsocketCloseCodes || {});
37
48
 
38
49
  var __accessCheck$4 = (obj, member, msg) => {
39
50
  if (!member.has(obj))
@@ -1585,6 +1596,7 @@ var __spreadValues$1 = (a, b) => {
1585
1596
  };
1586
1597
  var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
1587
1598
  const BACKOFF_RETRY_DELAYS = [250, 500, 1e3, 2e3, 4e3, 8e3, 1e4];
1599
+ const BACKOFF_RETRY_DELAYS_SLOW = [2e3, 3e4, 6e4, 3e5];
1588
1600
  const HEARTBEAT_INTERVAL = 3e4;
1589
1601
  const PONG_TIMEOUT = 2e3;
1590
1602
  function isValidRoomEventType(value) {
@@ -1615,6 +1627,9 @@ function makeStateMachine(state, context, mockedEffects) {
1615
1627
  const effects = mockedEffects || {
1616
1628
  authenticate(auth, createWebSocket) {
1617
1629
  return auth(context.room).then(({ token }) => {
1630
+ if (state.connection.state !== "authenticating") {
1631
+ return;
1632
+ }
1618
1633
  const parsedToken = parseToken(token);
1619
1634
  const socket = createWebSocket(token);
1620
1635
  authenticationSuccess(parsedToken, socket);
@@ -2127,21 +2142,25 @@ See v0.13 release notes for more information.
2127
2142
  updateConnection({ state: "failed" });
2128
2143
  const error = new LiveblocksError(event.reason, event.code);
2129
2144
  for (const listener of state.listeners.error) {
2130
- if (process.env.NODE_ENV !== "production") {
2131
- console.error(`Connection to Liveblocks websocket server closed. Reason: ${error.message} (code: ${error.code})`);
2132
- }
2133
2145
  listener(error);
2134
2146
  }
2135
- } else if (event.wasClean === false) {
2147
+ const delay = getRetryDelay(true);
2136
2148
  state.numberOfRetry++;
2149
+ if (process.env.NODE_ENV !== "production") {
2150
+ console.error(`Connection to Liveblocks websocket server closed. Reason: ${error.message} (code: ${error.code}). Retrying in ${delay}ms.`);
2151
+ }
2152
+ updateConnection({ state: "unavailable" });
2153
+ state.timeoutHandles.reconnect = effects.scheduleReconnect(delay);
2154
+ } else if (event.code === WebsocketCloseCodes.CLOSE_WITHOUT_RETRY) {
2155
+ updateConnection({ state: "closed" });
2156
+ } else {
2137
2157
  const delay = getRetryDelay();
2158
+ state.numberOfRetry++;
2138
2159
  if (process.env.NODE_ENV !== "production") {
2139
2160
  console.warn(`Connection to Liveblocks websocket server closed (code: ${event.code}). Retrying in ${delay}ms.`);
2140
2161
  }
2141
2162
  updateConnection({ state: "unavailable" });
2142
2163
  state.timeoutHandles.reconnect = effects.scheduleReconnect(delay);
2143
- } else {
2144
- updateConnection({ state: "closed" });
2145
2164
  }
2146
2165
  }
2147
2166
  function updateConnection(connection) {
@@ -2150,7 +2169,10 @@ See v0.13 release notes for more information.
2150
2169
  listener(connection.state);
2151
2170
  }
2152
2171
  }
2153
- function getRetryDelay() {
2172
+ function getRetryDelay(slow = false) {
2173
+ if (slow) {
2174
+ return BACKOFF_RETRY_DELAYS_SLOW[state.numberOfRetry < BACKOFF_RETRY_DELAYS_SLOW.length ? state.numberOfRetry : BACKOFF_RETRY_DELAYS_SLOW.length - 1];
2175
+ }
2154
2176
  return BACKOFF_RETRY_DELAYS[state.numberOfRetry < BACKOFF_RETRY_DELAYS.length ? state.numberOfRetry : BACKOFF_RETRY_DELAYS.length - 1];
2155
2177
  }
2156
2178
  function onError() {
package/lib/esm/index.mjs CHANGED
@@ -34,6 +34,17 @@ var OpType = /* @__PURE__ */ ((OpType2) => {
34
34
  OpType2[OpType2["CreateRegister"] = 8] = "CreateRegister";
35
35
  return OpType2;
36
36
  })(OpType || {});
37
+ var WebsocketCloseCodes = /* @__PURE__ */ ((WebsocketCloseCodes2) => {
38
+ WebsocketCloseCodes2[WebsocketCloseCodes2["CLOSE_ABNORMAL"] = 1006] = "CLOSE_ABNORMAL";
39
+ WebsocketCloseCodes2[WebsocketCloseCodes2["INVALID_MESSAGE_FORMAT"] = 4e3] = "INVALID_MESSAGE_FORMAT";
40
+ WebsocketCloseCodes2[WebsocketCloseCodes2["NOT_ALLOWED"] = 4001] = "NOT_ALLOWED";
41
+ WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_MESSAGES_PER_SECONDS"] = 4002] = "MAX_NUMBER_OF_MESSAGES_PER_SECONDS";
42
+ WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_CONCURRENT_CONNECTIONS"] = 4003] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS";
43
+ WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP"] = 4004] = "MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP";
44
+ WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM"] = 4005] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM";
45
+ WebsocketCloseCodes2[WebsocketCloseCodes2["CLOSE_WITHOUT_RETRY"] = 4999] = "CLOSE_WITHOUT_RETRY";
46
+ return WebsocketCloseCodes2;
47
+ })(WebsocketCloseCodes || {});
37
48
 
38
49
  var __accessCheck$4 = (obj, member, msg) => {
39
50
  if (!member.has(obj))
@@ -1585,6 +1596,7 @@ var __spreadValues$1 = (a, b) => {
1585
1596
  };
1586
1597
  var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
1587
1598
  const BACKOFF_RETRY_DELAYS = [250, 500, 1e3, 2e3, 4e3, 8e3, 1e4];
1599
+ const BACKOFF_RETRY_DELAYS_SLOW = [2e3, 3e4, 6e4, 3e5];
1588
1600
  const HEARTBEAT_INTERVAL = 3e4;
1589
1601
  const PONG_TIMEOUT = 2e3;
1590
1602
  function isValidRoomEventType(value) {
@@ -1615,6 +1627,9 @@ function makeStateMachine(state, context, mockedEffects) {
1615
1627
  const effects = mockedEffects || {
1616
1628
  authenticate(auth, createWebSocket) {
1617
1629
  return auth(context.room).then(({ token }) => {
1630
+ if (state.connection.state !== "authenticating") {
1631
+ return;
1632
+ }
1618
1633
  const parsedToken = parseToken(token);
1619
1634
  const socket = createWebSocket(token);
1620
1635
  authenticationSuccess(parsedToken, socket);
@@ -2127,21 +2142,25 @@ See v0.13 release notes for more information.
2127
2142
  updateConnection({ state: "failed" });
2128
2143
  const error = new LiveblocksError(event.reason, event.code);
2129
2144
  for (const listener of state.listeners.error) {
2130
- if (process.env.NODE_ENV !== "production") {
2131
- console.error(`Connection to Liveblocks websocket server closed. Reason: ${error.message} (code: ${error.code})`);
2132
- }
2133
2145
  listener(error);
2134
2146
  }
2135
- } else if (event.wasClean === false) {
2147
+ const delay = getRetryDelay(true);
2136
2148
  state.numberOfRetry++;
2149
+ if (process.env.NODE_ENV !== "production") {
2150
+ console.error(`Connection to Liveblocks websocket server closed. Reason: ${error.message} (code: ${error.code}). Retrying in ${delay}ms.`);
2151
+ }
2152
+ updateConnection({ state: "unavailable" });
2153
+ state.timeoutHandles.reconnect = effects.scheduleReconnect(delay);
2154
+ } else if (event.code === WebsocketCloseCodes.CLOSE_WITHOUT_RETRY) {
2155
+ updateConnection({ state: "closed" });
2156
+ } else {
2137
2157
  const delay = getRetryDelay();
2158
+ state.numberOfRetry++;
2138
2159
  if (process.env.NODE_ENV !== "production") {
2139
2160
  console.warn(`Connection to Liveblocks websocket server closed (code: ${event.code}). Retrying in ${delay}ms.`);
2140
2161
  }
2141
2162
  updateConnection({ state: "unavailable" });
2142
2163
  state.timeoutHandles.reconnect = effects.scheduleReconnect(delay);
2143
- } else {
2144
- updateConnection({ state: "closed" });
2145
2164
  }
2146
2165
  }
2147
2166
  function updateConnection(connection) {
@@ -2150,7 +2169,10 @@ See v0.13 release notes for more information.
2150
2169
  listener(connection.state);
2151
2170
  }
2152
2171
  }
2153
- function getRetryDelay() {
2172
+ function getRetryDelay(slow = false) {
2173
+ if (slow) {
2174
+ return BACKOFF_RETRY_DELAYS_SLOW[state.numberOfRetry < BACKOFF_RETRY_DELAYS_SLOW.length ? state.numberOfRetry : BACKOFF_RETRY_DELAYS_SLOW.length - 1];
2175
+ }
2154
2176
  return BACKOFF_RETRY_DELAYS[state.numberOfRetry < BACKOFF_RETRY_DELAYS.length ? state.numberOfRetry : BACKOFF_RETRY_DELAYS.length - 1];
2155
2177
  }
2156
2178
  function onError() {
@@ -42,6 +42,7 @@ var WebsocketCloseCodes = /* @__PURE__ */ ((WebsocketCloseCodes2) => {
42
42
  WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_CONCURRENT_CONNECTIONS"] = 4003] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS";
43
43
  WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP"] = 4004] = "MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP";
44
44
  WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM"] = 4005] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM";
45
+ WebsocketCloseCodes2[WebsocketCloseCodes2["CLOSE_WITHOUT_RETRY"] = 4999] = "CLOSE_WITHOUT_RETRY";
45
46
  return WebsocketCloseCodes2;
46
47
  })(WebsocketCloseCodes || {});
47
48
 
@@ -42,6 +42,7 @@ var WebsocketCloseCodes = /* @__PURE__ */ ((WebsocketCloseCodes2) => {
42
42
  WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_CONCURRENT_CONNECTIONS"] = 4003] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS";
43
43
  WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP"] = 4004] = "MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP";
44
44
  WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM"] = 4005] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM";
45
+ WebsocketCloseCodes2[WebsocketCloseCodes2["CLOSE_WITHOUT_RETRY"] = 4999] = "CLOSE_WITHOUT_RETRY";
45
46
  return WebsocketCloseCodes2;
46
47
  })(WebsocketCloseCodes || {});
47
48
 
package/lib/index.js CHANGED
@@ -273,6 +273,7 @@ var WebsocketCloseCodes;
273
273
  WebsocketCloseCodes[WebsocketCloseCodes["MAX_NUMBER_OF_CONCURRENT_CONNECTIONS"] = 4003] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS";
274
274
  WebsocketCloseCodes[WebsocketCloseCodes["MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP"] = 4004] = "MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP";
275
275
  WebsocketCloseCodes[WebsocketCloseCodes["MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM"] = 4005] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM";
276
+ WebsocketCloseCodes[WebsocketCloseCodes["CLOSE_WITHOUT_RETRY"] = 4999] = "CLOSE_WITHOUT_RETRY";
276
277
  })(WebsocketCloseCodes || (WebsocketCloseCodes = {}));
277
278
 
278
279
  var _parent = new WeakMap();
@@ -2398,6 +2399,7 @@ function _applyDeleteObjectKey2(op) {
2398
2399
  }
2399
2400
 
2400
2401
  var BACKOFF_RETRY_DELAYS = [250, 500, 1000, 2000, 4000, 8000, 10000];
2402
+ var BACKOFF_RETRY_DELAYS_SLOW = [2000, 30000, 60000, 300000];
2401
2403
  var HEARTBEAT_INTERVAL = 30000;
2402
2404
  var PONG_TIMEOUT = 2000;
2403
2405
 
@@ -2435,6 +2437,11 @@ function makeStateMachine(state, context, mockedEffects) {
2435
2437
  authenticate: function authenticate(auth, createWebSocket) {
2436
2438
  return auth(context.room).then(function (_ref2) {
2437
2439
  var token = _ref2.token;
2440
+
2441
+ if (state.connection.state !== "authenticating") {
2442
+ return;
2443
+ }
2444
+
2438
2445
  var parsedToken = parseToken(token);
2439
2446
  var socket = createWebSocket(token);
2440
2447
  authenticationSuccess(parsedToken, socket);
@@ -3161,29 +3168,38 @@ function makeStateMachine(state, context, mockedEffects) {
3161
3168
  for (var _iterator10 = _createForOfIteratorHelperLoose(state.listeners.error), _step10; !(_step10 = _iterator10()).done;) {
3162
3169
  var _listener4 = _step10.value;
3163
3170
 
3164
- if (process.env.NODE_ENV !== "production") {
3165
- console.error("Connection to Liveblocks websocket server closed. Reason: " + error.message + " (code: " + error.code + ")");
3166
- }
3167
-
3168
3171
  _listener4(error);
3169
3172
  }
3170
- } else if (event.wasClean === false) {
3171
- state.numberOfRetry++;
3172
3173
 
3173
- var _delay = getRetryDelay();
3174
+ var _delay = getRetryDelay(true);
3175
+
3176
+ state.numberOfRetry++;
3174
3177
 
3175
3178
  if (process.env.NODE_ENV !== "production") {
3176
- console.warn("Connection to Liveblocks websocket server closed (code: " + event.code + "). Retrying in " + _delay + "ms.");
3179
+ console.error("Connection to Liveblocks websocket server closed. Reason: " + error.message + " (code: " + error.code + "). Retrying in " + _delay + "ms.");
3177
3180
  }
3178
3181
 
3179
3182
  updateConnection({
3180
3183
  state: "unavailable"
3181
3184
  });
3182
3185
  state.timeoutHandles.reconnect = effects.scheduleReconnect(_delay);
3183
- } else {
3186
+ } else if (event.code === WebsocketCloseCodes.CLOSE_WITHOUT_RETRY) {
3184
3187
  updateConnection({
3185
3188
  state: "closed"
3186
3189
  });
3190
+ } else {
3191
+ var _delay2 = getRetryDelay();
3192
+
3193
+ state.numberOfRetry++;
3194
+
3195
+ if (process.env.NODE_ENV !== "production") {
3196
+ console.warn("Connection to Liveblocks websocket server closed (code: " + event.code + "). Retrying in " + _delay2 + "ms.");
3197
+ }
3198
+
3199
+ updateConnection({
3200
+ state: "unavailable"
3201
+ });
3202
+ state.timeoutHandles.reconnect = effects.scheduleReconnect(_delay2);
3187
3203
  }
3188
3204
  }
3189
3205
 
@@ -3197,7 +3213,15 @@ function makeStateMachine(state, context, mockedEffects) {
3197
3213
  }
3198
3214
  }
3199
3215
 
3200
- function getRetryDelay() {
3216
+ function getRetryDelay(slow) {
3217
+ if (slow === void 0) {
3218
+ slow = false;
3219
+ }
3220
+
3221
+ if (slow) {
3222
+ return BACKOFF_RETRY_DELAYS_SLOW[state.numberOfRetry < BACKOFF_RETRY_DELAYS_SLOW.length ? state.numberOfRetry : BACKOFF_RETRY_DELAYS_SLOW.length - 1];
3223
+ }
3224
+
3201
3225
  return BACKOFF_RETRY_DELAYS[state.numberOfRetry < BACKOFF_RETRY_DELAYS.length ? state.numberOfRetry : BACKOFF_RETRY_DELAYS.length - 1];
3202
3226
  }
3203
3227
 
package/lib/internal.d.ts CHANGED
@@ -180,7 +180,8 @@ declare enum WebsocketCloseCodes {
180
180
  MAX_NUMBER_OF_MESSAGES_PER_SECONDS = 4002,
181
181
  MAX_NUMBER_OF_CONCURRENT_CONNECTIONS = 4003,
182
182
  MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP = 4004,
183
- MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM = 4005
183
+ MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM = 4005,
184
+ CLOSE_WITHOUT_RETRY = 4999
184
185
  }
185
186
 
186
187
  declare const min = 32;
package/lib/internal.js CHANGED
@@ -56,6 +56,7 @@ exports.WebsocketCloseCodes = void 0;
56
56
  WebsocketCloseCodes[WebsocketCloseCodes["MAX_NUMBER_OF_CONCURRENT_CONNECTIONS"] = 4003] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS";
57
57
  WebsocketCloseCodes[WebsocketCloseCodes["MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP"] = 4004] = "MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP";
58
58
  WebsocketCloseCodes[WebsocketCloseCodes["MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM"] = 4005] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM";
59
+ WebsocketCloseCodes[WebsocketCloseCodes["CLOSE_WITHOUT_RETRY"] = 4999] = "CLOSE_WITHOUT_RETRY";
59
60
  })(exports.WebsocketCloseCodes || (exports.WebsocketCloseCodes = {}));
60
61
 
61
62
  var min = 32;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/client",
3
- "version": "0.15.1",
3
+ "version": "0.15.5",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",