@100mslive/roomkit-react 0.3.12 → 0.3.13-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import Draggable, { ControlPosition } from 'react-draggable';
2
3
  import { useMedia } from 'react-use';
3
4
  import {
4
5
  HMSTranscript,
@@ -27,6 +28,9 @@ class SimpleQueue {
27
28
  private storage: TranscriptData[] = [];
28
29
  constructor(private capacity: number = 3, private MAX_STORAGE_TIME: number = 5000) {}
29
30
  enqueue(data: TranscriptData): void {
31
+ if (!data.transcript.trim()) {
32
+ return;
33
+ }
30
34
  if (this.size() === this.capacity && this.storage[this.size() - 1].final) {
31
35
  this.dequeue(this.storage[this.size() - 1]);
32
36
  }
@@ -164,7 +168,13 @@ const TranscriptView = ({ peer_id, data }: { peer_id: string; data: string }) =>
164
168
  );
165
169
  };
166
170
 
167
- export const CaptionsViewer = () => {
171
+ export const CaptionsViewer = ({
172
+ defaultPosition,
173
+ setDefaultPosition,
174
+ }: {
175
+ defaultPosition: ControlPosition;
176
+ setDefaultPosition: (position: ControlPosition) => void;
177
+ }) => {
168
178
  const { elements, screenType } = useRoomLayoutConferencingScreen();
169
179
  const isMobile = useMedia(config.media.md);
170
180
  const isChatOpen = useIsSidepaneTypeOpen(SIDE_PANE_OPTIONS.CHAT);
@@ -178,6 +188,8 @@ export const CaptionsViewer = () => {
178
188
 
179
189
  const isTranscriptionEnabled = useHMSStore(selectIsTranscriptionEnabled);
180
190
 
191
+ const nodeRef = useRef<HTMLDivElement>(null);
192
+
181
193
  useEffect(() => {
182
194
  const timeInterval = setInterval(() => {
183
195
  if (!captionQueue) {
@@ -205,30 +217,40 @@ export const CaptionsViewer = () => {
205
217
  return null;
206
218
  }
207
219
  return (
208
- <Box
209
- css={{
210
- position: 'absolute',
211
- w: isMobile ? '100%' : '40%',
212
- bottom: showCaptionAtTop ? '' : '0',
213
- top: showCaptionAtTop ? '0' : '',
214
- left: isMobile ? 0 : '50%',
215
- transform: isMobile ? '' : 'translateX(-50%)',
216
- background: '#000000A3',
217
- overflow: 'clip',
218
- zIndex: 10,
219
- height: 'fit-content',
220
- r: '$1',
221
- p: '$6',
222
- transition: 'bottom 0.3s ease-in-out',
223
- '&:empty': { display: 'none' },
220
+ <Draggable
221
+ bounds="parent"
222
+ nodeRef={nodeRef}
223
+ defaultPosition={defaultPosition}
224
+ onStop={(_, data) => {
225
+ setDefaultPosition({ x: data.lastX, y: data.lastY });
224
226
  }}
225
227
  >
226
- <Flex direction="column">
227
- {dataToShow.map((data: { [key: string]: string }, index: number) => {
228
- const key = Object.keys(data)[0];
229
- return <TranscriptView key={index} peer_id={key} data={data[key]} />;
230
- })}
231
- </Flex>
232
- </Box>
228
+ <Box
229
+ ref={nodeRef}
230
+ css={{
231
+ position: 'absolute',
232
+ w: isMobile ? '100%' : '40%',
233
+ bottom: showCaptionAtTop ? '' : '0',
234
+ top: showCaptionAtTop ? '0' : '',
235
+ left: isMobile ? 0 : '50%',
236
+ transform: isMobile ? '' : 'translateX(-50%)',
237
+ background: '#000000A3',
238
+ overflow: 'clip',
239
+ zIndex: 10,
240
+ height: 'fit-content',
241
+ r: '$1',
242
+ p: '$6',
243
+ transition: 'bottom 0.3s ease-in-out',
244
+ '&:empty': { display: 'none' },
245
+ }}
246
+ >
247
+ <Flex direction="column">
248
+ {dataToShow.map((data: { [key: string]: string }, index: number) => {
249
+ const key = Object.keys(data)[0];
250
+ return <TranscriptView key={index} peer_id={key} data={data[key]} />;
251
+ })}
252
+ </Flex>
253
+ </Box>
254
+ </Draggable>
233
255
  );
234
256
  };