Skip to content

Commit af93d6e

Browse files
author
smoghe-bw
committed
feat(rtc): add onConnectStatus event handler
Emit connectStatus event separately from ready so callers can subscribe to connect status updates independently via onConnectStatus.
1 parent a95a03d commit af93d6e

3 files changed

Lines changed: 26 additions & 33 deletions

File tree

src/v1/bandwidthRtc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ export class BandwidthRtc {
147147
this.readyHandler = callback;
148148
}
149149

150+
150151
/**
151152
* Publish media to the Bandwidth WebRTC platform
152153
*

src/v1/signaling.test.ts

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,29 +94,21 @@ describe("Signaling connect method", () => {
9494
}
9595
});
9696

97-
test("should merge connectStatus into readyMetadata and re-emit ready", async () => {
97+
test("should emit ready with connectStatus fields when gateway sends ready with connect status data", async () => {
9898
const emitSpy = jest.spyOn(signaling, "emit");
9999

100100
await signaling.connect({ endpointToken: "test-token" });
101101

102+
// Simulate a second ready event from the gateway that includes connect status fields
102103
const ws = (signaling as any).ws;
103-
const connectStatusCallback = ws.on.mock.calls.find((call: any) => call[0] === "connectStatus")?.[1];
104+
const readyCallback = ws.on.mock.calls.find((call: any) => call[0] === "ready")?.[1];
104105

105-
if (connectStatusCallback) {
106-
const testEvent = {
107-
status: "COMPLETED",
108-
accountId: "9900000",
109-
sessionId: "session-1",
110-
from: "ep-1",
111-
fromType: "ENDPOINT",
112-
fromTags: "tag1",
113-
to: "ep-2",
114-
toType: "ENDPOINT",
115-
toTags: "tag2",
116-
};
117-
connectStatusCallback(testEvent);
118-
expect(emitSpy).toHaveBeenCalledWith("ready", expect.objectContaining({
106+
if (readyCallback) {
107+
const readyWithConnectStatus = {
119108
endpointId: "test-endpoint",
109+
deviceId: "device-1",
110+
territory: "US",
111+
region: "us-east-1",
120112
connectStatus: "COMPLETED",
121113
accountId: "9900000",
122114
sessionId: "session-1",
@@ -126,7 +118,23 @@ describe("Signaling connect method", () => {
126118
to: "ep-2",
127119
toType: "ENDPOINT",
128120
toTags: "tag2",
129-
}));
121+
};
122+
readyCallback(readyWithConnectStatus);
123+
expect(emitSpy).toHaveBeenCalledWith(
124+
"ready",
125+
expect.objectContaining({
126+
endpointId: "test-endpoint",
127+
connectStatus: "COMPLETED",
128+
accountId: "9900000",
129+
sessionId: "session-1",
130+
from: "ep-1",
131+
fromType: "ENDPOINT",
132+
fromTags: "tag1",
133+
to: "ep-2",
134+
toType: "ENDPOINT",
135+
toTags: "tag2",
136+
}),
137+
);
130138
}
131139
});
132140
});

src/v1/signaling.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,6 @@ class Signaling extends EventEmitter {
5252
this.emit("sdpOffer", event);
5353
});
5454

55-
ws.on("connectStatus", (event: any) => {
56-
logger.debug("Websocket connectStatus", event);
57-
this.readyMetadata = {
58-
...this.readyMetadata!,
59-
connectStatus: event.status,
60-
accountId: event.accountId,
61-
sessionId: event.sessionId,
62-
from: event.from,
63-
fromType: event.fromType,
64-
fromTags: event.fromTags,
65-
to: event.to,
66-
toType: event.toType,
67-
toTags: event.toTags,
68-
};
69-
this.emit("ready", this.readyMetadata);
70-
});
7155

7256
ws.on("open", async () => {
7357
logger.debug("Websocket open");

0 commit comments

Comments
 (0)