@liveblocks/core 1.1.0-beta1 → 1.1.0-beta2
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/dist/index.js +60 -36
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -157,7 +157,7 @@ var onMessageFromPanel = eventSource.observable;
|
|
|
157
157
|
// src/devtools/index.ts
|
|
158
158
|
var VERSION = true ? (
|
|
159
159
|
/* istanbul ignore next */
|
|
160
|
-
"1.1.0-
|
|
160
|
+
"1.1.0-beta2"
|
|
161
161
|
) : "dev";
|
|
162
162
|
var _devtoolsSetupHasRun = false;
|
|
163
163
|
function setupDevTools(getAllRooms) {
|
|
@@ -901,10 +901,39 @@ function log(level, message) {
|
|
|
901
901
|
logger(message);
|
|
902
902
|
};
|
|
903
903
|
}
|
|
904
|
+
function logPrematureErrorOrCloseEvent(e) {
|
|
905
|
+
const conn = "Connection to Liveblocks websocket server";
|
|
906
|
+
return (ctx) => {
|
|
907
|
+
if (e instanceof Error) {
|
|
908
|
+
warn(`${conn} could not be established. ${String(e)}`);
|
|
909
|
+
} else {
|
|
910
|
+
warn(
|
|
911
|
+
isCloseEvent(e) ? `${conn} closed prematurely (code: ${e.code}). Retrying in ${ctx.backoffDelay}ms.` : `${conn} could not be established.`
|
|
912
|
+
);
|
|
913
|
+
}
|
|
914
|
+
};
|
|
915
|
+
}
|
|
916
|
+
function logCloseEvent(event) {
|
|
917
|
+
return (ctx) => {
|
|
918
|
+
warn(
|
|
919
|
+
`Connection to Liveblocks websocket server closed (code: ${event.code}). Retrying in ${ctx.backoffDelay}ms.`
|
|
920
|
+
);
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
var logPermanentClose = log(
|
|
924
|
+
1 /* WARN */,
|
|
925
|
+
"Connection to WebSocket closed permanently. Won't retry."
|
|
926
|
+
);
|
|
904
927
|
function sendHeartbeat(ctx) {
|
|
905
928
|
var _a;
|
|
906
929
|
(_a = ctx.socket) == null ? void 0 : _a.send("ping");
|
|
907
930
|
}
|
|
931
|
+
function isCloseEvent(error2) {
|
|
932
|
+
return !(error2 instanceof Error) && error2.type === "close";
|
|
933
|
+
}
|
|
934
|
+
function isCustomCloseEvent(error2) {
|
|
935
|
+
return isCloseEvent(error2) && error2.code >= 4e3 && error2.code < 4100;
|
|
936
|
+
}
|
|
908
937
|
function enableTracing(machine) {
|
|
909
938
|
const start = (/* @__PURE__ */ new Date()).getTime();
|
|
910
939
|
function log2(...args) {
|
|
@@ -1118,23 +1147,24 @@ function createConnectionStateMachine(delegates, enableDebugLogging) {
|
|
|
1118
1147
|
effect: log(2 /* ERROR */, err.message)
|
|
1119
1148
|
};
|
|
1120
1149
|
}
|
|
1150
|
+
if (isCloseEvent(err) && err.code === 4999) {
|
|
1151
|
+
return {
|
|
1152
|
+
target: "@idle.failed",
|
|
1153
|
+
effect: log(2 /* ERROR */, err.reason)
|
|
1154
|
+
};
|
|
1155
|
+
}
|
|
1156
|
+
if (isCustomCloseEvent(err) && err.code !== 4001) {
|
|
1157
|
+
return {
|
|
1158
|
+
target: "@connecting.backoff",
|
|
1159
|
+
effect: [
|
|
1160
|
+
increaseBackoffDelayAggressively,
|
|
1161
|
+
logPrematureErrorOrCloseEvent(err)
|
|
1162
|
+
]
|
|
1163
|
+
};
|
|
1164
|
+
}
|
|
1121
1165
|
return {
|
|
1122
1166
|
target: "@auth.backoff",
|
|
1123
|
-
effect: [
|
|
1124
|
-
// Increase the backoff delay conditionally
|
|
1125
|
-
// TODO: This is ugly. DRY this up with the other code 40xx checks elsewhere.
|
|
1126
|
-
!(err instanceof Error) && err.type === "close" && err.code >= 4e3 && err.code <= 4100 ? increaseBackoffDelayAggressively : increaseBackoffDelay,
|
|
1127
|
-
// Produce a useful log message
|
|
1128
|
-
(ctx) => {
|
|
1129
|
-
if (err instanceof Error) {
|
|
1130
|
-
warn(String(err));
|
|
1131
|
-
} else {
|
|
1132
|
-
warn(
|
|
1133
|
-
err.type === "close" ? `Connection to Liveblocks websocket server closed prematurely (code: ${err.code}). Retrying in ${ctx.backoffDelay}ms.` : "Connection to Liveblocks websocket server could not be established."
|
|
1134
|
-
);
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
]
|
|
1167
|
+
effect: [increaseBackoffDelay, logPrematureErrorOrCloseEvent(err)]
|
|
1138
1168
|
};
|
|
1139
1169
|
}
|
|
1140
1170
|
);
|
|
@@ -1185,37 +1215,31 @@ function createConnectionStateMachine(delegates, enableDebugLogging) {
|
|
|
1185
1215
|
if (e.event.code === 4999) {
|
|
1186
1216
|
return {
|
|
1187
1217
|
target: "@idle.failed",
|
|
1188
|
-
effect:
|
|
1189
|
-
1 /* WARN */,
|
|
1190
|
-
"Connection to WebSocket closed permanently. Won't retry."
|
|
1191
|
-
)
|
|
1218
|
+
effect: logPermanentClose
|
|
1192
1219
|
};
|
|
1193
1220
|
}
|
|
1194
|
-
if (e.event.code
|
|
1221
|
+
if (e.event.code === 4001) {
|
|
1222
|
+
return {
|
|
1223
|
+
target: "@auth.backoff",
|
|
1224
|
+
effect: [increaseBackoffDelay, logCloseEvent(e.event)]
|
|
1225
|
+
};
|
|
1226
|
+
}
|
|
1227
|
+
if (isCustomCloseEvent(e.event)) {
|
|
1195
1228
|
return {
|
|
1196
1229
|
target: "@connecting.backoff",
|
|
1197
1230
|
effect: [
|
|
1198
1231
|
increaseBackoffDelayAggressively,
|
|
1199
|
-
(
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
if (event.code >= 4e3 && event.code <= 4100) {
|
|
1204
|
-
const err = new LiveblocksError(event.reason, event.code);
|
|
1205
|
-
onLiveblocksError.notify(err);
|
|
1206
|
-
}
|
|
1232
|
+
logCloseEvent(e.event),
|
|
1233
|
+
() => {
|
|
1234
|
+
const err = new LiveblocksError(e.event.reason, e.event.code);
|
|
1235
|
+
onLiveblocksError.notify(err);
|
|
1207
1236
|
}
|
|
1208
1237
|
]
|
|
1209
1238
|
};
|
|
1210
1239
|
}
|
|
1211
1240
|
return {
|
|
1212
1241
|
target: "@connecting.backoff",
|
|
1213
|
-
effect: [
|
|
1214
|
-
increaseBackoffDelay,
|
|
1215
|
-
(ctx) => warn(
|
|
1216
|
-
`Connection to Liveblocks websocket server closed (code: ${e.event.code}). Retrying in ${ctx.backoffDelay}ms.`
|
|
1217
|
-
)
|
|
1218
|
-
]
|
|
1242
|
+
effect: [increaseBackoffDelay, logCloseEvent(e.event)]
|
|
1219
1243
|
};
|
|
1220
1244
|
}
|
|
1221
1245
|
});
|
|
@@ -5277,7 +5301,7 @@ function makeCreateSocketDelegateForRoom(liveblocksServer, WebSocketPolyfill) {
|
|
|
5277
5301
|
// @ts-ignore (__PACKAGE_VERSION__ will be injected by the build script)
|
|
5278
5302
|
true ? (
|
|
5279
5303
|
/* istanbul ignore next */
|
|
5280
|
-
"1.1.0-
|
|
5304
|
+
"1.1.0-beta2"
|
|
5281
5305
|
) : "dev"}`
|
|
5282
5306
|
);
|
|
5283
5307
|
};
|