@@ -10,22 +10,21 @@ 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 { TrackReference , useSessionContext , useSessionMessages , useTrackToggle } from '@livekit/components-react' ;
27+ import { useConnection } from '@/hooks/useConnection' ;
2928
3029export default function AssistantScreen ( ) {
3130 // Start the audio session first.
@@ -40,27 +39,19 @@ export default function AssistantScreen() {
4039 } ;
4140 } , [ ] ) ;
4241
43- const connectionDetails = useConnectionDetails ( ) ;
44-
4542 return (
4643 < 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 >
44+ < RoomView />
5645 </ SafeAreaView >
5746 ) ;
5847}
5948
6049const RoomView = ( ) => {
6150 const router = useRouter ( ) ;
62-
51+ const connection = useConnection ( ) ;
52+ const session = useSessionContext ( ) ;
6353 const room = useRoomContext ( ) ;
54+
6455 useIOSAudioManagement ( room , true ) ;
6556
6657 const {
@@ -83,39 +74,34 @@ const RoomView = () => {
8374 participant : localParticipant ,
8475 publication : localCameraTrack ,
8576 source : Track . Source . Camera ,
86- }
77+ } satisfies TrackReference
8778 : localScreenShareTrack . length > 0 && isScreenShareEnabled
8879 ? localScreenShareTrack [ 0 ]
8980 : null ;
9081
91- // Transcriptions
92- const transcriptionState = useDataStreamTranscriptions ( ) ;
93- const addTranscription = transcriptionState . addTranscription ;
82+ // Messages
83+ const { messages, send } = useSessionMessages ( )
9484 const [ isChatEnabled , setChatEnabled ] = useState ( false ) ;
9585 const [ chatMessage , setChatMessage ] = useState ( '' ) ;
9686
9787 const onChatSend = useCallback (
9888 ( message : string ) => {
99- addTranscription ( localParticipantIdentity , message ) ;
89+ send ( message )
10090 setChatMessage ( '' ) ;
10191 } ,
102- [ localParticipantIdentity , addTranscription , setChatMessage ]
92+ [ localParticipantIdentity , setChatMessage ]
10393 ) ;
10494
10595 // 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 ] ) ;
96+ const micToggle = useTrackToggle ( { source : Track . Source . Microphone } ) ;
97+ const cameraToggle = useTrackToggle ( { source : Track . Source . Camera } ) ;
98+ const screenShareToggle = useTrackToggle ( { source : Track . Source . ScreenShare } ) ;
11599 const onChatClick = useCallback ( ( ) => {
116100 setChatEnabled ( ! isChatEnabled ) ;
117101 } , [ isChatEnabled , setChatEnabled ] ) ;
118102 const onExitClick = useCallback ( ( ) => {
103+ connection . startDisconnectTransition ( ) ;
104+ connection . onDisconnectTransitionComplete ( ) ;
119105 router . back ( ) ;
120106 } , [ router ] ) ;
121107
@@ -161,7 +147,7 @@ const RoomView = () => {
161147 < View style = { styles . spacer } />
162148 < ChatLog
163149 style = { styles . logContainer }
164- transcriptions = { transcriptionState . transcriptions }
150+ messages = { messages }
165151 />
166152 < ChatBar
167153 style = { styles . chatBar }
@@ -194,10 +180,10 @@ const RoomView = () => {
194180 isCameraEnabled,
195181 isScreenShareEnabled,
196182 isChatEnabled,
197- onMicClick,
198- onCameraClick,
183+ onMicClick : micToggle . toggle ,
184+ onCameraClick : cameraToggle . toggle ,
199185 onChatClick,
200- onScreenShareClick,
186+ onScreenShareClick : screenShareToggle . toggle ,
201187 onExitClick,
202188 } }
203189 />
0 commit comments