@@ -47,6 +47,7 @@ import { CallFeed } from './callFeed';
4747import { MatrixClient } from "../client" ;
4848import { ISendEventResponse } from "../@types/requests" ;
4949import { EventEmitterEvents , TypedEventEmitter } from "../models/typed-event-emitter" ;
50+ import { DeviceInfo } from '../crypto/deviceinfo' ;
5051
5152// events: hangup, error(err), replaced(call), state(state, oldState)
5253
@@ -343,6 +344,7 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
343344 private callLength = 0 ;
344345
345346 private opponentDeviceId : string ;
347+ private opponentDeviceInfo : DeviceInfo ;
346348 private opponentSessionId : string ;
347349 public groupCallId : string ;
348350
@@ -508,6 +510,17 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
508510 return this . feeds . filter ( ( feed ) => ! feed . isLocal ( ) ) ;
509511 }
510512
513+ private async initOpponentCrypto ( ) {
514+ if ( ! this . opponentDeviceId ) return ;
515+
516+ const userId = this . invitee || this . getOpponentMember ( ) . userId ;
517+ const deviceInfoMap = await this . client . crypto . deviceList . downloadKeys ( [ userId ] , false ) ;
518+ this . opponentDeviceInfo = deviceInfoMap [ userId ] [ this . opponentDeviceId ] ;
519+ if ( this . opponentDeviceInfo === undefined ) {
520+ throw new Error ( `No keys found for opponent device ${ this . opponentDeviceId } !` ) ;
521+ }
522+ }
523+
511524 /**
512525 * Generates and returns localSDPStreamMetadata
513526 * @returns {SDPStreamMetadata } localSDPStreamMetadata
@@ -792,6 +805,7 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
792805 // handler will start giving us more call events (eg. candidates) so if
793806 // we haven't set the party ID, we'll ignore them.
794807 this . chooseOpponent ( event ) ;
808+ await this . initOpponentCrypto ( ) ;
795809 try {
796810 await this . peerConn . setRemoteDescription ( invite . offer ) ;
797811 await this . addBufferedIceCandidates ( ) ;
@@ -2052,9 +2066,10 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
20522066 } ,
20532067 } ;
20542068 const userId = this . invitee || this . getOpponentMember ( ) . userId ;
2055- const deviceInfoMap = await this . client . crypto . deviceList . downloadKeys ( [ userId ] , false ) ;
2056- const deviceInfo = deviceInfoMap [ userId ] [ this . opponentDeviceId ] ;
2057- return this . client . crypto . encryptAndSendToDevices ( [ { userId, deviceInfo } ] , payload ) ;
2069+ return this . client . crypto . encryptAndSendToDevices ( [ {
2070+ userId,
2071+ deviceInfo : this . opponentDeviceInfo ,
2072+ } ] , payload ) ;
20582073 } else {
20592074 this . emit ( CallEvent . SendVoipEvent , {
20602075 type : "sendEvent" ,
@@ -2351,6 +2366,8 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
23512366 this . checkForErrorListener ( ) ;
23522367 this . direction = CallDirection . Outbound ;
23532368
2369+ await this . initOpponentCrypto ( ) ;
2370+
23542371 // XXX Find a better way to do this
23552372 this . client . callEventHandler . calls . set ( this . callId , this ) ;
23562373
0 commit comments