Skip to content

Commit 40e68e5

Browse files
chore: send to client the contact info of who requested a call transfer. (RocketChat#37150)
1 parent 6d605e6 commit 40e68e5

6 files changed

Lines changed: 46 additions & 0 deletions

File tree

ee/packages/media-calls/src/internal/SignalProcessor.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type { InternalCallParams } from '../definition/common';
1414
import { logger } from '../logger';
1515
import { mediaCallDirector } from '../server/CallDirector';
1616
import { UserActorAgent } from './agents/UserActorAgent';
17+
import { getNewCallTransferredBy } from '../server/getNewCallTransferredBy';
1718
import { stripSensitiveDataFromSignal } from '../server/stripSensitiveData';
1819

1920
export type SignalProcessorEvents = {
@@ -143,6 +144,8 @@ export class GlobalSignalProcessor {
143144
await mediaCallDirector.renewCallId(call._id);
144145
}
145146

147+
const transferredBy = getNewCallTransferredBy(call);
148+
146149
if (isCaller) {
147150
this.sendSignal(uid, {
148151
callId: call._id,
@@ -157,6 +160,8 @@ export class GlobalSignalProcessor {
157160
...call.callee,
158161
},
159162
...(call.callerRequestedId && { requestedCallId: call.callerRequestedId }),
163+
...(call.parentCallId && { replacingCallId: call.parentCallId }),
164+
...(transferredBy && { transferredBy }),
160165
});
161166
}
162167

@@ -173,6 +178,8 @@ export class GlobalSignalProcessor {
173178
contact: {
174179
...call.caller,
175180
},
181+
...(call.parentCallId && { replacingCallId: call.parentCallId }),
182+
...(transferredBy && { transferredBy }),
176183
});
177184
}
178185

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

278+
const transferredBy = getNewCallTransferredBy(call);
279+
271280
this.sendSignal(uid, {
272281
callId: call._id,
273282
type: 'new',
@@ -281,6 +290,8 @@ export class GlobalSignalProcessor {
281290
...call.callee,
282291
},
283292
requestedCallId: signal.callId,
293+
...(call.parentCallId && { replacingCallId: call.parentCallId }),
294+
...(transferredBy && { transferredBy }),
284295
});
285296

286297
return call;

ee/packages/media-calls/src/internal/agents/UserActorAgent.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { MediaCallNegotiations, MediaCalls } from '@rocket.chat/models';
55
import { UserActorSignalProcessor } from './CallSignalProcessor';
66
import { BaseMediaCallAgent } from '../../base/BaseAgent';
77
import { logger } from '../../logger';
8+
import { getNewCallTransferredBy } from '../../server/getNewCallTransferredBy';
89
import { getMediaCallServer } from '../../server/injection';
910

1011
export class UserActorAgent extends BaseMediaCallAgent {
@@ -167,6 +168,8 @@ export class UserActorAgent extends BaseMediaCallAgent {
167168
}
168169

169170
protected buildNewCallSignal(call: IMediaCall): ServerMediaSignalNewCall {
171+
const transferredBy = getNewCallTransferredBy(call);
172+
170173
return {
171174
callId: call._id,
172175
type: 'new',
@@ -176,6 +179,7 @@ export class UserActorAgent extends BaseMediaCallAgent {
176179
self: this.getMyCallActor(call),
177180
contact: this.getOtherCallActor(call),
178181
...(call.parentCallId && { replacingCallId: call.parentCallId }),
182+
...(transferredBy && { transferredBy }),
179183
...(call.callerRequestedId && this.role === 'caller' && { requestedCallId: call.callerRequestedId }),
180184
};
181185
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { IMediaCall } from '@rocket.chat/core-typings';
2+
import type { CallContact } from '@rocket.chat/media-signaling';
3+
4+
export function getNewCallTransferredBy(call: IMediaCall): CallContact | null {
5+
const { createdBy, parentCallId, caller, callee } = call;
6+
7+
if (!createdBy || !parentCallId) {
8+
return null;
9+
}
10+
11+
if (createdBy.type === caller.type && createdBy.id === caller.id) {
12+
return null;
13+
}
14+
15+
if (createdBy.type === callee.type && createdBy.id === callee.id) {
16+
return null;
17+
}
18+
19+
return createdBy;
20+
}

packages/media-signaling/src/definition/call/IClientMediaCall.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export interface IClientMediaCall {
7777
busy: boolean;
7878

7979
contact: CallContact;
80+
transferredBy: CallContact | null;
8081
audioLevel: number;
8182
localAudioLevel: number;
8283

packages/media-signaling/src/definition/signals/server/new.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ export type ServerMediaSignalNewCall = {
1515
requestedCallId?: string;
1616
/** If this new call initiated from a transfer, this will hold the id of the call that was transferred */
1717
replacingCallId?: string;
18+
/** If this new call initiated from a transfer, this will hold the information of the user who requested the transfer */
19+
transferredBy?: CallContact;
1820
};

packages/media-signaling/src/lib/Call.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ export class ClientMediaCall implements IClientMediaCall {
7878
return this._contact || {};
7979
}
8080

81+
private _transferredBy: CallContact | null;
82+
83+
public get transferredBy(): CallContact | null {
84+
return this._transferredBy;
85+
}
86+
8187
private _service: CallService | null;
8288

8389
public get service(): CallService | null {
@@ -200,6 +206,7 @@ export class ClientMediaCall implements IClientMediaCall {
200206
this.oldClientState = 'none';
201207
this._ignored = false;
202208
this._contact = null;
209+
this._transferredBy = null;
203210
this._service = null;
204211
}
205212

@@ -263,6 +270,7 @@ export class ClientMediaCall implements IClientMediaCall {
263270
this._service = signal.service;
264271
this._role = signal.role;
265272

273+
this._transferredBy = signal.transferredBy || null;
266274
this.changeContact(signal.contact);
267275

268276
if (this._role === 'caller' && !this.acceptedLocally) {

0 commit comments

Comments
 (0)