@100mslive/roomkit-react 0.3.16-alpha.0 → 0.3.16-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{HLSView-P7GF2RAU.js → HLSView-ERPYXVOY.js} +2 -2
- package/dist/{HLSView-KOCGTP23.css → HLSView-T2PXKR6I.css} +3 -3
- package/dist/{HLSView-KOCGTP23.css.map → HLSView-T2PXKR6I.css.map} +1 -1
- package/dist/Prebuilt/components/Chat/ChatBody.d.ts +887 -0
- package/dist/Prebuilt/components/Chat/ChatFooter.d.ts +1 -1
- package/dist/Prebuilt/components/Chat/utils.d.ts +2 -0
- package/dist/Prebuilt/components/PIP/PIPChat.d.ts +2 -0
- package/dist/Prebuilt/components/PIP/PIPChatOption.d.ts +5 -0
- package/dist/Prebuilt/components/PIP/PIPProvider.d.ts +6 -0
- package/dist/Prebuilt/components/PIP/PIPWindow.d.ts +7 -0
- package/dist/Prebuilt/components/PIP/context.d.ts +8 -0
- package/dist/Prebuilt/components/PIP/usePIPChat.d.ts +5 -0
- package/dist/Prebuilt/components/PIP/usePIPWindow.d.ts +2 -0
- package/dist/{chunk-DDB4BLHX.js → chunk-NKC36NL4.js} +8303 -7932
- package/dist/chunk-NKC36NL4.js.map +7 -0
- package/dist/index.cjs.css +2 -2
- package/dist/index.cjs.css.map +1 -1
- package/dist/index.cjs.js +3906 -3478
- package/dist/index.cjs.js.map +4 -4
- package/dist/index.css +2 -2
- package/dist/index.css.map +1 -1
- package/dist/index.js +1 -1
- package/dist/meta.cjs.json +1786 -1434
- package/dist/meta.esbuild.json +2262 -1910
- package/package.json +8 -7
- package/src/Prebuilt/components/AudioVideoToggle.tsx +14 -7
- package/src/Prebuilt/components/Chat/ChatBody.tsx +4 -12
- package/src/Prebuilt/components/Chat/ChatFooter.tsx +2 -3
- package/src/Prebuilt/components/Chat/utils.ts +11 -0
- package/src/Prebuilt/components/MoreSettings/MoreSettings.tsx +4 -1
- package/src/Prebuilt/components/MoreSettings/SplitComponents/DesktopOptions.tsx +13 -5
- package/src/Prebuilt/components/PIP/PIPChat.tsx +225 -0
- package/src/Prebuilt/components/PIP/PIPChatOption.tsx +18 -0
- package/src/Prebuilt/components/PIP/PIPProvider.tsx +56 -0
- package/src/Prebuilt/components/PIP/PIPWindow.tsx +13 -0
- package/src/Prebuilt/components/PIP/context.ts +10 -0
- package/src/Prebuilt/components/PIP/usePIPChat.tsx +103 -0
- package/src/Prebuilt/components/PIP/usePIPWindow.tsx +12 -0
- package/dist/chunk-DDB4BLHX.js.map +0 -7
- /package/dist/{HLSView-P7GF2RAU.js.map → HLSView-ERPYXVOY.js.map} +0 -0
package/package.json
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
"prebuilt",
|
11
11
|
"roomkit"
|
12
12
|
],
|
13
|
-
"version": "0.3.16-alpha.
|
13
|
+
"version": "0.3.16-alpha.1",
|
14
14
|
"author": "100ms",
|
15
15
|
"license": "MIT",
|
16
16
|
"repository": {
|
@@ -75,12 +75,12 @@
|
|
75
75
|
"react": ">=17.0.2 <19.0.0"
|
76
76
|
},
|
77
77
|
"dependencies": {
|
78
|
-
"@100mslive/hls-player": "0.3.16-alpha.
|
78
|
+
"@100mslive/hls-player": "0.3.16-alpha.1",
|
79
79
|
"@100mslive/hms-noise-cancellation": "0.0.1",
|
80
|
-
"@100mslive/hms-virtual-background": "1.13.16-alpha.
|
81
|
-
"@100mslive/hms-whiteboard": "0.0.6-alpha.
|
82
|
-
"@100mslive/react-icons": "0.10.16-alpha.
|
83
|
-
"@100mslive/react-sdk": "0.10.16-alpha.
|
80
|
+
"@100mslive/hms-virtual-background": "1.13.16-alpha.1",
|
81
|
+
"@100mslive/hms-whiteboard": "0.0.6-alpha.1",
|
82
|
+
"@100mslive/react-icons": "0.10.16-alpha.1",
|
83
|
+
"@100mslive/react-sdk": "0.10.16-alpha.1",
|
84
84
|
"@100mslive/types-prebuilt": "0.12.9",
|
85
85
|
"@emoji-mart/data": "^1.0.6",
|
86
86
|
"@emoji-mart/react": "^1.0.1",
|
@@ -104,6 +104,7 @@
|
|
104
104
|
"eventemitter2": "^6.4.9",
|
105
105
|
"lodash.merge": "^4.6.2",
|
106
106
|
"qrcode.react": "^3.1.0",
|
107
|
+
"react-dom": "^18.2.0",
|
107
108
|
"react-draggable": "^4.4.5",
|
108
109
|
"react-intersection-observer": "^9.4.3",
|
109
110
|
"react-swipeable": "^7.0.1",
|
@@ -116,5 +117,5 @@
|
|
116
117
|
"uuid": "^8.3.2",
|
117
118
|
"worker-timers": "^7.0.40"
|
118
119
|
},
|
119
|
-
"gitHead": "
|
120
|
+
"gitHead": "2ae950c4b6a1aed199e246ce1b8f9d2c1c2ebe7c"
|
120
121
|
}
|
@@ -109,6 +109,9 @@ const useNoiseCancellationWithPlugin = () => {
|
|
109
109
|
if (inProgress) {
|
110
110
|
return;
|
111
111
|
}
|
112
|
+
if (!krispPlugin.checkSupport().isSupported) {
|
113
|
+
throw Error('Krisp plugin is not supported');
|
114
|
+
}
|
112
115
|
setInProgress(true);
|
113
116
|
if (enabled) {
|
114
117
|
await actions.addPluginToAudioTrack(krispPlugin);
|
@@ -281,13 +284,17 @@ export const AudioVideoToggle = ({ hideOptions = false }: { hideOptions?: boolea
|
|
281
284
|
useEffect(() => {
|
282
285
|
(async () => {
|
283
286
|
if (isNoiseCancellationEnabled && !isKrispPluginAdded && !inProgress && localPeer?.audioTrack) {
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
287
|
+
try {
|
288
|
+
await setNoiseCancellationWithPlugin(true);
|
289
|
+
ToastManager.addToast({
|
290
|
+
title: `Noise Reduction Enabled`,
|
291
|
+
variant: 'standard',
|
292
|
+
duration: 2000,
|
293
|
+
icon: <AudioLevelIcon />,
|
294
|
+
});
|
295
|
+
} catch (error) {
|
296
|
+
console.error(error);
|
297
|
+
}
|
291
298
|
}
|
292
299
|
})();
|
293
300
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
@@ -28,18 +28,9 @@ import { useRoomLayoutConferencingScreen } from '../../provider/roomLayoutProvid
|
|
28
28
|
// @ts-ignore: No implicit Any
|
29
29
|
import { useSetSubscribedChatSelector } from '../AppData/useUISettings';
|
30
30
|
import { usePinnedBy } from '../hooks/usePinnedBy';
|
31
|
+
import { formatTime } from './utils';
|
31
32
|
import { CHAT_SELECTOR, SESSION_STORE_KEY } from '../../common/constants';
|
32
33
|
|
33
|
-
const formatTime = (date: Date) => {
|
34
|
-
if (!(date instanceof Date)) {
|
35
|
-
return '';
|
36
|
-
}
|
37
|
-
const hours = date.getHours();
|
38
|
-
const minutes = date.getMinutes();
|
39
|
-
const suffix = hours > 11 ? 'PM' : 'AM';
|
40
|
-
return `${hours < 10 ? '0' : ''}${hours}:${minutes < 10 ? '0' : ''}${minutes} ${suffix}`;
|
41
|
-
};
|
42
|
-
|
43
34
|
const rowHeights: Record<number, { size: number; id: string }> = {};
|
44
35
|
let listInstance: VariableSizeList | null = null; //eslint-disable-line
|
45
36
|
function getRowHeight(index: number) {
|
@@ -109,7 +100,7 @@ const MessageTypeContainer = ({ left, right }: { left?: string; right?: string }
|
|
109
100
|
);
|
110
101
|
};
|
111
102
|
|
112
|
-
const MessageType = ({
|
103
|
+
export const MessageType = ({
|
113
104
|
roles,
|
114
105
|
hasCurrentUserSent,
|
115
106
|
receiver,
|
@@ -172,7 +163,8 @@ const getMessageType = ({ roles, receiver }: { roles?: HMSRoleName[]; receiver?:
|
|
172
163
|
}
|
173
164
|
return receiver ? 'private' : '';
|
174
165
|
};
|
175
|
-
|
166
|
+
|
167
|
+
export const SenderName = styled(Text, {
|
176
168
|
overflow: 'hidden',
|
177
169
|
textOverflow: 'ellipsis',
|
178
170
|
whiteSpace: 'nowrap',
|
@@ -20,10 +20,9 @@ import { useIsPeerBlacklisted } from '../hooks/useChatBlacklist';
|
|
20
20
|
// @ts-ignore: No implicit any
|
21
21
|
import { useEmojiPickerStyles } from './useEmojiPickerStyles';
|
22
22
|
import { useDefaultChatSelection, useLandscapeHLSStream, useMobileHLSStream } from '../../common/hooks';
|
23
|
+
import { CHAT_MESSAGE_LIMIT } from './utils';
|
23
24
|
import { CHAT_SELECTOR, SESSION_STORE_KEY } from '../../common/constants';
|
24
25
|
|
25
|
-
const CHAT_MESSAGE_LIMIT = 2000;
|
26
|
-
|
27
26
|
const TextArea = styled('textarea', {
|
28
27
|
width: '100%',
|
29
28
|
bg: 'transparent',
|
@@ -76,7 +75,7 @@ function EmojiPicker({ onSelect }: { onSelect: (emoji: any) => void }) {
|
|
76
75
|
);
|
77
76
|
}
|
78
77
|
|
79
|
-
export const ChatFooter = ({ onSend, children }: { onSend: (count: number) => void; children
|
78
|
+
export const ChatFooter = ({ onSend, children }: { onSend: (count: number) => void; children?: ReactNode }) => {
|
80
79
|
const hmsActions = useHMSActions();
|
81
80
|
const inputRef = useRef<HTMLTextAreaElement>(null);
|
82
81
|
const [draftMessage, setDraftMessage] = useChatDraftMessage();
|
@@ -0,0 +1,11 @@
|
|
1
|
+
export const formatTime = (date: Date) => {
|
2
|
+
if (!(date instanceof Date)) {
|
3
|
+
return '';
|
4
|
+
}
|
5
|
+
const hours = date.getHours();
|
6
|
+
const minutes = date.getMinutes();
|
7
|
+
const suffix = hours > 11 ? 'PM' : 'AM';
|
8
|
+
return `${hours < 10 ? '0' : ''}${hours}:${minutes < 10 ? '0' : ''}${minutes} ${suffix}`;
|
9
|
+
};
|
10
|
+
|
11
|
+
export const CHAT_MESSAGE_LIMIT = 2000;
|
@@ -10,6 +10,7 @@ import { DesktopOptions } from './SplitComponents/DesktopOptions';
|
|
10
10
|
// @ts-ignore: No implicit Any
|
11
11
|
import { MwebOptions } from './SplitComponents/MwebOptions';
|
12
12
|
import { config as cssConfig } from '../../..';
|
13
|
+
import { PIPProvider } from '../PIP/PIPProvider';
|
13
14
|
import { useLandscapeHLSStream } from '../../common/hooks';
|
14
15
|
|
15
16
|
export const MoreSettings = ({
|
@@ -24,6 +25,8 @@ export const MoreSettings = ({
|
|
24
25
|
return isMobile || isLandscapeHLSStream ? (
|
25
26
|
<MwebOptions elements={elements} screenType={screenType} />
|
26
27
|
) : (
|
27
|
-
<
|
28
|
+
<PIPProvider>
|
29
|
+
<DesktopOptions elements={elements} screenType={screenType} />
|
30
|
+
</PIPProvider>
|
28
31
|
);
|
29
32
|
};
|
@@ -28,8 +28,11 @@ import { Checkbox, Dropdown, Flex, Switch, Text, Tooltip } from '../../../..';
|
|
28
28
|
import IconButton from '../../../IconButton';
|
29
29
|
// @ts-ignore: No implicit any
|
30
30
|
import { PIP } from '../../PIP';
|
31
|
+
import { PIPChat } from '../../PIP/PIPChat';
|
31
32
|
// @ts-ignore: No implicit any
|
33
|
+
import { PIPChatOption } from '../../PIP/PIPChatOption';
|
32
34
|
import { PictureInPicture } from '../../PIP/PIPManager';
|
35
|
+
import { PIPWindow } from '../../PIP/PIPWindow';
|
33
36
|
// @ts-ignore: No implicit any
|
34
37
|
import { RoleChangeModal } from '../../RoleChangeModal';
|
35
38
|
// @ts-ignore: No implicit any
|
@@ -48,6 +51,8 @@ import { MuteAllModal } from '../MuteAllModal';
|
|
48
51
|
import { useDropdownList } from '../../hooks/useDropdownList';
|
49
52
|
import { useMyMetadata } from '../../hooks/useMetadata';
|
50
53
|
// @ts-ignore: No implicit any
|
54
|
+
import { usePIPChat } from '../../PIP/usePIPChat';
|
55
|
+
// @ts-ignore: No implicit any
|
51
56
|
import { APP_DATA, isMacOS } from '../../../common/constants';
|
52
57
|
|
53
58
|
const MODALS = {
|
@@ -79,6 +84,8 @@ export const DesktopOptions = ({
|
|
79
84
|
const isBRBEnabled = !!elements?.brb;
|
80
85
|
const isTranscriptionAllowed = useHMSStore(selectIsTranscriptionAllowedByMode(HMSTranscriptionMode.CAPTION));
|
81
86
|
const isTranscriptionEnabled = useHMSStore(selectIsTranscriptionEnabled);
|
87
|
+
const { isSupported, pipWindow, requestPipWindow } = usePIPChat();
|
88
|
+
const showPipChatOption = !!elements?.chat && isSupported;
|
82
89
|
|
83
90
|
useDropdownList({ open: openModals.size > 0, name: 'MoreSettings' });
|
84
91
|
|
@@ -98,6 +105,11 @@ export const DesktopOptions = ({
|
|
98
105
|
|
99
106
|
return (
|
100
107
|
<Fragment>
|
108
|
+
{isSupported && pipWindow ? (
|
109
|
+
<PIPWindow pipWindow={pipWindow}>
|
110
|
+
<PIPChat />
|
111
|
+
</PIPWindow>
|
112
|
+
) : null}
|
101
113
|
<Dropdown.Root
|
102
114
|
open={openModals.has(MODALS.MORE_SETTINGS)}
|
103
115
|
onOpenChange={value => updateState(MODALS.MORE_SETTINGS, value)}
|
@@ -168,13 +180,9 @@ export const DesktopOptions = ({
|
|
168
180
|
</Dropdown.Item>
|
169
181
|
) : null}
|
170
182
|
|
183
|
+
<PIPChatOption showPIPChat={showPipChatOption} openChat={async () => await requestPipWindow(350, 500)} />
|
171
184
|
<FullScreenItem />
|
172
|
-
{/* {isAllowedToPublish.screen && isEmbedEnabled && (
|
173
|
-
<EmbedUrl setShowOpenUrl={() => updateState(MODALS.EMBED_URL, true)} />
|
174
|
-
)} */}
|
175
|
-
|
176
185
|
<Dropdown.ItemSeparator css={{ mx: 0 }} />
|
177
|
-
|
178
186
|
<Dropdown.Item onClick={() => updateState(MODALS.DEVICE_SETTINGS, true)} data-testid="device_settings_btn">
|
179
187
|
<SettingsIcon />
|
180
188
|
<Text variant="sm" css={{ ml: '$4' }}>
|
@@ -0,0 +1,225 @@
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
2
|
+
import {
|
3
|
+
selectHMSMessages,
|
4
|
+
selectLocalPeerID,
|
5
|
+
selectSessionStore,
|
6
|
+
selectUnreadHMSMessagesCount,
|
7
|
+
useHMSStore,
|
8
|
+
} from '@100mslive/react-sdk';
|
9
|
+
import { SendIcon } from '@100mslive/react-icons';
|
10
|
+
import { Box, Flex } from '../../../Layout';
|
11
|
+
import { Text } from '../../../Text';
|
12
|
+
import { TextArea } from '../../../TextArea';
|
13
|
+
import { Tooltip } from '../../../Tooltip';
|
14
|
+
import IconButton from '../../IconButton';
|
15
|
+
import { AnnotisedMessage } from '../Chat/ChatBody';
|
16
|
+
import { useRoomLayoutConferencingScreen } from '../../provider/roomLayoutProvider/hooks/useRoomLayoutScreen';
|
17
|
+
import { CHAT_MESSAGE_LIMIT, formatTime } from '../Chat/utils';
|
18
|
+
import { SESSION_STORE_KEY } from '../../common/constants';
|
19
|
+
|
20
|
+
export const PIPChat = () => {
|
21
|
+
const messages = useHMSStore(selectHMSMessages);
|
22
|
+
const localPeerID = useHMSStore(selectLocalPeerID);
|
23
|
+
const count = useHMSStore(selectUnreadHMSMessagesCount);
|
24
|
+
const [unreadMessageCount, setUnreadMessageCount] = useState(0);
|
25
|
+
|
26
|
+
const getSenderName = useCallback(
|
27
|
+
(senderName: string, senderID?: string) => {
|
28
|
+
const slicedName = senderName.length > 10 ? senderName.slice(0, 10) + '...' : senderName;
|
29
|
+
return slicedName + (senderID === localPeerID ? ' (You)' : '');
|
30
|
+
},
|
31
|
+
[localPeerID],
|
32
|
+
);
|
33
|
+
|
34
|
+
useEffect(() => {
|
35
|
+
const timeoutId = setTimeout(() => {
|
36
|
+
setUnreadMessageCount(count);
|
37
|
+
}, 100);
|
38
|
+
return () => clearTimeout(timeoutId);
|
39
|
+
}, [count]);
|
40
|
+
|
41
|
+
const blacklistedMessageIDs = useHMSStore(selectSessionStore(SESSION_STORE_KEY.CHAT_MESSAGE_BLACKLIST));
|
42
|
+
const filteredMessages = useMemo(() => {
|
43
|
+
const blacklistedMessageIDSet = new Set(blacklistedMessageIDs || []);
|
44
|
+
return messages?.filter(message => message.type === 'chat' && !blacklistedMessageIDSet.has(message.id)) || [];
|
45
|
+
}, [blacklistedMessageIDs, messages]);
|
46
|
+
const { elements } = useRoomLayoutConferencingScreen();
|
47
|
+
const message_placeholder = elements?.chat?.message_placeholder || 'Send a message';
|
48
|
+
const canSendChatMessages = !!elements?.chat?.public_chat_enabled || !!elements?.chat?.roles_whitelist?.length;
|
49
|
+
|
50
|
+
return (
|
51
|
+
<div style={{ height: '100%' }}>
|
52
|
+
<Box
|
53
|
+
id="chat-container"
|
54
|
+
css={{
|
55
|
+
bg: '$surface_dim',
|
56
|
+
overflowY: 'auto',
|
57
|
+
// Subtracting height of footer
|
58
|
+
h: canSendChatMessages ? 'calc(100% - 90px)' : '100%',
|
59
|
+
position: 'relative',
|
60
|
+
}}
|
61
|
+
>
|
62
|
+
{unreadMessageCount ? (
|
63
|
+
<Box
|
64
|
+
id="new-message-notif"
|
65
|
+
style={{
|
66
|
+
position: 'fixed',
|
67
|
+
bottom: '76px',
|
68
|
+
right: '4px',
|
69
|
+
}}
|
70
|
+
>
|
71
|
+
<Text
|
72
|
+
variant="xs"
|
73
|
+
css={{ cursor: 'pointer' }}
|
74
|
+
style={{ color: 'white', background: 'gray', padding: '4px', borderRadius: '4px' }}
|
75
|
+
>
|
76
|
+
{unreadMessageCount === 1 ? 'New message' : `${unreadMessageCount} new messages`}
|
77
|
+
</Text>
|
78
|
+
</Box>
|
79
|
+
) : (
|
80
|
+
''
|
81
|
+
)}
|
82
|
+
{filteredMessages.length === 0 ? (
|
83
|
+
<div
|
84
|
+
style={{ display: 'flex', height: '100%', width: '100%', alignItems: 'center', justifyContent: 'center' }}
|
85
|
+
>
|
86
|
+
<Text>No messages here yet</Text>
|
87
|
+
</div>
|
88
|
+
) : (
|
89
|
+
filteredMessages.map(message => (
|
90
|
+
<Box className="pip-message" key={message.id} id={message.id} style={{ padding: '8px 0.75rem' }}>
|
91
|
+
<Flex style={{ width: '100%', alignItems: 'center', justifyContent: 'between' }}>
|
92
|
+
<Text
|
93
|
+
style={{ display: 'flex', justifyContent: 'between', width: '100%', alignItems: 'center' }}
|
94
|
+
css={{
|
95
|
+
color: '$on_surface_high',
|
96
|
+
fontWeight: '$semiBold',
|
97
|
+
}}
|
98
|
+
>
|
99
|
+
<Flex style={{ flexGrow: 1, gap: '2px', alignItems: 'center' }}>
|
100
|
+
{message.senderName === 'You' || !message.senderName ? (
|
101
|
+
<Text as="span" variant="sub2" css={{ color: '$on_surface_high', fontWeight: '$semiBold' }}>
|
102
|
+
{message.senderName || 'Anonymous'}
|
103
|
+
</Text>
|
104
|
+
) : (
|
105
|
+
<Tooltip title={message.senderName} side="top" align="start">
|
106
|
+
<Text as="span" variant="sub2" css={{ color: '$on_surface_high', fontWeight: '$semiBold' }}>
|
107
|
+
{getSenderName(message.senderName, message?.sender)}
|
108
|
+
</Text>
|
109
|
+
</Tooltip>
|
110
|
+
)}
|
111
|
+
{message.recipientRoles ? (
|
112
|
+
<Text as="span" variant="sub2" css={{ color: '$on_surface_high', fontWeight: '$semiBold' }}>
|
113
|
+
to {message.recipientRoles} (Group)
|
114
|
+
</Text>
|
115
|
+
) : null}
|
116
|
+
{message.recipientPeer ? (
|
117
|
+
<Text as="span" variant="sub2" css={{ color: '$on_surface_high', fontWeight: '$semiBold' }}>
|
118
|
+
(DM)
|
119
|
+
</Text>
|
120
|
+
) : null}
|
121
|
+
</Flex>
|
122
|
+
|
123
|
+
<Text
|
124
|
+
variant="xs"
|
125
|
+
css={{
|
126
|
+
color: '$on_surface_medium',
|
127
|
+
flexShrink: 0,
|
128
|
+
p: '$2',
|
129
|
+
whitespace: 'nowrap',
|
130
|
+
}}
|
131
|
+
>
|
132
|
+
{formatTime(message.time)}
|
133
|
+
</Text>
|
134
|
+
</Text>
|
135
|
+
</Flex>
|
136
|
+
<Text
|
137
|
+
variant="sm"
|
138
|
+
css={{
|
139
|
+
w: '100%',
|
140
|
+
mt: '$2',
|
141
|
+
wordBreak: 'break-word',
|
142
|
+
whiteSpace: 'pre-wrap',
|
143
|
+
userSelect: 'all',
|
144
|
+
color: '$on_surface_high',
|
145
|
+
}}
|
146
|
+
>
|
147
|
+
<AnnotisedMessage message={message.message} />
|
148
|
+
</Text>
|
149
|
+
</Box>
|
150
|
+
))
|
151
|
+
)}
|
152
|
+
<div id="marker" style={{ height: filteredMessages.length ? '1px' : 0 }} />
|
153
|
+
</Box>
|
154
|
+
{canSendChatMessages && (
|
155
|
+
<Box css={{ bg: '$surface_dim' }}>
|
156
|
+
<Flex css={{ px: '$4', pb: '3px', gap: '$2', alignItems: 'center' }}>
|
157
|
+
<Text variant="caption">To:</Text>
|
158
|
+
<Flex css={{ bg: '$primary_bright', color: '$on_primary_high', r: '$2' }}>
|
159
|
+
<select
|
160
|
+
id="selector"
|
161
|
+
style={{
|
162
|
+
background: 'inherit',
|
163
|
+
color: 'inherit',
|
164
|
+
border: 'none',
|
165
|
+
outline: 'none',
|
166
|
+
borderRadius: '4px',
|
167
|
+
padding: '0 2px',
|
168
|
+
}}
|
169
|
+
defaultValue={elements.chat?.public_chat_enabled ? 'Everyone' : elements.chat?.roles_whitelist?.[0]}
|
170
|
+
>
|
171
|
+
{elements.chat?.roles_whitelist?.map(role => (
|
172
|
+
<option key={role} value={role}>
|
173
|
+
{role}
|
174
|
+
</option>
|
175
|
+
))}
|
176
|
+
{elements.chat?.public_chat_enabled ? <option value="Everyone">Everyone</option> : ''}
|
177
|
+
</select>
|
178
|
+
</Flex>
|
179
|
+
</Flex>
|
180
|
+
<Flex
|
181
|
+
align="center"
|
182
|
+
css={{
|
183
|
+
bg: '$surface_default',
|
184
|
+
minHeight: '$16',
|
185
|
+
width: '100%',
|
186
|
+
py: '$6',
|
187
|
+
pl: '$4',
|
188
|
+
boxSizing: 'border-box',
|
189
|
+
gap: '$2',
|
190
|
+
r: '$2',
|
191
|
+
}}
|
192
|
+
>
|
193
|
+
<TextArea
|
194
|
+
id="chat-input"
|
195
|
+
maxLength={CHAT_MESSAGE_LIMIT}
|
196
|
+
style={{ border: 'none', resize: 'none' }}
|
197
|
+
css={{
|
198
|
+
w: '100%',
|
199
|
+
c: '$on_surface_high',
|
200
|
+
padding: '0.25rem !important',
|
201
|
+
}}
|
202
|
+
placeholder={message_placeholder}
|
203
|
+
required
|
204
|
+
autoComplete="off"
|
205
|
+
aria-autocomplete="none"
|
206
|
+
/>
|
207
|
+
|
208
|
+
<IconButton
|
209
|
+
id="send-btn"
|
210
|
+
css={{
|
211
|
+
ml: 'auto',
|
212
|
+
height: 'max-content',
|
213
|
+
mr: '$4',
|
214
|
+
'&:hover': { c: '$on_surface_medium' },
|
215
|
+
}}
|
216
|
+
data-testid="send_msg_btn"
|
217
|
+
>
|
218
|
+
<SendIcon />
|
219
|
+
</IconButton>
|
220
|
+
</Flex>
|
221
|
+
</Box>
|
222
|
+
)}
|
223
|
+
</div>
|
224
|
+
);
|
225
|
+
};
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { ExternalLinkIcon } from '@100mslive/react-icons';
|
3
|
+
import { Dropdown } from '../../../Dropdown';
|
4
|
+
import { Text } from '../../../Text';
|
5
|
+
|
6
|
+
export const PIPChatOption = ({ openChat, showPIPChat }: { openChat: () => void; showPIPChat: boolean }) => {
|
7
|
+
if (!showPIPChat) {
|
8
|
+
return <></>;
|
9
|
+
}
|
10
|
+
return (
|
11
|
+
<Dropdown.Item onClick={openChat} data-testid="brb_btn">
|
12
|
+
<ExternalLinkIcon height={18} width={18} style={{ padding: '0 $2' }} />
|
13
|
+
<Text variant="sm" css={{ ml: '$4', color: '$on_surface_high' }}>
|
14
|
+
Pop out Chat
|
15
|
+
</Text>
|
16
|
+
</Dropdown.Item>
|
17
|
+
);
|
18
|
+
};
|
@@ -0,0 +1,56 @@
|
|
1
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
2
|
+
import { PIPContext } from './context';
|
3
|
+
|
4
|
+
type PIPProviderProps = {
|
5
|
+
children: React.ReactNode;
|
6
|
+
};
|
7
|
+
|
8
|
+
export const PIPProvider = ({ children }: PIPProviderProps) => {
|
9
|
+
// Detect if the feature is available.
|
10
|
+
const isSupported = 'documentPictureInPicture' in window;
|
11
|
+
|
12
|
+
// Expose pipWindow that is currently active
|
13
|
+
const [pipWindow, setPipWindow] = useState<Window | null>(null);
|
14
|
+
|
15
|
+
// Close pipWidnow programmatically
|
16
|
+
const closePipWindow = useCallback(() => {
|
17
|
+
if (pipWindow != null) {
|
18
|
+
pipWindow.close();
|
19
|
+
setPipWindow(null);
|
20
|
+
}
|
21
|
+
}, [pipWindow]);
|
22
|
+
|
23
|
+
// Open new pipWindow
|
24
|
+
const requestPipWindow = useCallback(
|
25
|
+
async (width: number, height: number) => {
|
26
|
+
// We don't want to allow multiple requests.
|
27
|
+
if (pipWindow != null) {
|
28
|
+
return;
|
29
|
+
}
|
30
|
+
// @ts-ignore for documentPIP
|
31
|
+
const pip = await window.documentPictureInPicture.requestWindow({
|
32
|
+
width,
|
33
|
+
height,
|
34
|
+
});
|
35
|
+
|
36
|
+
// Detect when window is closed by user
|
37
|
+
pip.addEventListener('pagehide', () => {
|
38
|
+
setPipWindow(null);
|
39
|
+
});
|
40
|
+
|
41
|
+
setPipWindow(pip);
|
42
|
+
},
|
43
|
+
[pipWindow],
|
44
|
+
);
|
45
|
+
|
46
|
+
const value = useMemo(() => {
|
47
|
+
return {
|
48
|
+
isSupported,
|
49
|
+
pipWindow,
|
50
|
+
requestPipWindow,
|
51
|
+
closePipWindow,
|
52
|
+
};
|
53
|
+
}, [closePipWindow, isSupported, pipWindow, requestPipWindow]);
|
54
|
+
|
55
|
+
return <PIPContext.Provider value={value}>{children}</PIPContext.Provider>;
|
56
|
+
};
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { createPortal } from 'react-dom';
|
3
|
+
|
4
|
+
type PIPWindowProps = {
|
5
|
+
pipWindow: Window;
|
6
|
+
children: React.ReactNode;
|
7
|
+
};
|
8
|
+
|
9
|
+
export const PIPWindow = ({ pipWindow, children }: PIPWindowProps) => {
|
10
|
+
pipWindow.document.body.style.margin = '0';
|
11
|
+
pipWindow.document.body.style.overflowX = 'hidden';
|
12
|
+
return createPortal(children, pipWindow.document.body);
|
13
|
+
};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { createContext } from 'react';
|
2
|
+
|
3
|
+
export type PIPContextType = {
|
4
|
+
isSupported: boolean;
|
5
|
+
pipWindow: Window | null;
|
6
|
+
requestPipWindow: (width: number, height: number) => Promise<void>;
|
7
|
+
closePipWindow: () => void;
|
8
|
+
};
|
9
|
+
|
10
|
+
export const PIPContext = createContext<PIPContextType | undefined>(undefined);
|
@@ -0,0 +1,103 @@
|
|
1
|
+
import { useEffect } from 'react';
|
2
|
+
import { useHMSActions } from '@100mslive/react-sdk';
|
3
|
+
import { getCssText } from '../../../Theme';
|
4
|
+
import { usePIPWindow } from './usePIPWindow';
|
5
|
+
|
6
|
+
export const usePIPChat = () => {
|
7
|
+
const hmsActions = useHMSActions();
|
8
|
+
const { isSupported, requestPipWindow, pipWindow, closePipWindow } = usePIPWindow();
|
9
|
+
|
10
|
+
useEffect(() => {
|
11
|
+
if (document && pipWindow) {
|
12
|
+
const style = document.createElement('style');
|
13
|
+
style.id = 'stitches';
|
14
|
+
style.textContent = getCssText();
|
15
|
+
pipWindow.document.head.appendChild(style);
|
16
|
+
}
|
17
|
+
}, [pipWindow]);
|
18
|
+
|
19
|
+
// @ts-ignore
|
20
|
+
useEffect(() => {
|
21
|
+
if (pipWindow) {
|
22
|
+
const chatContainer = pipWindow.document.getElementById('chat-container');
|
23
|
+
const selector = pipWindow.document.getElementById('selector') as HTMLSelectElement;
|
24
|
+
const sendBtn = pipWindow.document.getElementById('send-btn');
|
25
|
+
const pipChatInput = pipWindow.document.getElementById('chat-input') as HTMLTextAreaElement;
|
26
|
+
const marker = pipWindow.document.getElementById('marker');
|
27
|
+
|
28
|
+
const observer = new IntersectionObserver(
|
29
|
+
entries => {
|
30
|
+
entries.forEach(entry => {
|
31
|
+
if (entry.isIntersecting && entry.target.id) {
|
32
|
+
hmsActions.setMessageRead(true, entry.target.id);
|
33
|
+
}
|
34
|
+
});
|
35
|
+
},
|
36
|
+
{
|
37
|
+
root: chatContainer,
|
38
|
+
threshold: 0.8,
|
39
|
+
},
|
40
|
+
);
|
41
|
+
|
42
|
+
const mutationObserver = new MutationObserver(mutations => {
|
43
|
+
mutations.forEach(mutation => {
|
44
|
+
if (mutation.addedNodes.length > 0) {
|
45
|
+
const newMessages = mutation.addedNodes;
|
46
|
+
newMessages.forEach(message => {
|
47
|
+
const messageId = (message as Element)?.id;
|
48
|
+
if (messageId === 'new-message-notif') {
|
49
|
+
message.addEventListener('click', () =>
|
50
|
+
setTimeout(() => marker?.scrollIntoView({ block: 'end', behavior: 'smooth' }), 0),
|
51
|
+
);
|
52
|
+
} else if (messageId) observer.observe(message as Element);
|
53
|
+
});
|
54
|
+
}
|
55
|
+
});
|
56
|
+
});
|
57
|
+
mutationObserver.observe(chatContainer as Node, {
|
58
|
+
childList: true,
|
59
|
+
});
|
60
|
+
|
61
|
+
const sendMessage = async () => {
|
62
|
+
const selection = selector?.value || 'Everyone';
|
63
|
+
if (selection === 'Everyone') {
|
64
|
+
await hmsActions.sendBroadcastMessage(pipChatInput.value.trim());
|
65
|
+
} else {
|
66
|
+
await hmsActions.sendGroupMessage(pipChatInput.value.trim(), [selection]);
|
67
|
+
}
|
68
|
+
pipChatInput.value = '';
|
69
|
+
setTimeout(() => marker?.scrollIntoView({ block: 'end', behavior: 'smooth' }), 0);
|
70
|
+
};
|
71
|
+
|
72
|
+
if (sendBtn && hmsActions && pipChatInput) {
|
73
|
+
const pipMessages = pipWindow.document.getElementsByClassName('pip-message');
|
74
|
+
// @ts-ignore
|
75
|
+
[...pipMessages].forEach(message => {
|
76
|
+
if (message.id) {
|
77
|
+
hmsActions.setMessageRead(true, message.id);
|
78
|
+
}
|
79
|
+
});
|
80
|
+
// @ts-ignore
|
81
|
+
const sendOnEnter = e => {
|
82
|
+
if (e.key === 'Enter') sendMessage();
|
83
|
+
};
|
84
|
+
sendBtn.addEventListener('click', sendMessage);
|
85
|
+
pipChatInput.addEventListener('keypress', sendOnEnter);
|
86
|
+
return () => {
|
87
|
+
sendBtn.removeEventListener('click', sendMessage);
|
88
|
+
pipChatInput.removeEventListener('keypress', sendOnEnter);
|
89
|
+
mutationObserver.disconnect();
|
90
|
+
observer.disconnect();
|
91
|
+
};
|
92
|
+
}
|
93
|
+
}
|
94
|
+
}, [pipWindow, hmsActions]);
|
95
|
+
|
96
|
+
useEffect(() => {
|
97
|
+
return () => {
|
98
|
+
pipWindow && closePipWindow();
|
99
|
+
};
|
100
|
+
}, [closePipWindow, pipWindow]);
|
101
|
+
|
102
|
+
return { isSupported, requestPipWindow, pipWindow };
|
103
|
+
};
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { useContext } from 'react';
|
2
|
+
import { PIPContext, PIPContextType } from './context';
|
3
|
+
|
4
|
+
export const usePIPWindow = (): PIPContextType => {
|
5
|
+
const context = useContext(PIPContext);
|
6
|
+
|
7
|
+
if (context === undefined) {
|
8
|
+
throw new Error('usePIPWindow must be used within a PIPContext');
|
9
|
+
}
|
10
|
+
|
11
|
+
return context;
|
12
|
+
};
|