Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/bandwidthRtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class BandwidthRtc {
// Event handlers
private streamAvailableHandler?: { (event: RtcStream): void };
private streamUnavailableHandler?: { (event: RtcStream): void };
private inboundStreamNotificationHandler?: { (event: RtcStream): void };
private readyHandler?: { (readyMetadata: ReadyMetadata): void };

private logLevel?: LogLevel;
Expand Down Expand Up @@ -77,6 +78,10 @@ class BandwidthRtc {
this.delegate!.onStreamUnavailable(this.streamUnavailableHandler);
}

if (this.inboundStreamNotificationHandler) {
this.delegate!.onInboundStreamNotification(this.inboundStreamNotificationHandler);
}

if (this.readyHandler) {
this.delegate!.onReady(this.readyHandler);
}
Expand Down Expand Up @@ -116,6 +121,19 @@ class BandwidthRtc {
}
}

/**
* Set the function that will be called when the gateway signals that an inbound
* stream is ready to be accepted or declined, before the WebRTC media arrives.
* Use this to drive accept/decline UI; mediaStream will be undefined at this point.
* @param callback callback function
*/
onInboundStreamNotification(callback: { (event: RtcStream): void }): void {
this.inboundStreamNotificationHandler = callback;
if (this.delegate) {
this.delegate.onInboundStreamNotification(callback);
}
}

/**
* Set the function that will be called when a subscribed stream becomes unavailable
* @param callback callback function
Expand Down
20 changes: 16 additions & 4 deletions src/v1/bandwidthRtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
// Event handlers
private streamAvailableHandler?: { (event: RtcStream): void };
private streamUnavailableHandler?: { (event: RtcStream): void };
private inboundStreamNotificationHandler?: { (event: RtcStream): void };
private readyHandler?: { (readyMetadata: ReadyMetadata): void };

/**
Expand Down Expand Up @@ -109,9 +110,9 @@
this.signaling.on("ready", this.handleReady.bind(this));
this.signaling.on("sdpOffer", this.handleSubscribeSdpOffer.bind(this));
this.signaling.on("init", this.init.bind(this));
this.signaling.on("streamAvailable", ({ callId }: { callId: string }) => {
if (this.streamAvailableHandler) {
this.streamAvailableHandler({ mediaTypes: [MediaType.AUDIO], callId });
this.signaling.on("streamAvailable", ({ callId, autoAccepted }: { callId: string; autoAccepted: boolean }) => {
if (this.inboundStreamNotificationHandler) {
this.inboundStreamNotificationHandler({ mediaTypes: [MediaType.AUDIO], callId, autoAccepted });

Check failure on line 115 in src/v1/bandwidthRtc.ts

View workflow job for this annotation

GitHub Actions / build-and-test

Object literal may only specify known properties, and 'autoAccepted' does not exist in type 'RtcStream'.
}
});
this.signaling.on("streamUnavailable", ({ callId }: { callId: string }) => {
Expand All @@ -134,13 +135,24 @@
}

/**
* Set the function that will be called when a subscribed stream becomes available
* Set the function that will be called when a subscribed stream becomes available.
* The RtcStream passed to the callback always contains a populated mediaStream.
* @param callback callback function
*/
onStreamAvailable(callback: { (event: RtcStream): void }): void {
this.streamAvailableHandler = callback;
}

/**
* Set the function that will be called when the gateway signals that an inbound
* stream is ready to be accepted or declined, before the WebRTC media arrives.
* Use this to drive accept/decline UI; mediaStream will be undefined at this point.
* @param callback callback function
*/
onInboundStreamNotification(callback: { (event: RtcStream): void }): void {
this.inboundStreamNotificationHandler = callback;
}

/**
* Set the function that will be called when a subscribed stream becomes unavailable
* @param callback callback function
Expand Down
Loading