@@ -112,11 +112,9 @@ export default class CallHandler {
112112 }
113113
114114 getAnyActiveCall ( ) {
115- const roomsWithCalls = Object . keys ( this . calls ) ;
116- for ( let i = 0 ; i < roomsWithCalls . length ; i ++ ) {
117- if ( this . calls . get ( roomsWithCalls [ i ] ) &&
118- this . calls . get ( roomsWithCalls [ i ] ) . call_state !== "ended" ) {
119- return this . calls . get ( roomsWithCalls [ i ] ) ;
115+ for ( const call of this . calls . values ( ) ) {
116+ if ( call . state !== "ended" ) {
117+ return call ;
120118 }
121119 }
122120 return null ;
@@ -182,7 +180,7 @@ export default class CallHandler {
182180 } ) ;
183181 } ) ;
184182 call . on ( "hangup" , ( ) => {
185- this . setCallState ( undefined , call . roomId , "ended" ) ;
183+ this . removeCallForRoom ( call . roomId ) ;
186184 } ) ;
187185 // map web rtc states to dummy UI state
188186 // ringing|ringback|connected|ended|busy|stop_ringback|stop_ringing
@@ -194,7 +192,7 @@ export default class CallHandler {
194192 this . setCallState ( call , call . roomId , "ringback" ) ;
195193 this . play ( "ringbackAudio" ) ;
196194 } else if ( newState === "ended" && oldState === "connected" ) {
197- this . setCallState ( undefined , call . roomId , "ended" ) ;
195+ this . removeCallForRoom ( call . roomId ) ;
198196 this . pause ( "ringbackAudio" ) ;
199197 this . play ( "callendAudio" ) ;
200198 } else if ( newState === "ended" && oldState === "invite_sent" &&
@@ -225,7 +223,11 @@ export default class CallHandler {
225223 console . log (
226224 `Call state in ${ roomId } changed to ${ status } (${ call ? call . call_state : "-" } )` ,
227225 ) ;
228- this . calls . set ( roomId , call ) ;
226+ if ( call ) {
227+ this . calls . set ( roomId , call ) ;
228+ } else {
229+ this . calls . delete ( roomId ) ;
230+ }
229231
230232 if ( status === "ringing" ) {
231233 this . play ( "ringAudio" ) ;
@@ -243,6 +245,10 @@ export default class CallHandler {
243245 } ) ;
244246 }
245247
248+ private removeCallForRoom ( roomId : string ) {
249+ this . setCallState ( null , roomId , null ) ;
250+ }
251+
246252 private showICEFallbackPrompt ( ) {
247253 const cli = MatrixClientPeg . get ( ) ;
248254 const code = sub => < code > { sub } </ code > ;
@@ -285,7 +291,7 @@ export default class CallHandler {
285291 } else if ( payload . type === 'screensharing' ) {
286292 const screenCapErrorString = PlatformPeg . get ( ) . screenCaptureErrorString ( ) ;
287293 if ( screenCapErrorString ) {
288- this . setCallState ( undefined , newCall . roomId , "ended" ) ;
294+ this . removeCallForRoom ( newCall . roomId ) ;
289295 console . log ( "Can't capture screen: " + screenCapErrorString ) ;
290296 Modal . createTrackedDialog ( 'Call Handler' , 'Unable to capture screen' , ErrorDialog , {
291297 title : _t ( 'Unable to capture screen' ) ,
@@ -386,7 +392,7 @@ export default class CallHandler {
386392 return ; // no call to hangup
387393 }
388394 this . calls . get ( payload . room_id ) . hangup ( ) ;
389- this . setCallState ( null , payload . room_id , "ended" ) ;
395+ this . removeCallForRoom ( payload . room_id ) ;
390396 break ;
391397 case 'answer' :
392398 if ( ! this . calls . get ( payload . room_id ) ) {
0 commit comments