@@ -10,22 +10,25 @@ import {
1010import React , { useCallback , useEffect , useState } from 'react' ;
1111import {
1212 AudioSession ,
13- LiveKitRoom ,
1413 useIOSAudioManagement ,
1514 useLocalParticipant ,
1615 useParticipantTracks ,
1716 useRoomContext ,
1817 VideoTrack ,
1918} from '@livekit/react-native' ;
20- import { useConnectionDetails } from '@/hooks/useConnectionDetails' ;
2119import { SafeAreaView } from 'react-native-safe-area-context' ;
2220import { useRouter } from 'expo-router' ;
2321import ControlBar from './ui/ControlBar' ;
2422import ChatBar from './ui/ChatBar' ;
2523import ChatLog from './ui/ChatLog' ;
2624import AgentVisualization from './ui/AgentVisualization' ;
27- import useDataStreamTranscriptions from '@/hooks/useDataStreamTranscriptions' ;
2825import { Track } from 'livekit-client' ;
26+ import {
27+ TrackReference ,
28+ useSessionMessages ,
29+ useTrackToggle ,
30+ } from '@livekit/components-react' ;
31+ import { useConnection } from '@/hooks/useConnection' ;
2932
3033export default function AssistantScreen ( ) {
3134 // Start the audio session first.
@@ -40,27 +43,18 @@ export default function AssistantScreen() {
4043 } ;
4144 } , [ ] ) ;
4245
43- const connectionDetails = useConnectionDetails ( ) ;
44-
4546 return (
4647 < SafeAreaView >
47- < LiveKitRoom
48- serverUrl = { connectionDetails ?. url }
49- token = { connectionDetails ?. token }
50- connect = { true }
51- audio = { true }
52- video = { false }
53- >
54- < RoomView />
55- </ LiveKitRoom >
48+ < RoomView />
5649 </ SafeAreaView >
5750 ) ;
5851}
5952
6053const RoomView = ( ) => {
6154 const router = useRouter ( ) ;
62-
55+ const connection = useConnection ( ) ;
6356 const room = useRoomContext ( ) ;
57+
6458 useIOSAudioManagement ( room , true ) ;
6559
6660 const {
@@ -79,45 +73,41 @@ const RoomView = () => {
7973
8074 const localVideoTrack =
8175 localCameraTrack && isCameraEnabled
82- ? {
76+ ? ( {
8377 participant : localParticipant ,
8478 publication : localCameraTrack ,
8579 source : Track . Source . Camera ,
86- }
80+ } satisfies TrackReference )
8781 : localScreenShareTrack . length > 0 && isScreenShareEnabled
8882 ? localScreenShareTrack [ 0 ]
8983 : null ;
9084
91- // Transcriptions
92- const transcriptionState = useDataStreamTranscriptions ( ) ;
93- const addTranscription = transcriptionState . addTranscription ;
85+ // Messages
86+ const { messages, send } = useSessionMessages ( ) ;
9487 const [ isChatEnabled , setChatEnabled ] = useState ( false ) ;
9588 const [ chatMessage , setChatMessage ] = useState ( '' ) ;
9689
9790 const onChatSend = useCallback (
9891 ( message : string ) => {
99- addTranscription ( localParticipantIdentity , message ) ;
92+ send ( message ) ;
10093 setChatMessage ( '' ) ;
10194 } ,
102- [ localParticipantIdentity , addTranscription , setChatMessage ]
95+ [ setChatMessage , send ]
10396 ) ;
10497
10598 // Control callbacks
106- const onMicClick = useCallback ( ( ) => {
107- localParticipant . setMicrophoneEnabled ( ! isMicrophoneEnabled ) ;
108- } , [ isMicrophoneEnabled , localParticipant ] ) ;
109- const onCameraClick = useCallback ( ( ) => {
110- localParticipant . setCameraEnabled ( ! isCameraEnabled ) ;
111- } , [ isCameraEnabled , localParticipant ] ) ;
112- const onScreenShareClick = useCallback ( ( ) => {
113- localParticipant . setScreenShareEnabled ( ! isScreenShareEnabled ) ;
114- } , [ isScreenShareEnabled , localParticipant ] ) ;
99+ const micToggle = useTrackToggle ( { source : Track . Source . Microphone } ) ;
100+ const cameraToggle = useTrackToggle ( { source : Track . Source . Camera } ) ;
101+ const screenShareToggle = useTrackToggle ( {
102+ source : Track . Source . ScreenShare ,
103+ } ) ;
115104 const onChatClick = useCallback ( ( ) => {
116105 setChatEnabled ( ! isChatEnabled ) ;
117106 } , [ isChatEnabled , setChatEnabled ] ) ;
118107 const onExitClick = useCallback ( ( ) => {
108+ connection . disconnect ( ) ;
119109 router . back ( ) ;
120- } , [ router ] ) ;
110+ } , [ connection , router ] ) ;
121111
122112 // Layout positioning
123113 const [ containerWidth , setContainerWidth ] = useState (
@@ -159,10 +149,7 @@ const RoomView = () => {
159149 } }
160150 >
161151 < View style = { styles . spacer } />
162- < ChatLog
163- style = { styles . logContainer }
164- transcriptions = { transcriptionState . transcriptions }
165- />
152+ < ChatLog style = { styles . logContainer } messages = { messages } />
166153 < ChatBar
167154 style = { styles . chatBar }
168155 value = { chatMessage }
@@ -194,10 +181,10 @@ const RoomView = () => {
194181 isCameraEnabled,
195182 isScreenShareEnabled,
196183 isChatEnabled,
197- onMicClick,
198- onCameraClick,
184+ onMicClick : micToggle . toggle ,
185+ onCameraClick : cameraToggle . toggle ,
199186 onChatClick,
200- onScreenShareClick,
187+ onScreenShareClick : screenShareToggle . toggle ,
201188 onExitClick,
202189 } }
203190 />
0 commit comments