Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/great-apes-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/ui-voip": patch
---

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.
19 changes: 17 additions & 2 deletions packages/ui-voip/src/v2/MediaCallProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
useSetModal,
useSelectedDevices,
useToastMessageDispatch,
useSetting,
} from '@rocket.chat/ui-contexts';
import { useCallback, useEffect } from 'react';
import { createPortal } from 'react-dom';
Expand All @@ -18,7 +19,7 @@ import MediaCallContext, { PeerInfo } from './MediaCallContext';
import MediaCallWidget from './MediaCallWidget';
import TransferModal from './TransferModal';
import { useCallSounds } from './useCallSounds';
import { useMediaSession } from './useMediaSession';
import { getExtensionFromPeerInfo, useMediaSession } from './useMediaSession';
import { useMediaSessionInstance } from './useMediaSessionInstance';
import useMediaStream from './useMediaStream';
import { isValidTone, useTonePlayer } from './useTonePlayer';
Expand All @@ -45,6 +46,8 @@ const MediaCallProvider = ({ children }: { children: React.ReactNode }) => {

const requestDevice = useDevicePermissionPrompt2();

const forceSIPRouting = useSetting('VoIP_TeamCollab_SIP_Integration_For_Internal_Calls');

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

const getAutocompleteOptions = async (filter: string) => {
const peerUsername = session.peerInfo && 'username' in session.peerInfo ? session.peerInfo.username : undefined;
const peerExtension = session.peerInfo ? getExtensionFromPeerInfo(session.peerInfo) : undefined;

const conditions =
peerExtension || forceSIPRouting
? {
$and: [
forceSIPRouting && { freeSwitchExtension: { $exists: true } },
peerExtension && { freeSwitchExtension: { $ne: peerExtension } },
].filter(Boolean),
}
: undefined;

const exceptions = [user?.username, peerUsername].filter(Boolean);

const { items } = await usersAutoCompleteEndpoint({
selector: JSON.stringify({ term: filter, exceptions }),
selector: JSON.stringify({ term: filter, exceptions, ...(conditions && { conditions }) }),
});
return (
items.map((user) => {
Expand Down
12 changes: 12 additions & 0 deletions packages/ui-voip/src/v2/useMediaSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ type MediaSession = SessionInfo & {
sendTone: (tone: string) => void;
};

export const getExtensionFromPeerInfo = (peerInfo: PeerInfo): string | undefined => {
if ('callerId' in peerInfo) {
return peerInfo.callerId;
}

if ('number' in peerInfo) {
return peerInfo.number;
}

return undefined;
};

const deriveWidgetStateFromCallState = (callState: CallState, callRole: CallRole): State | undefined => {
switch (callState) {
case 'active':
Expand Down
Loading