able-jackal-84140
07/08/2025, 2:15 PMtall-airline-16756
07/08/2025, 2:15 PMtall-airline-16756
07/08/2025, 2:15 PMuseDisconnectButton
hook to create a disconnect button that handles the termination for you. Example:
import { useDisconnectButton } from "@livekit/components-react";
function CustomDisconnectButton() {
const { onClick } = useDisconnectButton();
return (
);
}
1. Manually (e.g., Dart): Stop local and remote tracks individually, then disconnect from the room. Example:
// Stop local audio track
if (localAudioTrack != null) {
await localAudioTrack.stop();
}
// Stop remote audio track
if (remoteAudioTrack != null) {
await remoteAudioTrack.stop();
}
// Disconnect from the room
await room.disconnect();
This stops all media tracks and disconnects the client from the room, effectively terminating the call.
If you use web React components, the hook method is simpler to integrate.
This allows you to add any custom logic before calling these disconnect steps as needed.