@phpsandbox/sdk 0.0.34 → 0.0.35
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/browser/phpsandbox-sdk.esm.js +42 -16
- package/dist/browser/phpsandbox-sdk.esm.js.map +2 -2
- package/dist/browser/phpsandbox-sdk.esm.min.js +2 -2
- package/dist/browser/phpsandbox-sdk.esm.min.js.map +3 -3
- package/dist/browser/phpsandbox-sdk.iife.js +42 -16
- package/dist/browser/phpsandbox-sdk.iife.js.map +2 -2
- package/dist/browser/phpsandbox-sdk.iife.min.js +2 -2
- package/dist/browser/phpsandbox-sdk.iife.min.js.map +3 -3
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/socket/index.d.ts +2 -0
- package/dist/socket/index.d.ts.map +1 -1
- package/dist/socket/index.js +37 -18
- package/dist/socket/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -3222,6 +3222,12 @@ var NamedDisposable = class {
|
|
|
3222
3222
|
};
|
|
3223
3223
|
|
|
3224
3224
|
// src/socket/index.ts
|
|
3225
|
+
var ConnectionTimeoutError = class extends Error {
|
|
3226
|
+
constructor(message = "WebSocket connection timeout") {
|
|
3227
|
+
super(message);
|
|
3228
|
+
this.name = "ConnectionTimeoutError";
|
|
3229
|
+
}
|
|
3230
|
+
};
|
|
3225
3231
|
var ConnectionFailedError = class extends Error {
|
|
3226
3232
|
constructor(message, originalError) {
|
|
3227
3233
|
super(message);
|
|
@@ -3280,6 +3286,7 @@ var Transport = class {
|
|
|
3280
3286
|
this.validateConfiguration(options);
|
|
3281
3287
|
this.url = new URL(url);
|
|
3282
3288
|
this.PING_INTERVAL = options.pingInterval ?? 3e4;
|
|
3289
|
+
this.CONNECT_WAIT_TIMEOUT = options.connectWaitTimeout ?? 3e4;
|
|
3283
3290
|
this.connectionStats.connectionStartTime = Date.now();
|
|
3284
3291
|
const startClosed = options.startClosed !== false;
|
|
3285
3292
|
this.rws = new reconnecting_websocket_mjs_default(this.url.toString(), [], {
|
|
@@ -3309,6 +3316,9 @@ var Transport = class {
|
|
|
3309
3316
|
if (options.connectionTimeout !== void 0 && (options.connectionTimeout < 100 || options.connectionTimeout > 3e4)) {
|
|
3310
3317
|
throw new InvalidConfigurationError("connectionTimeout must be between 100ms and 30000ms");
|
|
3311
3318
|
}
|
|
3319
|
+
if (options.connectWaitTimeout !== void 0 && (options.connectWaitTimeout < 1e3 || options.connectWaitTimeout > 3e5)) {
|
|
3320
|
+
throw new InvalidConfigurationError("connectWaitTimeout must be between 1000ms and 300000ms");
|
|
3321
|
+
}
|
|
3312
3322
|
if (options.maxRetries !== void 0 && (options.maxRetries < 0 || options.maxRetries > 100)) {
|
|
3313
3323
|
throw new InvalidConfigurationError("maxRetries must be between 0 and 100");
|
|
3314
3324
|
}
|
|
@@ -4043,34 +4053,50 @@ connect_fn = function() {
|
|
|
4043
4053
|
__privateMethod(this, _Transport_instances, startPeriodicPing_fn).call(this);
|
|
4044
4054
|
return;
|
|
4045
4055
|
}
|
|
4046
|
-
if (this.rws.readyState === 3) {
|
|
4047
|
-
this.rws.reconnect();
|
|
4048
|
-
}
|
|
4049
4056
|
let timeoutId;
|
|
4050
|
-
|
|
4057
|
+
let errorCount = 0;
|
|
4058
|
+
const cleanup = () => {
|
|
4051
4059
|
this.rws.removeEventListener("open", openHandler);
|
|
4052
4060
|
this.rws.removeEventListener("error", errorHandler);
|
|
4061
|
+
this.rws.removeEventListener("close", closeHandler);
|
|
4053
4062
|
clearTimeout(timeoutId);
|
|
4063
|
+
};
|
|
4064
|
+
const openHandler = () => {
|
|
4065
|
+
cleanup();
|
|
4054
4066
|
this.connectPromise = null;
|
|
4055
4067
|
resolve();
|
|
4056
4068
|
__privateMethod(this, _Transport_instances, startPeriodicPing_fn).call(this);
|
|
4057
4069
|
};
|
|
4058
4070
|
const errorHandler = (error) => {
|
|
4059
|
-
|
|
4060
|
-
this.
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4071
|
+
errorCount += 1;
|
|
4072
|
+
this.log("warn", "WebSocket emitted an error while connecting; waiting for reconnect/open", {
|
|
4073
|
+
errorCount,
|
|
4074
|
+
error: describeWebSocketEvent(error)
|
|
4075
|
+
});
|
|
4076
|
+
};
|
|
4077
|
+
const closeHandler = (event) => {
|
|
4078
|
+
const detail = describeWebSocketEvent(event);
|
|
4079
|
+
if ("code" in event && (event.code === 1008 || event.code === 4e3)) {
|
|
4080
|
+
cleanup();
|
|
4081
|
+
this.connectPromise = null;
|
|
4082
|
+
reject(new ConnectionFailedError(`WebSocket connection failed: ${detail}`, event));
|
|
4083
|
+
return;
|
|
4084
|
+
}
|
|
4085
|
+
this.log("warn", "WebSocket closed before opening; waiting for reconnect/open", {
|
|
4086
|
+
error: detail
|
|
4087
|
+
});
|
|
4065
4088
|
};
|
|
4066
|
-
timeoutId = setTimeout(() => {
|
|
4067
|
-
this.rws.removeEventListener("open", openHandler);
|
|
4068
|
-
this.rws.removeEventListener("error", errorHandler);
|
|
4069
|
-
this.connectPromise = null;
|
|
4070
|
-
reject(new Error("WebSocket connection timeout"));
|
|
4071
|
-
}, 1e4);
|
|
4072
4089
|
this.rws.addEventListener("open", openHandler);
|
|
4073
4090
|
this.rws.addEventListener("error", errorHandler);
|
|
4091
|
+
this.rws.addEventListener("close", closeHandler);
|
|
4092
|
+
if (this.rws.readyState === 3) {
|
|
4093
|
+
this.rws.reconnect();
|
|
4094
|
+
}
|
|
4095
|
+
timeoutId = setTimeout(() => {
|
|
4096
|
+
cleanup();
|
|
4097
|
+
this.connectPromise = null;
|
|
4098
|
+
reject(new ConnectionTimeoutError(`WebSocket connection timeout after ${this.CONNECT_WAIT_TIMEOUT}ms`));
|
|
4099
|
+
}, this.CONNECT_WAIT_TIMEOUT);
|
|
4074
4100
|
});
|
|
4075
4101
|
return this.connectPromise;
|
|
4076
4102
|
};
|