@sayknow-cli/bridge-client 0.4.7 → 0.5.0

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/client.ts +13 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@sayknow-cli/bridge-client",
4
- "version": "0.4.7",
4
+ "version": "0.5.0",
5
5
  "description": "Transport-only v3 SDK WebSocket client",
6
6
  "homepage": "https://sayknow-cli.com",
7
7
  "author": "jaybeyond and Sayknow-CLI Contributors",
package/src/client.ts CHANGED
@@ -59,6 +59,8 @@ type Incarnation = {
59
59
  openTimer?: ReturnType<typeof setTimeout>;
60
60
  failure?: Error;
61
61
  helloTimer?: ReturnType<typeof setTimeout>;
62
+ /** Hello frames that arrived before the open handler advanced phase to "hello". */
63
+ earlyHello?: Frame;
62
64
  resolveOpen?: () => void;
63
65
  rejectOpen?: (error: Error) => void;
64
66
  resolveHello?: () => void;
@@ -425,6 +427,12 @@ export class SdkClient {
425
427
  incarnation.resolveOpen = undefined;
426
428
  incarnation.rejectOpen = undefined;
427
429
  this.#beginHello(incarnation);
430
+ const earlyHello = incarnation.earlyHello;
431
+ if (earlyHello) {
432
+ incarnation.earlyHello = undefined;
433
+ this.#acceptHello(incarnation, earlyHello);
434
+ if (this.#isActive(incarnation)) this.#notifyFrameHandlers(earlyHello);
435
+ }
428
436
  }) as EventListener,
429
437
  true,
430
438
  );
@@ -513,6 +521,11 @@ export class SdkClient {
513
521
  return;
514
522
  }
515
523
  if (frame.type === "hello" || frame.type === "server_hello" || frame.type === "broker_hello") {
524
+ if (incarnation.phase === "opening" && this.#isCandidate(incarnation.cycle, incarnation)) {
525
+ // Buffer until the open handler advances phase; do not drop.
526
+ incarnation.earlyHello = frame;
527
+ return;
528
+ }
516
529
  if (incarnation.phase === "hello" && this.#isCandidate(incarnation.cycle, incarnation)) {
517
530
  this.#acceptHello(incarnation, frame);
518
531
  if (this.#isActive(incarnation)) this.#notifyFrameHandlers(frame);