Skip to content
11 changes: 11 additions & 0 deletions ee/packages/media-calls/src/internal/SignalProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { InternalCallParams } from '../definition/common';
import { logger } from '../logger';
import { mediaCallDirector } from '../server/CallDirector';
import { UserActorAgent } from './agents/UserActorAgent';
import { getNewCallTransferredBy } from '../server/getNewCallTransferredBy';
import { stripSensitiveDataFromSignal } from '../server/stripSensitiveData';

export type SignalProcessorEvents = {
Expand Down Expand Up @@ -143,6 +144,8 @@ export class GlobalSignalProcessor {
await mediaCallDirector.renewCallId(call._id);
}

const transferredBy = getNewCallTransferredBy(call);

if (isCaller) {
this.sendSignal(uid, {
callId: call._id,
Expand All @@ -157,6 +160,8 @@ export class GlobalSignalProcessor {
...call.callee,
},
...(call.callerRequestedId && { requestedCallId: call.callerRequestedId }),
...(call.parentCallId && { replacingCallId: call.parentCallId }),
...(transferredBy && { transferredBy }),
});
}

Expand All @@ -173,6 +178,8 @@ export class GlobalSignalProcessor {
contact: {
...call.caller,
},
...(call.parentCallId && { replacingCallId: call.parentCallId }),
...(transferredBy && { transferredBy }),
});
}

Expand Down Expand Up @@ -268,6 +275,8 @@ export class GlobalSignalProcessor {
this.rejectCallRequest(uid, { ...rejection, reason: 'already-requested' });
}

const transferredBy = getNewCallTransferredBy(call);

this.sendSignal(uid, {
callId: call._id,
type: 'new',
Expand All @@ -281,6 +290,8 @@ export class GlobalSignalProcessor {
...call.callee,
},
requestedCallId: signal.callId,
...(call.parentCallId && { replacingCallId: call.parentCallId }),
...(transferredBy && { transferredBy }),
});

return call;
Expand Down
4 changes: 4 additions & 0 deletions ee/packages/media-calls/src/internal/agents/UserActorAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MediaCallNegotiations, MediaCalls } from '@rocket.chat/models';
import { UserActorSignalProcessor } from './CallSignalProcessor';
import { BaseMediaCallAgent } from '../../base/BaseAgent';
import { logger } from '../../logger';
import { getNewCallTransferredBy } from '../../server/getNewCallTransferredBy';
import { getMediaCallServer } from '../../server/injection';

export class UserActorAgent extends BaseMediaCallAgent {
Expand Down Expand Up @@ -167,6 +168,8 @@ export class UserActorAgent extends BaseMediaCallAgent {
}

protected buildNewCallSignal(call: IMediaCall): ServerMediaSignalNewCall {
const transferredBy = getNewCallTransferredBy(call);

return {
callId: call._id,
type: 'new',
Expand All @@ -176,6 +179,7 @@ export class UserActorAgent extends BaseMediaCallAgent {
self: this.getMyCallActor(call),
contact: this.getOtherCallActor(call),
...(call.parentCallId && { replacingCallId: call.parentCallId }),
...(transferredBy && { transferredBy }),
...(call.callerRequestedId && this.role === 'caller' && { requestedCallId: call.callerRequestedId }),
};
}
Expand Down
20 changes: 20 additions & 0 deletions ee/packages/media-calls/src/server/getNewCallTransferredBy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { IMediaCall } from '@rocket.chat/core-typings';
import type { CallContact } from '@rocket.chat/media-signaling';

export function getNewCallTransferredBy(call: IMediaCall): CallContact | null {
const { createdBy, parentCallId, caller, callee } = call;

if (!createdBy || !parentCallId) {
return null;
}

if (createdBy.type === caller.type && createdBy.id === caller.id) {
return null;
}

if (createdBy.type === callee.type && createdBy.id === callee.id) {
return null;
}

return createdBy;
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export interface IClientMediaCall {
busy: boolean;

contact: CallContact;
transferredBy: CallContact | null;
audioLevel: number;
localAudioLevel: number;

Expand Down
2 changes: 2 additions & 0 deletions packages/media-signaling/src/definition/signals/server/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ export type ServerMediaSignalNewCall = {
requestedCallId?: string;
/** If this new call initiated from a transfer, this will hold the id of the call that was transferred */
replacingCallId?: string;
/** If this new call initiated from a transfer, this will hold the information of the user who requested the transfer */
transferredBy?: CallContact;
};
8 changes: 8 additions & 0 deletions packages/media-signaling/src/lib/Call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ export class ClientMediaCall implements IClientMediaCall {
return this._contact || {};
}

private _transferredBy: CallContact | null;

public get transferredBy(): CallContact | null {
return this._transferredBy;
}

private _service: CallService | null;

public get service(): CallService | null {
Expand Down Expand Up @@ -200,6 +206,7 @@ export class ClientMediaCall implements IClientMediaCall {
this.oldClientState = 'none';
this._ignored = false;
this._contact = null;
this._transferredBy = null;
this._service = null;
}

Expand Down Expand Up @@ -263,6 +270,7 @@ export class ClientMediaCall implements IClientMediaCall {
this._service = signal.service;
this._role = signal.role;

this._transferredBy = signal.transferredBy || null;
this.changeContact(signal.contact);

if (this._role === 'caller' && !this.acceptedLocally) {
Expand Down
Loading