-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Expand file tree
/
Copy pathMediaCallProvider.tsx
More file actions
34 lines (27 loc) · 1.2 KB
/
MediaCallProvider.tsx
File metadata and controls
34 lines (27 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { Emitter } from '@rocket.chat/emitter';
import { usePermission } from '@rocket.chat/ui-contexts';
import { MediaCallProvider as MediaCallProviderBase, MediaCallInstanceContext } from '@rocket.chat/ui-voip';
import type { ReactNode } from 'react';
import { useMemo } from 'react';
import { useHasLicenseModule } from '../hooks/useHasLicenseModule';
const MediaCallProvider = ({ children }: { children: ReactNode }) => {
const canMakeInternalCall = usePermission('allow-internal-voice-calls');
const canMakeExternalCall = usePermission('allow-external-voice-calls');
const { data: hasModule = false } = useHasLicenseModule('teams-voip');
const unauthorizedContextValue = useMemo(
() => ({
instance: undefined,
signalEmitter: new Emitter<any>(),
audioElement: undefined,
openRoomId: undefined,
setOpenRoomId: () => undefined,
getAutocompleteOptions: () => Promise.resolve([]),
}),
[],
);
if (!hasModule || (!canMakeInternalCall && !canMakeExternalCall)) {
return <MediaCallInstanceContext.Provider value={unauthorizedContextValue}>{children}</MediaCallInstanceContext.Provider>;
}
return <MediaCallProviderBase>{children}</MediaCallProviderBase>;
};
export default MediaCallProvider;