@@ -131,6 +131,7 @@ export class BandwidthRtc {
131131 this . signaling . on ( "init" , this . init . bind ( this ) ) ;
132132 this . signaling . on ( "streamAvailable" , ( { callId, autoAccepted } : { callId : string ; autoAccepted : boolean } ) => {
133133 if ( this . pendingSubscribeStream ) {
134+ // ontrack already fired at connect time — fire the combined event now.
134135 this . callIsActive = true ;
135136 this . streamAvailableHandler ?.( {
136137 mediaTypes : [ MediaType . AUDIO ] ,
@@ -139,7 +140,7 @@ export class BandwidthRtc {
139140 autoAccepted,
140141 } ) ;
141142 } else {
142- // ontrack hasn't fired yet — store and fire once it does
143+ // ontrack hasn't fired yet — store and fire once it does.
143144 this . pendingCallInfo = { callId, autoAccepted } ;
144145 }
145146 } ) ;
@@ -151,7 +152,7 @@ export class BandwidthRtc {
151152 this . pendingCallInfo = undefined ;
152153 this . streamUnavailableHandler ?.( {
153154 mediaTypes : [ MediaType . AUDIO ] ,
154- mediaStream : this . pendingSubscribeStream ,
155+ mediaStream : this . pendingSubscribeStream ! ,
155156 callId,
156157 } ) ;
157158 } ) ;
@@ -527,6 +528,17 @@ export class BandwidthRtc {
527528
528529 track . onunmute = ( event ) => {
529530 logger . debug ( "onunmute" , event . target ) ;
531+ // Fallback for gateways that don't send WS streamAvailable: fire
532+ // onStreamAvailable when audio actually starts flowing. No-op on new
533+ // gateways because callIsActive is already true from the WS event.
534+ if ( ! this . callIsActive && this . pendingSubscribeStream ) {
535+ this . callIsActive = true ;
536+ logger . debug ( "onStreamAvailable (onunmute fallback)" , this . pendingSubscribeStream . id ) ;
537+ this . streamAvailableHandler ?.( {
538+ mediaTypes : [ MediaType . AUDIO ] ,
539+ mediaStream : this . pendingSubscribeStream ,
540+ } ) ;
541+ }
530542 } ;
531543
532544 track . onended = ( event ) => {
@@ -567,24 +579,19 @@ export class BandwidthRtc {
567579 }
568580 } ;
569581
570- // Store the subscribe stream. We fire onStreamAvailable only when the WS
571- // streamAvailable notification arrives (which carries callId/autoAccepted), so
572- // that customers always receive a single event with mediaStream set. If the WS
573- // notification already arrived before ontrack, fire the combined event now.
574582 this . pendingSubscribeStream = stream ;
575583 if ( this . pendingCallInfo ) {
584+ // WS arrived before ontrack — fire the combined event now.
576585 const { callId, autoAccepted } = this . pendingCallInfo ;
577586 this . pendingCallInfo = undefined ;
578587 this . callIsActive = true ;
579- logger . debug ( "onStreamAvailable (deferred )" , stream . id ) ;
588+ logger . debug ( "onStreamAvailable (WS-enriched )" , stream . id ) ;
580589 this . streamAvailableHandler ?.( {
581590 mediaTypes : [ MediaType . AUDIO ] ,
582591 mediaStream : stream ,
583592 callId,
584593 autoAccepted,
585594 } ) ;
586- } else {
587- logger . debug ( "ontrack: stored subscribe stream, waiting for WS streamAvailable" , stream . id ) ;
588595 }
589596 }
590597 } ;
0 commit comments