I'm currently using Nodejs version, so how can I a...
# ask-ai
h
I'm currently using Nodejs version, so how can I achieve "switch the linked participant in the room" in Nodejs? I noticed when call session.start(...), it'll create the private RoomIO properties, so I tried 2 approaches and none is working: 1. Manually create a RoomIO like the python version, but it doesn't work like I expect. The agent's still listening to the first participant. 2. Access the AgentSession.roomId like this:
Copy code
// Listen participant metadata changed
const roomIO = (session as any).roomIO as voice.RoomIO;
roomIO.setParticipant(participant.identity);
Then if this participant publish an audio track, I get a log: "RoomEvent.TrackSubscribed: Stream source already set"
t
To switch the linked participant in a room using Node.js, you can easily do this with the LiveKit Agents SDK. Let me walk you through the steps: • First, use the
RoomIO
class from the LiveKit Agents SDK to manage the linked participant. • Then, call the
setParticipant
method to switch to the participant you want by their identity:
Copy code
import { RoomIO } from '@livekit/agents';

// Assuming you have a RoomIO instance
const roomIO = new RoomIO({
  agentSession: yourAgentSession,
  room: yourRoom,
  // other options...
});

// Switch to a specific participant by identity
roomIO.setParticipant('participant-identity');

// Or unset the current participant
roomIO.unsetParticipant();
This approach will make sure the audio and video streams switch smoothly to the participant you specify. If you happen to see an error like "Stream source already set," it usually means the participant's audio track might be in use elsewhere, so double-check that it’s managed properly. If you need any more help, I’m here for you! Sources: livekit-agents/livekit/agents/voice/room_io/room_io.py | quickstart/src/joinroom.js | packages/livekit-server-sdk/src/RoomServiceClient.ts | Managing participants | LiveKit docs | cmd/lk/room.go