-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: VoIP freeswitch UI start call actions (#33008)
* feat: added options to useUserInfoQuery * feat: added freeSwitchExtension to full user data * feat: added freeSwitchExtension to /v1/im.members * feat: implemented enable/disable voice call menu item * feat: implemented start call menu into the room toolbox * feat: start call actions for user/members contextual bars and user card * feat: added enable/disable voice call button to NavBarV2 * feat: added dialer button to NavBarV2 * feat: made dialer button primary only if Omnichannel's voip is enabled * feat: adjusted call toolbox action to be more compatible * test: adjusted channel and video conf e2e tests to account for the new call menu * fix: start call menu action not acepting className * feat: improved error feedback * Use 'view-user-voip-extension' permission to decide if extension should be loaded * fix: passing incorrect ref * fix: adjusted dialer error feedback * refactor: renamed voice call with voip * refactor: removed iconOnly prop and kept same behavior with logic * refactor: reduced the use of useMemo in the useVideoConfMenuOptions hook * Use `AnchorPortal` --------- Co-authored-by: Pierre <pierre.lehnen@rocket.chat> Co-authored-by: Tasso <tasso.evangelista@rocket.chat>
- Loading branch information
1 parent
c81fc2f
commit 175b2b8
Showing
42 changed files
with
593 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
apps/meteor/client/NavBarV2/NavBarSettingsToolbar/UserMenu/hooks/useVoipItems.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Box } from '@rocket.chat/fuselage'; | ||
import type { GenericMenuItemProps } from '@rocket.chat/ui-client'; | ||
import { useToastMessageDispatch } from '@rocket.chat/ui-contexts'; | ||
import { useVoipAPI, useVoipState } from '@rocket.chat/ui-voip'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import React, { useMemo } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
export const useVoipItems = (): GenericMenuItemProps[] => { | ||
const { t } = useTranslation(); | ||
const dispatchToastMessage = useToastMessageDispatch(); | ||
|
||
const { clientError, isEnabled, isReady, isRegistered } = useVoipState(); | ||
const { register, unregister } = useVoipAPI(); | ||
|
||
const toggleVoip = useMutation({ | ||
mutationFn: async () => { | ||
if (!isRegistered) { | ||
await register(); | ||
return true; | ||
} | ||
|
||
await unregister(); | ||
return false; | ||
}, | ||
onSuccess: (isEnabled: boolean) => { | ||
dispatchToastMessage({ | ||
type: 'success', | ||
message: isEnabled ? t('Voice_calling_enabled') : t('Voice_calling_disabled'), | ||
}); | ||
}, | ||
}); | ||
|
||
const tooltip = useMemo(() => { | ||
if (clientError) { | ||
return t(clientError.message); | ||
} | ||
|
||
if (!isReady || toggleVoip.isLoading) { | ||
return t('Loading'); | ||
} | ||
|
||
return ''; | ||
}, [clientError, isReady, toggleVoip.isLoading, t]); | ||
|
||
return useMemo(() => { | ||
if (!isEnabled) { | ||
return []; | ||
} | ||
|
||
return [ | ||
{ | ||
id: 'toggle-voip', | ||
icon: isRegistered ? 'phone-disabled' : 'phone', | ||
disabled: !isReady || toggleVoip.isLoading, | ||
onClick: () => toggleVoip.mutate(), | ||
content: ( | ||
<Box is='span' title={tooltip}> | ||
{isRegistered ? t('Disable_voice_calling') : t('Enable_voice_calling')} | ||
</Box> | ||
), | ||
}, | ||
]; | ||
}, [isEnabled, isRegistered, isReady, tooltip, t, toggleVoip]); | ||
}; | ||
|
||
export default useVoipItems; |
48 changes: 48 additions & 0 deletions
48
apps/meteor/client/NavBarV2/NavBarVoipToolbar/NavBarItemVoipDialer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { NavBarItem } from '@rocket.chat/fuselage'; | ||
import { useEffectEvent } from '@rocket.chat/fuselage-hooks'; | ||
import { useLayout } from '@rocket.chat/ui-contexts'; | ||
import { useVoipDialer, useVoipState } from '@rocket.chat/ui-voip'; | ||
import type { HTMLAttributes } from 'react'; | ||
import React, { useMemo } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
type NavBarItemVoipDialerProps = Omit<HTMLAttributes<HTMLElement>, 'is'> & { | ||
primary?: boolean; | ||
}; | ||
|
||
const NavBarItemVoipDialer = (props: NavBarItemVoipDialerProps) => { | ||
const { t } = useTranslation(); | ||
const { sidebar } = useLayout(); | ||
const { clientError, isEnabled, isReady, isRegistered } = useVoipState(); | ||
const { open: isDialerOpen, openDialer, closeDialer } = useVoipDialer(); | ||
|
||
const handleToggleDialer = useEffectEvent(() => { | ||
sidebar.toggle(); | ||
isDialerOpen ? closeDialer() : openDialer(); | ||
}); | ||
|
||
const title = useMemo(() => { | ||
if (!isReady && !clientError) { | ||
return t('Loading'); | ||
} | ||
|
||
if (!isRegistered || clientError) { | ||
return t('Voice_calling_disabled'); | ||
} | ||
|
||
return t('New_Call'); | ||
}, [clientError, isReady, isRegistered, t]); | ||
|
||
return isEnabled ? ( | ||
<NavBarItem | ||
{...props} | ||
title={title} | ||
icon='phone' | ||
onClick={handleToggleDialer} | ||
pressed={isDialerOpen} | ||
disabled={!isReady || !isRegistered} | ||
/> | ||
) : null; | ||
}; | ||
|
||
export default NavBarItemVoipDialer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as NavBarItemVoipDialer } from './NavBarItemVoipDialer'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
apps/meteor/client/hooks/roomActions/useStartCallRoomAction/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './useStartCallRoomAction'; |
41 changes: 41 additions & 0 deletions
41
apps/meteor/client/hooks/roomActions/useStartCallRoomAction/useStartCallRoomAction.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { GenericMenu } from '@rocket.chat/ui-client'; | ||
import React, { useMemo } from 'react'; | ||
|
||
import HeaderToolbarAction from '../../../components/Header/HeaderToolbarAction'; | ||
import type { RoomToolboxActionConfig } from '../../../views/room/contexts/RoomToolboxContext'; | ||
import useVideoConfMenuOptions from './useVideoConfMenuOptions'; | ||
import useVoipMenuOptions from './useVoipMenuOptions'; | ||
|
||
export const useStartCallRoomAction = () => { | ||
const voipCall = useVideoConfMenuOptions(); | ||
const videoCall = useVoipMenuOptions(); | ||
|
||
return useMemo((): RoomToolboxActionConfig | undefined => { | ||
if (!videoCall.allowed && !voipCall.allowed) { | ||
return undefined; | ||
} | ||
|
||
return { | ||
id: 'start-call', | ||
title: 'Call', | ||
icon: 'phone', | ||
groups: [...videoCall.groups, ...voipCall.groups], | ||
disabled: videoCall.disabled && voipCall.disabled, | ||
full: true, | ||
order: Math.max(voipCall.order, videoCall.order), | ||
featured: true, | ||
renderToolboxItem: ({ id, icon, title, disabled, className }) => ( | ||
<GenericMenu | ||
button={<HeaderToolbarAction />} | ||
key={id} | ||
title={title} | ||
disabled={disabled} | ||
items={[...voipCall.items, ...videoCall.items]} | ||
className={className} | ||
placement='bottom-start' | ||
icon={icon} | ||
/> | ||
), | ||
}; | ||
}, [videoCall, voipCall]); | ||
}; |
Oops, something went wrong.