bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/video-provider/video-provider-graphql/adapter.tsx
Tainan Felipe 3bc40df230
Add: useDeduplicatedSubscription hook (#20376)
* Add: useDeduplicatedSubscription hook

* Fix: TS error

* Add: components using useDeduplicatedSubscription

* Change: Move to useDeduplicatedSubscription

* Change: unsubscribe logic to own useEffect

* Change: remove file import over package

* Fix: TS errors

* Fix: private chat not loading

* Change: revert changes on queries

* Fix: eslint error

* Remove: html-webpack-plugin package

* Fix: external video

* Add: comment about the stringToHash function

* Fix: video player showing tools over presentation
2024-06-04 10:40:54 -03:00

57 lines
1.5 KiB
TypeScript

import { useEffect, useRef } from 'react';
import logger from '/imports/startup/client/logger';
import {
VIDEO_STREAMS_SUBSCRIPTION,
VideoStreamsResponse,
} from './queries';
import { setStreams } from './state';
import { AdapterProps } from '../../components-data/graphqlToMiniMongoAdapterManager/component';
import useDeduplicatedSubscription from '/imports/ui/core/hooks/useDeduplicatedSubscription';
const VideoStreamAdapter: React.FC<AdapterProps> = ({
onReady,
children,
}) => {
const ready = useRef(false);
const { data, loading, error } = useDeduplicatedSubscription<VideoStreamsResponse>(VIDEO_STREAMS_SUBSCRIPTION);
useEffect(() => {
if (loading) return;
if (error) {
logger.error(`Video streams subscription failed. ${error.name}: ${error.message}`, error);
}
if (!data) {
setStreams([]);
return;
}
const streams = data.user_camera.map(({ streamId, user, voice }) => ({
stream: streamId,
deviceId: streamId.split('_')[3],
userId: user.userId,
name: user.name,
nameSortable: user.nameSortable,
pinned: user.pinned,
floor: voice?.floor || false,
lastFloorTime: voice?.lastFloorTime || '0',
isModerator: user.isModerator,
type: 'stream' as const,
}));
setStreams(streams);
}, [data]);
useEffect(() => {
if (!ready.current) {
ready.current = true;
onReady('VideoStreamAdapter');
}
}, [loading]);
return children;
};
export default VideoStreamAdapter;