@@ -110,11 +110,9 @@ export default class CallHandler {
110110 }
111111
112112 getAnyActiveCall ( ) {
113- const roomsWithCalls = Object . keys ( this . calls ) ;
114- for ( let i = 0 ; i < roomsWithCalls . length ; i ++ ) {
115- if ( this . calls . get ( roomsWithCalls [ i ] ) &&
116- this . calls . get ( roomsWithCalls [ i ] ) . call_state !== "ended" ) {
117- return this . calls . get ( roomsWithCalls [ i ] ) ;
113+ for ( const call of this . calls . values ( ) ) {
114+ if ( call . state !== "ended" ) {
115+ return call ;
118116 }
119117 }
120118 return null ;
@@ -180,7 +178,7 @@ export default class CallHandler {
180178 } ) ;
181179 } ) ;
182180 call . on ( "hangup" , ( ) => {
183- this . setCallState ( undefined , call . roomId , "ended" ) ;
181+ this . removeCallForRoom ( call . roomId ) ;
184182 } ) ;
185183 // map web rtc states to dummy UI state
186184 // ringing|ringback|connected|ended|busy|stop_ringback|stop_ringing
@@ -192,7 +190,7 @@ export default class CallHandler {
192190 this . setCallState ( call , call . roomId , "ringback" ) ;
193191 this . play ( "ringbackAudio" ) ;
194192 } else if ( newState === "ended" && oldState === "connected" ) {
195- this . setCallState ( undefined , call . roomId , "ended" ) ;
193+ this . removeCallForRoom ( call . roomId ) ;
196194 this . pause ( "ringbackAudio" ) ;
197195 this . play ( "callendAudio" ) ;
198196 } else if ( newState === "ended" && oldState === "invite_sent" &&
@@ -223,7 +221,11 @@ export default class CallHandler {
223221 console . log (
224222 `Call state in ${ roomId } changed to ${ status } (${ call ? call . call_state : "-" } )` ,
225223 ) ;
226- this . calls . set ( roomId , call ) ;
224+ if ( call ) {
225+ this . calls . set ( roomId , call ) ;
226+ } else {
227+ this . calls . delete ( roomId ) ;
228+ }
227229
228230 if ( status === "ringing" ) {
229231 this . play ( "ringAudio" ) ;
@@ -241,6 +243,10 @@ export default class CallHandler {
241243 } ) ;
242244 }
243245
246+ private removeCallForRoom ( roomId : string ) {
247+ this . setCallState ( null , roomId , null ) ;
248+ }
249+
244250 private showICEFallbackPrompt ( ) {
245251 const cli = MatrixClientPeg . get ( ) ;
246252 const code = sub => < code > { sub } </ code > ;
@@ -283,7 +289,7 @@ export default class CallHandler {
283289 } else if ( payload . type === 'screensharing' ) {
284290 const screenCapErrorString = PlatformPeg . get ( ) . screenCaptureErrorString ( ) ;
285291 if ( screenCapErrorString ) {
286- this . setCallState ( undefined , newCall . roomId , "ended" ) ;
292+ this . removeCallForRoom ( newCall . roomId ) ;
287293 console . log ( "Can't capture screen: " + screenCapErrorString ) ;
288294 Modal . createTrackedDialog ( 'Call Handler' , 'Unable to capture screen' , ErrorDialog , {
289295 title : _t ( 'Unable to capture screen' ) ,
@@ -376,7 +382,7 @@ export default class CallHandler {
376382 return ; // no call to hangup
377383 }
378384 this . calls . get ( payload . room_id ) . hangup ( ) ;
379- this . setCallState ( null , payload . room_id , "ended" ) ;
385+ this . removeCallForRoom ( payload . room_id ) ;
380386 break ;
381387 case 'answer' :
382388 if ( ! this . calls . get ( payload . room_id ) ) {
0 commit comments