diff --git a/app/custom-sounds/client/lib/CustomSounds.js b/app/custom-sounds/client/lib/CustomSounds.js index 7cea36be304..07c83303cb3 100644 --- a/app/custom-sounds/client/lib/CustomSounds.js +++ b/app/custom-sounds/client/lib/CustomSounds.js @@ -33,6 +33,12 @@ class CustomSoundsClass { extension: 'mp3', src: getURL('sounds/seasons.mp3'), }); + this.add({ + _id: 'telephone', + name: 'Telephone', + extension: 'mp3', + src: getURL('sounds/telephone.mp3'), + }); } add(sound) { diff --git a/client/providers/CallProvider/CallProvider.tsx b/client/providers/CallProvider/CallProvider.tsx index 3fe8ed24c6f..349bca3825b 100644 --- a/client/providers/CallProvider/CallProvider.tsx +++ b/client/providers/CallProvider/CallProvider.tsx @@ -3,8 +3,11 @@ import React, { useMemo, FC, useRef, useCallback, useEffect, useState } from 're import { createPortal } from 'react-dom'; import { OutgoingByeRequest } from 'sip.js/lib/core'; +import { CustomSounds } from '../../../app/custom-sounds/client'; import { Notifications } from '../../../app/notifications/client'; +import { getUserPreference } from '../../../app/utils/client'; import { IVoipRoom } from '../../../definition/IRoom'; +import { IUser } from '../../../definition/IUser'; import { WrapUpCallModal } from '../../components/voip/modal/WrapUpCallModal'; import { CallContext, CallContextValue } from '../../contexts/CallContext'; import { useSetModal } from '../../contexts/ModalContext'; @@ -16,6 +19,19 @@ import { useUser } from '../../contexts/UserContext'; import { roomCoordinator } from '../../lib/rooms/roomCoordinator'; import { isUseVoipClientResultError, isUseVoipClientResultLoading, useVoipClient } from './hooks/useVoipClient'; +const startRingback = (user: IUser): void => { + const audioVolume = getUserPreference(user, 'notificationsSoundVolume'); + CustomSounds.play('telephone', { + volume: Number((audioVolume / 100).toPrecision(2)), + loop: true, + }); +}; + +const stopRingback = (): void => { + CustomSounds.pause('telephone'); + CustomSounds.remove('telephone'); +}; + export const CallProvider: FC = ({ children }) => { const voipEnabled = useSetting('VoIP_Enabled'); @@ -181,6 +197,10 @@ export const CallProvider: FC = ({ children }) => { const { registrationInfo, voipClient } = result; + voipClient.on('incomingcall', () => user && startRingback(user)); + voipClient.on('callestablished', () => stopRingback()); + voipClient.on('callterminated', () => stopRingback()); + return { enabled: true, ready: true, diff --git a/public/sounds/telephone.mp3 b/public/sounds/telephone.mp3 new file mode 100644 index 00000000000..61deeaf40b3 Binary files /dev/null and b/public/sounds/telephone.mp3 differ