1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +03:00

Merge pull request #1652 from matrix-org/dbkr/attended_transfer

Attended transfer
This commit is contained in:
David Baker
2021-04-01 17:34:18 +01:00
committed by GitHub
2 changed files with 47 additions and 3 deletions

View File

@@ -1527,7 +1527,10 @@ export class MatrixCall extends EventEmitter {
}
}
async transfer(targetUserId: string, targetRoomId?: string) {
/*
* Transfers this call to another user
*/
async transfer(targetUserId: string) {
// Fetch the target user's global profile info: their room avatar / displayname
// could be different in whatever room we shae with them.
const profileInfo = await this.client.getProfileInfo(targetUserId);
@@ -1544,9 +1547,49 @@ export class MatrixCall extends EventEmitter {
create_call: replacementId,
} as MCallReplacesEvent;
if (targetRoomId) body.target_room = targetRoomId;
await this.sendVoipEvent(EventType.CallReplaces, body);
return this.sendVoipEvent(EventType.CallReplaces, body);
await this.terminate(CallParty.Local, CallErrorCode.Replaced, true);
}
/*
* Transfers this call to the target call, effectively 'joining' the
* two calls (so the remote parties on each call are connected together).
*/
async transferToCall(transferTargetCall?: MatrixCall) {
const targetProfileInfo = await this.client.getProfileInfo(transferTargetCall.getOpponentMember().userId);
const transfereeProfileInfo = await this.client.getProfileInfo(this.getOpponentMember().userId);
const newCallId = genCallID();
const bodyToTransferTarget = {
// the replacements on each side have their own ID, and it's distinct from the
// ID of the new call (but we can use the same function to generate it)
replacement_id: genCallID(),
target_user: {
id: this.getOpponentMember().userId,
display_name: transfereeProfileInfo.display_name,
avatar_url: transfereeProfileInfo.avatar_url,
},
await_call: newCallId,
} as MCallReplacesEvent;
await transferTargetCall.sendVoipEvent(EventType.CallReplaces, bodyToTransferTarget);
const bodyToTransferee = {
replacement_id: genCallID(),
target_user: {
id: transferTargetCall.getOpponentMember().userId,
display_name: targetProfileInfo.display_name,
avatar_url: targetProfileInfo.avatar_url,
},
create_call: newCallId,
} as MCallReplacesEvent;
await this.sendVoipEvent(EventType.CallReplaces, bodyToTransferee);
await this.terminate(CallParty.Local, CallErrorCode.Replaced, true);
await transferTargetCall.terminate(CallParty.Local, CallErrorCode.Replaced, true);
}
private async terminate(hangupParty: CallParty, hangupReason: CallErrorCode, shouldEmit: boolean) {