@@ -30,6 +30,7 @@ export type MediaSignalingSessionConfig = {
3030 randomStringFactory : RandomStringFactory ;
3131 transport : MediaSignalTransport < ClientMediaSignal > ;
3232 iceGatheringTimeout ?: number ;
33+ iceServers ?: RTCIceServer [ ] ;
3334} ;
3435
3536const STATE_REPORT_INTERVAL = 60000 ;
@@ -90,7 +91,7 @@ export class MediaSignalingSession extends Emitter<MediaSignalingEvents> {
9091 }
9192
9293 public isBusy ( ) : boolean {
93- return this . getMainCall ( ) ?. busy ?? false ;
94+ return this . getMainCall ( false ) ?. busy ?? false ;
9495 }
9596
9697 public enableStateReport ( interval : number ) : void {
@@ -126,14 +127,17 @@ export class MediaSignalingSession extends Emitter<MediaSignalingEvents> {
126127 return this . knownCalls . get ( callId ) || null ;
127128 }
128129
129- public getMainCall ( ) : IClientMediaCall | null {
130+ public getMainCall ( skipLocal = false ) : IClientMediaCall | null {
130131 let ringingCall : IClientMediaCall | null = null ;
131132 let pendingCall : IClientMediaCall | null = null ;
132133
133134 for ( const call of this . knownCalls . values ( ) ) {
134135 if ( call . state === 'hangup' || call . ignored ) {
135136 continue ;
136137 }
138+ if ( skipLocal && ! call . confirmed ) {
139+ continue ;
140+ }
137141
138142 if ( call . busy ) {
139143 return call ;
@@ -193,6 +197,10 @@ export class MediaSignalingSession extends Emitter<MediaSignalingEvents> {
193197
194198 public async startCall ( calleeType : CallActorType , calleeId : string , params : { contactInfo ?: CallContact } = { } ) : Promise < void > {
195199 this . config . logger ?. debug ( 'MediaSignalingSession.startCall' , calleeId ) ;
200+ if ( this . getMainCall ( false ) ) {
201+ throw new Error ( `Already on a call.` ) ;
202+ }
203+
196204 const { contactInfo } = params ;
197205
198206 const callId = this . createTemporaryCallId ( ) ;
@@ -215,6 +223,10 @@ export class MediaSignalingSession extends Emitter<MediaSignalingEvents> {
215223 this . config . iceGatheringTimeout = newTimeout ;
216224 }
217225
226+ public setIceServers ( iceServers : RTCIceServer [ ] ) : void {
227+ this . config . iceServers = iceServers ;
228+ }
229+
218230 private createTemporaryCallId ( ) : string {
219231 return `${ this . _sessionId } -${ this . config . randomStringFactory ( ) } ` ;
220232 }
@@ -450,7 +462,8 @@ export class MediaSignalingSession extends Emitter<MediaSignalingEvents> {
450462 logger : this . config . logger ,
451463 transporter : this . transporter ,
452464 processorFactories : this . config . processorFactories ,
453- iceGatheringTimeout : this . config . iceGatheringTimeout || 1000 ,
465+ iceGatheringTimeout : this . config . iceGatheringTimeout || 5000 ,
466+ iceServers : this . config . iceServers || [ ] ,
454467 sessionId : this . _sessionId ,
455468 } ;
456469
@@ -462,6 +475,7 @@ export class MediaSignalingSession extends Emitter<MediaSignalingEvents> {
462475 call . emitter . on ( 'clientStateChange' , ( ) => this . onCallClientStateChange ( call ) ) ;
463476 call . emitter . on ( 'trackStateChange' , ( ) => this . onTrackStateChange ( call ) ) ;
464477 call . emitter . on ( 'initialized' , ( ) => this . onNewCall ( call ) ) ;
478+ call . emitter . on ( 'confirmed' , ( ) => this . onConfirmedCall ( call ) ) ;
465479 call . emitter . on ( 'accepted' , ( ) => this . onAcceptedCall ( call ) ) ;
466480 call . emitter . on ( 'accepting' , ( ) => this . onAcceptingCall ( call ) ) ;
467481 call . emitter . on ( 'hidden' , ( ) => this . onHiddenCall ( call ) ) ;
@@ -491,6 +505,11 @@ export class MediaSignalingSession extends Emitter<MediaSignalingEvents> {
491505 this . onSessionStateChange ( ) ;
492506 }
493507
508+ private onConfirmedCall ( _call : ClientMediaCall ) : void {
509+ this . config . logger ?. debug ( 'MediaSignalingSession.onConfirmedCall' ) ;
510+ this . onSessionStateChange ( ) ;
511+ }
512+
494513 private onAcceptedCall ( _call : ClientMediaCall ) : void {
495514 this . config . logger ?. debug ( 'MediaSignalingSession.onAcceptedCall' ) ;
496515 this . onSessionStateChange ( ) ;
@@ -523,15 +542,16 @@ export class MediaSignalingSession extends Emitter<MediaSignalingEvents> {
523542 }
524543
525544 private onSessionStateChange ( ) : void {
526- const mainCall = this . getMainCall ( ) ;
527- const hasCall = Boolean ( mainCall ) ;
528- const hasVisibleCall = Boolean ( mainCall && ! mainCall . hidden ) ;
529- const hasBusyCall = Boolean ( hasVisibleCall && mainCall ?. busy ) ;
530-
531545 const hadCall = this . lastState . hasCall ;
532546 const hadVisibleCall = this . lastState . hasVisibleCall ;
533547 const hadBusyCall = this . lastState . hasBusyCall ;
534548
549+ // Do not skip local calls if we transitioned from a different active call to it
550+ const mainCall = this . getMainCall ( ! hadCall ) ;
551+ const hasCall = Boolean ( mainCall ) ;
552+ const hasVisibleCall = Boolean ( mainCall && ! mainCall . hidden ) ;
553+ const hasBusyCall = Boolean ( hasVisibleCall && mainCall ?. busy ) ;
554+
535555 this . lastState = { hasCall, hasVisibleCall, hasBusyCall } ;
536556
537557 if ( mainCall && ! hadCall ) {
0 commit comments