@lark-sh/client 0.1.9 → 0.1.10
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.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +18 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -391,6 +391,13 @@ interface ConnectOptions {
|
|
|
391
391
|
* - 'webtransport': Force WebTransport only (fails if unavailable)
|
|
392
392
|
*/
|
|
393
393
|
transport?: TransportType;
|
|
394
|
+
/**
|
|
395
|
+
* Timeout for WebTransport connection attempt in milliseconds.
|
|
396
|
+
* If WebTransport doesn't connect within this time, falls back to WebSocket.
|
|
397
|
+
* Only applies when transport is 'auto'.
|
|
398
|
+
* Default: 2000 (2 seconds)
|
|
399
|
+
*/
|
|
400
|
+
webtransportTimeout?: number;
|
|
394
401
|
}
|
|
395
402
|
interface AuthInfo {
|
|
396
403
|
uid: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -391,6 +391,13 @@ interface ConnectOptions {
|
|
|
391
391
|
* - 'webtransport': Force WebTransport only (fails if unavailable)
|
|
392
392
|
*/
|
|
393
393
|
transport?: TransportType;
|
|
394
|
+
/**
|
|
395
|
+
* Timeout for WebTransport connection attempt in milliseconds.
|
|
396
|
+
* If WebTransport doesn't connect within this time, falls back to WebSocket.
|
|
397
|
+
* Only applies when transport is 'auto'.
|
|
398
|
+
* Default: 2000 (2 seconds)
|
|
399
|
+
*/
|
|
400
|
+
webtransportTimeout?: number;
|
|
394
401
|
}
|
|
395
402
|
interface AuthInfo {
|
|
396
403
|
uid: string;
|
package/dist/index.js
CHANGED
|
@@ -405,18 +405,31 @@ async function createTransport(wsUrl, transportOptions, options = {}) {
|
|
|
405
405
|
if (shouldTryWebTransport) {
|
|
406
406
|
const wtUrl = wsUrlToWtUrl(wsUrl);
|
|
407
407
|
const wtTransport = new WebTransportClient(transportOptions);
|
|
408
|
+
const timeout = options.webtransportTimeout ?? 2e3;
|
|
409
|
+
let timeoutId;
|
|
410
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
411
|
+
timeoutId = setTimeout(() => reject(new Error("WebTransport connection timeout")), timeout);
|
|
412
|
+
});
|
|
408
413
|
try {
|
|
409
|
-
await wtTransport.connect(wtUrl);
|
|
414
|
+
await Promise.race([wtTransport.connect(wtUrl), timeoutPromise]);
|
|
410
415
|
return {
|
|
411
416
|
transport: wtTransport,
|
|
412
417
|
type: "webtransport",
|
|
413
418
|
url: wtUrl
|
|
414
419
|
};
|
|
415
420
|
} catch (err) {
|
|
421
|
+
try {
|
|
422
|
+
wtTransport.close();
|
|
423
|
+
} catch {
|
|
424
|
+
}
|
|
416
425
|
if (preferredType === "webtransport") {
|
|
417
426
|
throw err;
|
|
418
427
|
}
|
|
419
428
|
console.warn("WebTransport connection failed, falling back to WebSocket:", err);
|
|
429
|
+
} finally {
|
|
430
|
+
if (timeoutId !== void 0) {
|
|
431
|
+
clearTimeout(timeoutId);
|
|
432
|
+
}
|
|
420
433
|
}
|
|
421
434
|
}
|
|
422
435
|
const wsTransport = new WebSocketTransport(transportOptions);
|
|
@@ -2803,7 +2816,10 @@ var LarkDatabase = class {
|
|
|
2803
2816
|
onClose: this.handleClose.bind(this),
|
|
2804
2817
|
onError: this.handleError.bind(this)
|
|
2805
2818
|
},
|
|
2806
|
-
{
|
|
2819
|
+
{
|
|
2820
|
+
transport: options.transport,
|
|
2821
|
+
webtransportTimeout: options.webtransportTimeout
|
|
2822
|
+
}
|
|
2807
2823
|
);
|
|
2808
2824
|
this.transport = transportResult.transport;
|
|
2809
2825
|
this._transportType = transportResult.type;
|