Skip to content

Commit 20490af

Browse files
authored
fix: Filter out current peer and users without extension when sip is forced (#37320)
1 parent a3c22ff commit 20490af

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

.changeset/great-apes-pay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@rocket.chat/ui-voip": patch
3+
---
4+
5+
Fixes an issue in the voice call peer selection field (on the widget and transfer modal) by filtering out the current peer and users that do not have an extension assigned, in case of forced SIP routing.

packages/ui-voip/src/v2/MediaCallProvider.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
useSetModal,
1010
useSelectedDevices,
1111
useToastMessageDispatch,
12+
useSetting,
1213
} from '@rocket.chat/ui-contexts';
1314
import { useCallback, useEffect } from 'react';
1415
import { createPortal } from 'react-dom';
@@ -18,7 +19,7 @@ import MediaCallContext, { PeerInfo } from './MediaCallContext';
1819
import MediaCallWidget from './MediaCallWidget';
1920
import TransferModal from './TransferModal';
2021
import { useCallSounds } from './useCallSounds';
21-
import { useMediaSession } from './useMediaSession';
22+
import { getExtensionFromPeerInfo, useMediaSession } from './useMediaSession';
2223
import { useMediaSessionInstance } from './useMediaSessionInstance';
2324
import useMediaStream from './useMediaStream';
2425
import { isValidTone, useTonePlayer } from './useTonePlayer';
@@ -45,6 +46,8 @@ const MediaCallProvider = ({ children }: { children: React.ReactNode }) => {
4546

4647
const requestDevice = useDevicePermissionPrompt2();
4748

49+
const forceSIPRouting = useSetting('VoIP_TeamCollab_SIP_Integration_For_Internal_Calls');
50+
4851
// For some reason `exhaustive-deps` is complaining that "session" is not in the dependencies
4952
// But we're only using the changeDevice method from the session
5053
// So I'll just destructure it here
@@ -202,10 +205,22 @@ const MediaCallProvider = ({ children }: { children: React.ReactNode }) => {
202205

203206
const getAutocompleteOptions = async (filter: string) => {
204207
const peerUsername = session.peerInfo && 'username' in session.peerInfo ? session.peerInfo.username : undefined;
208+
const peerExtension = session.peerInfo ? getExtensionFromPeerInfo(session.peerInfo) : undefined;
209+
210+
const conditions =
211+
peerExtension || forceSIPRouting
212+
? {
213+
$and: [
214+
forceSIPRouting && { freeSwitchExtension: { $exists: true } },
215+
peerExtension && { freeSwitchExtension: { $ne: peerExtension } },
216+
].filter(Boolean),
217+
}
218+
: undefined;
219+
205220
const exceptions = [user?.username, peerUsername].filter(Boolean);
206221

207222
const { items } = await usersAutoCompleteEndpoint({
208-
selector: JSON.stringify({ term: filter, exceptions }),
223+
selector: JSON.stringify({ term: filter, exceptions, ...(conditions && { conditions }) }),
209224
});
210225
return (
211226
items.map((user) => {

packages/ui-voip/src/v2/useMediaSession.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ type MediaSession = SessionInfo & {
3434
sendTone: (tone: string) => void;
3535
};
3636

37+
export const getExtensionFromPeerInfo = (peerInfo: PeerInfo): string | undefined => {
38+
if ('callerId' in peerInfo) {
39+
return peerInfo.callerId;
40+
}
41+
42+
if ('number' in peerInfo) {
43+
return peerInfo.number;
44+
}
45+
46+
return undefined;
47+
};
48+
3749
const deriveWidgetStateFromCallState = (callState: CallState, callRole: CallRole): State | undefined => {
3850
switch (callState) {
3951
case 'active':

0 commit comments

Comments
 (0)