Skip to content

Commit f68bd79

Browse files
committed
feat: get rid of TrackReferencePlaceholder and just use TrackReference | null
1 parent 9b26e15 commit f68bd79

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

packages/react/src/hooks/useConversationWith.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { TokenSource } from '../TokenSource';
77
import { useMaybeRoomContext } from '../context';
88
import { RoomAgentDispatch, RoomConfiguration } from '@livekit/protocol';
99
import { useAgent } from './useAgent';
10-
import { TrackReferenceOrPlaceholder, TrackReferencePlaceholder } from '@livekit/components-core';
10+
import { TrackReference } from '@livekit/components-core';
1111
import { useLocalParticipant } from './useLocalParticipant';
1212

1313
export enum ConversationEvent {
@@ -74,8 +74,8 @@ type ConversationStateConnecting = ConversationStateCommon & {
7474
isReconnecting: false;
7575

7676
local: {
77-
cameraTrack: TrackReferencePlaceholder;
78-
microphoneTrack: TrackReferencePlaceholder;
77+
cameraTrack: null;
78+
microphoneTrack: null;
7979
};
8080
};
8181

@@ -85,8 +85,8 @@ type ConversationStateConnected = ConversationStateCommon & {
8585
isReconnecting: boolean;
8686

8787
local: {
88-
cameraTrack: TrackReferenceOrPlaceholder,
89-
microphoneTrack: TrackReferenceOrPlaceholder,
88+
cameraTrack: TrackReference | null,
89+
microphoneTrack: TrackReference | null,
9090
};
9191
};
9292

@@ -96,8 +96,8 @@ type ConversationStateDisconnected = ConversationStateCommon & {
9696
isReconnecting: false;
9797

9898
local: {
99-
cameraTrack: TrackReferencePlaceholder;
100-
microphoneTrack: TrackReferencePlaceholder;
99+
cameraTrack: null;
100+
microphoneTrack: null;
101101
};
102102
};
103103

@@ -186,11 +186,25 @@ export function useConversationWith(agentToDispatch: string | RoomAgentDispatch
186186
const { localParticipant } = useLocalParticipant({ room });
187187
const cameraPublication = localParticipant.getTrackPublication(Track.Source.Camera);
188188
const localCamera = useMemo(() => {
189-
return !cameraPublication?.isMuted ? { source: Track.Source.Camera as const, participant: localParticipant, publication: cameraPublication } : null;
189+
if (!cameraPublication || cameraPublication.isMuted) {
190+
return null;
191+
}
192+
return {
193+
source: Track.Source.Camera,
194+
participant: localParticipant,
195+
publication: cameraPublication,
196+
};
190197
}, [localParticipant, cameraPublication, cameraPublication?.isMuted]);
191198
const microphonePublication = localParticipant.getTrackPublication(Track.Source.Microphone);
192199
const localMicrophone = useMemo(() => {
193-
return !microphonePublication?.isMuted ? { source: Track.Source.Microphone as const, participant: localParticipant, publication: microphonePublication } : null;
200+
if (!microphonePublication || microphonePublication.isMuted) {
201+
return null;
202+
}
203+
return {
204+
source: Track.Source.Microphone,
205+
participant: localParticipant,
206+
publication: microphonePublication,
207+
};
194208
}, [localParticipant, microphonePublication, microphonePublication?.isMuted]);
195209

196210
const conversationState = useMemo((): ConversationStateConnecting | ConversationStateConnected | ConversationStateDisconnected => {
@@ -214,8 +228,8 @@ export function useConversationWith(agentToDispatch: string | RoomAgentDispatch
214228
...generateDerivedConnectionStateValues(ConnectionState.Connecting),
215229

216230
local: {
217-
cameraTrack: { participant: localParticipant, source: Track.Source.Camera },
218-
microphoneTrack: { participant: localParticipant, source: Track.Source.Microphone },
231+
cameraTrack: null,
232+
microphoneTrack: null,
219233
},
220234
};
221235

@@ -229,8 +243,8 @@ export function useConversationWith(agentToDispatch: string | RoomAgentDispatch
229243
...generateDerivedConnectionStateValues(roomConnectionState),
230244

231245
local: {
232-
cameraTrack: localCamera ?? { participant: localParticipant, source: Track.Source.Camera },
233-
microphoneTrack: localMicrophone ?? { participant: localParticipant, source: Track.Source.Microphone },
246+
cameraTrack: localCamera,
247+
microphoneTrack: localMicrophone,
234248
},
235249
};
236250

@@ -242,8 +256,8 @@ export function useConversationWith(agentToDispatch: string | RoomAgentDispatch
242256
...generateDerivedConnectionStateValues(ConnectionState.Disconnected),
243257

244258
local: {
245-
cameraTrack: { participant: localParticipant, source: Track.Source.Camera },
246-
microphoneTrack: { participant: localParticipant, source: Track.Source.Microphone },
259+
cameraTrack: null,
260+
microphoneTrack: null,
247261
},
248262
};
249263
}

0 commit comments

Comments
 (0)