-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Expand file tree
/
Copy pathMediaCallHistoryExternal.tsx
More file actions
51 lines (43 loc) · 1.55 KB
/
MediaCallHistoryExternal.tsx
File metadata and controls
51 lines (43 loc) · 1.55 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import type { CallHistoryItem, IExternalMediaCallHistoryItem, IMediaCall, Serialized } from '@rocket.chat/core-typings';
import { CallHistoryContextualBar, useWidgetExternalControls, usePeekMediaSessionState } from '@rocket.chat/ui-voip';
import { useMemo } from 'react';
type ExternalCallEndpointData = Serialized<{
item: IExternalMediaCallHistoryItem;
call: IMediaCall;
}>;
type MediaCallHistoryExternalProps = {
data: ExternalCallEndpointData;
onClose: () => void;
};
const getContact = (item: ExternalCallEndpointData['item']) => {
return {
number: item.contactExtension,
};
};
export const isExternalCallHistoryItem = (data: { item: Serialized<CallHistoryItem> }): data is ExternalCallEndpointData => {
return 'external' in data.item && data.item.external;
};
const MediaCallHistoryExternal = ({ data, onClose }: MediaCallHistoryExternalProps) => {
const contact = useMemo(() => getContact(data.item), [data]);
const historyData = useMemo(() => {
return {
callId: data.call._id,
direction: data.item.direction,
duration: data.item.duration,
startedAt: new Date(data.item.ts),
state: data.item.state,
};
}, [data]);
const state = usePeekMediaSessionState();
const { toggleWidget } = useWidgetExternalControls();
const actions = useMemo(() => {
if (state !== 'available') {
return {};
}
return {
voiceCall: () => toggleWidget(contact),
};
}, [contact, state, toggleWidget]);
return <CallHistoryContextualBar onClose={onClose} actions={actions} contact={contact} data={historyData} />;
};
export default MediaCallHistoryExternal;