salmon-lighter-12882
02/23/2025, 3:07 PMgray-monkey-83525
02/23/2025, 3:07 PMroom.on
method to register callbacks for different events. Here's a basic example:
import { Room, RoomEvent } from 'livekit-client';
// Create a new room instance
const room = new Room();
// Connect to the room
await room.connect('ws://localhost:7800', 'your_access_token');
// Add event listeners
room.on(RoomEvent.TrackPublished, (track, publication, participant) => {
console.log('Track published:', track);
});
room.on(RoomEvent.ParticipantConnected, (participant) => {
console.log('Participant connected:', participant.identity);
});
room.on(RoomEvent.Disconnected, () => {
console.log('Disconnected from room');
});
In this example, we are listening for TrackPublished
, ParticipantConnected
, and Disconnected
events. Each event has its own callback function that will be executed when the event is triggered.
Would you like more details on handling specific events or managing event listeners?
Sources:
- LiveKit JS Client SDK 👍 1 button 👎 0 button 💡 Hint: Mention @millions-hair-24956 in the thread for followups.salmon-lighter-12882
02/23/2025, 3:30 PMgray-monkey-83525
02/23/2025, 3:30 PMsetMicrophoneEnabled
method on the localParticipant
object. Here's how you can do it:
// Assume 'room' is an instance of a connected LiveKit Room
const localParticipant = room.localParticipant;
// Mute the microphone
localParticipant.setMicrophoneEnabled(false);
This method will stop the microphone from sending audio data to the server, effectively muting it. If you want to unmute the microphone later, you can call the same method with true
as the argument:
// Unmute the microphone
localParticipant.setMicrophoneEnabled(true);
Would you like more details on managing audio tracks or other participant controls?
Sources:
- LiveKit Client SDK - Handling Common Track Types 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.