@@ -541,6 +541,7 @@ export class MatrixCall extends EventEmitter {
541541 this . chooseOpponent ( event ) ;
542542 try {
543543 await this . peerConn . setRemoteDescription ( invite . offer ) ;
544+ await this . addBufferedIceCandidates ( ) ;
544545 } catch ( e ) {
545546 logger . debug ( "Failed to set remote description" , e ) ;
546547 this . terminate ( CallParty . Local , CallErrorCode . SetRemoteDescription , false ) ;
@@ -985,7 +986,7 @@ export class MatrixCall extends EventEmitter {
985986 private gotLocalIceCandidate = ( event : RTCPeerConnectionIceEvent ) => {
986987 if ( event . candidate ) {
987988 logger . debug (
988- "Got local ICE " + event . candidate . sdpMid + " candidate: " +
989+ "Call " + this . callId + " got local ICE " + event . candidate . sdpMid + " candidate: " +
989990 event . candidate . candidate ,
990991 ) ;
991992
@@ -1019,7 +1020,7 @@ export class MatrixCall extends EventEmitter {
10191020 }
10201021 } ;
10211022
1022- onRemoteIceCandidatesReceived ( ev : MatrixEvent ) {
1023+ async onRemoteIceCandidatesReceived ( ev : MatrixEvent ) {
10231024 if ( this . callHasEnded ( ) ) {
10241025 //debuglog("Ignoring remote ICE candidate because call has ended");
10251026 return ;
@@ -1051,15 +1052,18 @@ export class MatrixCall extends EventEmitter {
10511052 return ;
10521053 }
10531054
1054- this . addIceCandidates ( cands ) ;
1055+ await this . addIceCandidates ( cands ) ;
10551056 }
10561057
10571058 /**
10581059 * Used by MatrixClient.
10591060 * @param {Object } msg
10601061 */
10611062 async onAnswerReceived ( event : MatrixEvent ) {
1063+ logger . debug ( `Got answer for call ID ${ this . callId } from party ID ${ event . getContent ( ) . party_id } ` ) ;
1064+
10621065 if ( this . callHasEnded ( ) ) {
1066+ logger . debug ( `Ignoring answer because call ID ${ this . callId } has ended` ) ;
10631067 return ;
10641068 }
10651069
@@ -1072,6 +1076,7 @@ export class MatrixCall extends EventEmitter {
10721076 }
10731077
10741078 this . chooseOpponent ( event ) ;
1079+ await this . addBufferedIceCandidates ( ) ;
10751080
10761081 this . setState ( CallState . Connecting ) ;
10771082
@@ -1520,7 +1525,10 @@ export class MatrixCall extends EventEmitter {
15201525 }
15211526 }
15221527
1523- async transfer ( targetUserId : string , targetRoomId ?: string ) {
1528+ /*
1529+ * Transfers this call to another user
1530+ */
1531+ async transfer ( targetUserId : string ) {
15241532 // Fetch the target user's global profile info: their room avatar / displayname
15251533 // could be different in whatever room we shae with them.
15261534 const profileInfo = await this . client . getProfileInfo ( targetUserId ) ;
@@ -1537,11 +1545,16 @@ export class MatrixCall extends EventEmitter {
15371545 create_call : replacementId ,
15381546 } as MCallReplacesEvent ;
15391547
1540- if ( targetRoomId ) body . target_room = targetRoomId ;
1541-
15421548 return this . sendVoipEvent ( EventType . CallReplaces , body ) ;
15431549 }
15441550
1551+ /*
1552+ * Transfers this call to the target call, effectively 'joining' the
1553+ * two calls (so the remote parties on each call are connected together).
1554+ */
1555+ async transferToCall ( transferTargetCall ?: MatrixCall ) {
1556+ }
1557+
15451558 private async terminate ( hangupParty : CallParty , hangupReason : CallErrorCode , shouldEmit : boolean ) {
15461559 if ( this . callHasEnded ( ) ) return ;
15471560
@@ -1722,6 +1735,8 @@ export class MatrixCall extends EventEmitter {
17221735 // I choo-choo-choose you
17231736 const msg = ev . getContent ( ) ;
17241737
1738+ logger . debug ( `Choosing party ID ${ msg . party_id } for call ID ${ this . callId } ` ) ;
1739+
17251740 this . opponentVersion = msg . version ;
17261741 if ( this . opponentVersion === 0 ) {
17271742 // set to null to indicate that we've chosen an opponent, but because
@@ -1735,30 +1750,32 @@ export class MatrixCall extends EventEmitter {
17351750 }
17361751 this . opponentCaps = msg . capabilities || { } ;
17371752 this . opponentMember = ev . sender ;
1753+ }
17381754
1755+ private async addBufferedIceCandidates ( ) {
17391756 const bufferedCands = this . remoteCandidateBuffer . get ( this . opponentPartyId ) ;
17401757 if ( bufferedCands ) {
17411758 logger . info ( `Adding ${ bufferedCands . length } buffered candidates for opponent ${ this . opponentPartyId } ` ) ;
1742- this . addIceCandidates ( bufferedCands ) ;
1759+ await this . addIceCandidates ( bufferedCands ) ;
17431760 }
17441761 this . remoteCandidateBuffer = null ;
17451762 }
17461763
1747- private addIceCandidates ( cands : RTCIceCandidate [ ] ) {
1764+ private async addIceCandidates ( cands : RTCIceCandidate [ ] ) {
17481765 for ( const cand of cands ) {
17491766 if (
17501767 ( cand . sdpMid === null || cand . sdpMid === undefined ) &&
17511768 ( cand . sdpMLineIndex === null || cand . sdpMLineIndex === undefined )
17521769 ) {
17531770 logger . debug ( "Ignoring remote ICE candidate with no sdpMid or sdpMLineIndex" ) ;
1754- return ;
1771+ continue ;
17551772 }
1756- logger . debug ( "Got remote ICE " + cand . sdpMid + " candidate: " + cand . candidate ) ;
1773+ logger . debug ( "Call " + this . callId + " got remote ICE " + cand . sdpMid + " candidate: " + cand . candidate ) ;
17571774 try {
1758- this . peerConn . addIceCandidate ( cand ) ;
1775+ await this . peerConn . addIceCandidate ( cand ) ;
17591776 } catch ( err ) {
17601777 if ( ! this . ignoreOffer ) {
1761- logger . info ( "Failed to add remore ICE candidate" , err ) ;
1778+ logger . info ( "Failed to add remote ICE candidate" , err ) ;
17621779 }
17631780 }
17641781 }
0 commit comments