diff --git a/app/custom/VideoConferenceClientImpl.tsx b/app/custom/VideoConferenceClientImpl.tsx index 02b779c..391ddb6 100644 --- a/app/custom/VideoConferenceClientImpl.tsx +++ b/app/custom/VideoConferenceClientImpl.tsx @@ -7,11 +7,13 @@ import { Room, RoomConnectOptions, RoomOptions, + RoomEvent, VideoPresets, + type TranscriptionSegment, type VideoCodec, } from 'livekit-client'; import { DebugMode } from '@/lib/Debug'; -import { useMemo } from 'react'; +import { useMemo, useEffect, useState } from 'react'; import { decodePassphrase } from '@/lib/client-utils'; import { SettingsMenu } from '@/lib/SettingsMenu'; @@ -57,6 +59,33 @@ export function VideoConferenceClientImpl(props: { }; }, []); + const [transcriptions, setTranscriptions] = useState<{ [id: string]: TranscriptionSegment }>({}); + useEffect(() => { + if (!room) { + return; + } + console.log('ROOM!!!'); + const updateTranscriptions = ( + segments: TranscriptionSegment[], + participant: any, + publication: any, + ) => { + console.log('received transcriptions', segments); + setTranscriptions((prev) => { + const newTranscriptions = { ...prev }; + for (const segment of segments) { + newTranscriptions[segment.id] = segment; + } + console.log('===>', newTranscriptions); + return newTranscriptions; + }); + }; + room.on(RoomEvent.TranscriptionReceived, updateTranscriptions); + return () => { + room.off(RoomEvent.TranscriptionReceived, updateTranscriptions); + }; + }, [room]); + return ( ({}); + const [latestText, setLatestText] = React.useState(''); + React.useEffect(() => { + if (!room) { + return; + } + const updateTranscriptions = ( + segments: TranscriptionSegment[], + participant: any, + publication: any, + ) => { + if (segments.length > 0) { + setLatestText(segments[0].text); + } + // setTranscriptions((prev) => { + // const newTranscriptions = { ...prev }; + // for (const segment of segments) { + // newTranscriptions[segment.id] = segment; + // } + // console.log('===>', newTranscriptions); + // return newTranscriptions; + // }); + }; + room.on(RoomEvent.TranscriptionReceived, updateTranscriptions); + return () => { + room.off(RoomEvent.TranscriptionReceived, updateTranscriptions); + }; + }, [room]); + const router = useRouter(); const handleOnLeave = React.useCallback(() => router.push('/'), [router]); @@ -172,8 +206,9 @@ function VideoConferenceComponent(props: { chatMessageFormatter={formatChatMessageLinks} SettingsComponent={SHOW_SETTINGS_MENU ? SettingsMenu : undefined} /> - + {/* */} + ); diff --git a/lib/Transcript.tsx b/lib/Transcript.tsx new file mode 100644 index 0000000..ed69ea4 --- /dev/null +++ b/lib/Transcript.tsx @@ -0,0 +1,9 @@ +import styles from '../styles/Transcript.module.css'; + +export default function Transcript(props: { latestText: string }) { + return ( +
+

{props.latestText}

+
+ ); +} diff --git a/styles/Transcript.module.css b/styles/Transcript.module.css new file mode 100644 index 0000000..86939f6 --- /dev/null +++ b/styles/Transcript.module.css @@ -0,0 +1,14 @@ + +.wrap { + position:absolute; + top: 32px; + width:100%; + left:0; + right:0; +} + +.text{ + color:white; + text-align:center; + margin:16px; +} \ No newline at end of file