@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.mjs CHANGED
@@ -362,18 +362,31 @@ async function createTransport(wsUrl, transportOptions, options = {}) {
362
362
  if (shouldTryWebTransport) {
363
363
  const wtUrl = wsUrlToWtUrl(wsUrl);
364
364
  const wtTransport = new WebTransportClient(transportOptions);
365
+ const timeout = options.webtransportTimeout ?? 2e3;
366
+ let timeoutId;
367
+ const timeoutPromise = new Promise((_, reject) => {
368
+ timeoutId = setTimeout(() => reject(new Error("WebTransport connection timeout")), timeout);
369
+ });
365
370
  try {
366
- await wtTransport.connect(wtUrl);
371
+ await Promise.race([wtTransport.connect(wtUrl), timeoutPromise]);
367
372
  return {
368
373
  transport: wtTransport,
369
374
  type: "webtransport",
370
375
  url: wtUrl
371
376
  };
372
377
  } catch (err) {
378
+ try {
379
+ wtTransport.close();
380
+ } catch {
381
+ }
373
382
  if (preferredType === "webtransport") {
374
383
  throw err;
375
384
  }
376
385
  console.warn("WebTransport connection failed, falling back to WebSocket:", err);
386
+ } finally {
387
+ if (timeoutId !== void 0) {
388
+ clearTimeout(timeoutId);
389
+ }
377
390
  }
378
391
  }
379
392
  const wsTransport = new WebSocketTransport(transportOptions);
@@ -2760,7 +2773,10 @@ var LarkDatabase = class {
2760
2773
  onClose: this.handleClose.bind(this),
2761
2774
  onError: this.handleError.bind(this)
2762
2775
  },
2763
- { transport: options.transport }
2776
+ {
2777
+ transport: options.transport,
2778
+ webtransportTimeout: options.webtransportTimeout
2779
+ }
2764
2780
  );
2765
2781
  this.transport = transportResult.transport;
2766
2782
  this._transportType = transportResult.type;