voicebot-react-native-expo
Version:
This is a voicebot-react-native package of Kipps AI voice bot for React Native Expo
43 lines (39 loc) • 1.55 kB
text/typescript
import type { Room, RoomEvent } from 'livekit-client';
import { useLocalParticipant } from './useLocalParticipant';
import { useRemoteParticipants } from './useRemoteParticipants';
import * as React from 'react';
/** @public */
export interface UseParticipantsOptions {
/**
* To optimize performance, you can use the `updateOnlyOn` property to decide on what RoomEvents the hook updates.
* By default it updates on all relevant RoomEvents to keep the returned participants array up to date.
* The minimal set of non-overwriteable `RoomEvents` is: `[RoomEvent.ParticipantConnected, RoomEvent.ParticipantDisconnected, RoomEvent.ConnectionStateChanged]`
*/
updateOnlyOn?: RoomEvent[];
/**
* The room to use. If not provided, the hook will use the room from the context.
*/
room?: Room;
}
/**
* The `useParticipants` hook returns all participants (local and remote) of the current room.
* @remarks
* To optimize performance, you can use the `updateOnlyOn` property to decide on what `RoomEvents` the hook updates.
*
* @example
* ```tsx
* const participants = useParticipants();
* <ParticipantLoop participants={participants}>
* <ParticipantName />
* </ParticipantLoop>
* ```
* @public
*/
export function useParticipants(options: UseParticipantsOptions = {}) {
const remoteParticipants = useRemoteParticipants(options);
const { localParticipant } = useLocalParticipant(options);
return React.useMemo(
() => [localParticipant, ...remoteParticipants],
[localParticipant, remoteParticipants],
);
}