Skip to content

Commit 36327ad

Browse files
committed
fix: address issue with local participant state not always being reactive
There are some landmines around useLocalParticipant().isCameraEnabled / isMicrophoneEnabled, they don't seem to update properly?
1 parent acf1f63 commit 36327ad

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

packages/react/src/hooks/useConversationWith.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,15 @@ export function useConversationWith(agentToDispatch: string | RoomAgentDispatch,
186186
};
187187
}, [room, emitter]);
188188

189-
const { localParticipant, cameraTrack, microphoneTrack } = useLocalParticipant({ room });
189+
const { localParticipant } = useLocalParticipant({ room });
190+
const cameraPublication = localParticipant.getTrackPublication(Track.Source.Camera);
190191
const localCamera = useMemo(() => {
191-
return cameraTrack ? { source: Track.Source.Camera as const, participant: localParticipant, publication: microphoneTrack } : null;
192-
}, [localParticipant, microphoneTrack]);
192+
return !cameraPublication?.isMuted ? { source: Track.Source.Camera as const, participant: localParticipant, publication: cameraPublication } : null;
193+
}, [localParticipant, cameraPublication, cameraPublication?.isMuted]);
194+
const microphonePublication = localParticipant.getTrackPublication(Track.Source.Microphone);
193195
const localMicrophone = useMemo(() => {
194-
return microphoneTrack ? { source: Track.Source.Microphone as const, participant: localParticipant, publication: microphoneTrack } : null;
195-
}, [localParticipant, microphoneTrack]);
196+
return !microphonePublication?.isMuted ? { source: Track.Source.Microphone as const, participant: localParticipant, publication: microphonePublication } : null;
197+
}, [localParticipant, microphonePublication, microphonePublication?.isMuted]);
196198

197199
const conversationState = useMemo((): ConversationStateConnecting | ConversationStateConnected | ConversationStateDisconnected => {
198200
const common: ConversationStateCommon = {
@@ -248,7 +250,7 @@ export function useConversationWith(agentToDispatch: string | RoomAgentDispatch,
248250
},
249251
};
250252
}
251-
}, [options.credentials, room, emitter, roomConnectionState, localParticipant]);
253+
}, [options.credentials, room, emitter, roomConnectionState, localParticipant, localCamera, localMicrophone]);
252254
useEffect(() => {
253255
emitter.emit(ConversationEvent.ConnectionStateChanged, conversationState.connectionState);
254256
}, [emitter, conversationState.connectionState]);

0 commit comments

Comments
 (0)