Skip to main content
Version: Next

Manage On-Screen Participants - React Native

It is important that only the necessary person is present on the screen when livestream is on. To handle this, we will be using the pin and unpin methods of the useParticipant hook.

note

To ensure only the hosts/speakers are shown in the grid, you should use the SPOTLIGHT layout and pin as the priority when starting the interactive livestream.

Let us first explore two methods that we will be using to manage on-screen participats.

pin()

With this method you can pin any participant's Camera, Screen Share or both. This can be useful to identify the participants based on which you can perform rendering participant grid.

unpin()

With this methods you can unpin any participant's Camera, Screen Share or both. This can be useful to reset pin state of the participant.

Managing On-Screen Participants

  1. If you want to pin all the hosts/speakers automatically, you can do it by listenting to the onMeetingJoined callback and onParticipantModeChanged, where you can pin and unpin based on the mode.
import { useMeeting } from "@videosdk.live/react-native-sdk";

function MeetingView() {
const mMeeting = useMeeting({});

//We are using a reference to the meeting object because
//While referencing it in the callbacks we want to use its latest state
const mMeetingRef = useRef();

useEffect(() => {
mMeetingRef.current = mMeeting;
}, [mMeeting]);

const { localParticipant } = useMeeting({
onMeetingJoined: () => {
const localParticipant = mMeetingRef.current?.localParticipant;
//We will pin the participant if mode is conference
if (localParticipant.mode == Constants.modes.CONFERENCE) {
localParticipant.pin();
} else {
localParticipant.unpin();
}
},
onParticipantModeChanged: ({ participantId, mode }) => {
const localParticipant = mMeetingRef.current?.localParticipant;
//We will pin the participant if mode is conference else unpin him
if (participantId == localParticipant.id) {
if (localParticipant.mode == Constants.modes.CONFERENCE) {
localParticipant.pin();
} else {
localParticipant.unpin();
}
}
},
});
return <>...</>;
}
  1. When rendering the participant grid on the Speaker side, make sure to show only the participants who are in CONFERENCE mode. You can filter the participants as shown in below examples.
const { participants } = useMeeting();
const speakers = [...participants.values()].filter((participant) => {
return participant.mode == Constants.modes.CONFERENCE;
});

API Reference

The API references for all the methods utilized in this guide are provided below.

Got a Question? Ask us on discord