late-businessperson-58140
08/20/2025, 4:46 AMtall-airline-16756
08/20/2025, 4:47 AMtall-airline-16756
08/20/2025, 4:47 AMlate-businessperson-58140
08/20/2025, 4:47 AMtall-airline-16756
08/20/2025, 4:47 AMonError
, onMediaDeviceFailure
, and onEncryptionError
props: These come with the LiveKitRoom
component. Here's a quick example:
<LiveKitRoom
serverUrl="{serverUrl}"
token="{token}"
onError={(error) => {
console.error('LiveKit error occurred:', error);
}}
onMediaDeviceFailure={(failure) => {
console.error('Media device failure:', failure);
if (failure === 'PermissionDenied') {
alert('Please grant camera/microphone permissions');
}
}}
onEncryptionError={(error) => {
console.error('Encryption error:', error);
}}
onDisconnected={() => {
console.log('Disconnected from room');
}}
/>
• Keep an eye on the error
field in `RoomState`: If this field shows up, it tells you the current error state of the room.
• Listen for specific error events: You can subscribe to events like mediaDevicesError
, encryptionError
, or disconnected
to get detailed error info or reasons for disconnects.
If you want a hand setting this up or have any questions, just let me know—I’m happy to help!
Sources: docs/interfaces/RoomState.html | README.md | Sources/LiveKit/Errors.swift | Runtime/Scripts/Room/Errors.cs | README.mdlate-businessperson-58140
08/20/2025, 4:51 AM+91${_values_.phoneNumber}
,
},
{
onSuccess: () => {
Toaster({
variant: "success",
message: "Agent is calling. Please pick up call.",
});
hide();
},
onError: error => {
console.error("Call error:", error);
Toaster({
variant: "error",
message: "Failed to initiate call. Please try again.",
});
},
}
);
},
});
const handleShowSelectPhoneNumber = () => {
NiceModal.show(NoPhoneNumbersModal, {
numbers: phoneNumbers || [],
setSelectedNumber: (_number_: string) => {
setFieldValue("agentPhoneNumber", number);
},
});
};
useEffect(() => {
const onParticipantConnected = () => {
if (!intervalRef.current) {
intervalRef.current = setInterval(() => {
setCallDuration(d => d + 1);
}, 1000);
}
};
const onDisconnected = () => {
setCallStatus(CallStatus.DISCONNECTED);
if (intervalRef.current) {
clearInterval(intervalRef.current);
intervalRef.current = null;
}
};
room.on("participantConnected", onParticipantConnected);
room.on("disconnected", onDisconnected);
return () => {
room.off("participantConnected", onParticipantConnected);
room.off("disconnected", onDisconnected);
};
}, [room]);
const toggleMute = async () => {
if (!micTrack || room.state !== "connected") return;
try {
if (isMuted) {
await micTrack.unmute();
setIsMuted(false);
} else {
await micTrack.mute();
setIsMuted(true);
}
} catch (err) {
console.error("Error toggling mute:", err);
}
};
useEffect(() => {
const handleKeyDown = async (_e_: KeyboardEvent) => {
if (e.code === "Space" && micTrack && isMuted) {
await micTrack.unmute();
setIsMuted(false);
}
};
const handleKeyUp = async (_e_: KeyboardEvent) => {
if (e.code === "Space" && micTrack && !isMuted) {
await micTrack.mute();
setIsMuted(true);
}
};
window.addEventListener("keydown", handleKeyDown);
window.addEventListener("keyup", handleKeyUp);
return () => {
window.removeEventListener("keydown", handleKeyDown);
window.removeEventListener("keyup", handleKeyUp);
};
}, [micTrack, isMuted]);
async function *fetchMicDevices*() {
try {
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
const devices = await navigator.mediaDevices.enumerateDevices();
const audioInputs = devices
.filter(d => d.kind === "audioinput")
.map(d => ({
label: d.label || "Microphone",
value: d.deviceId,
}));
setMicDevices(audioInputs);
stream.getTracks().forEach(track => track.stop());
} catch (err) {
console.error("Failed to get mic devices:", err);
Toaster({ variant: "error", message: "Please allow microphone permission." });
}
}
study this code and provide soluthintall-airline-16756
08/20/2025, 4:51 AMlate-businessperson-58140
08/20/2025, 4:52 AMtall-airline-16756
08/20/2025, 4:53 AMroom.connect()
call in a try-catch block: This way, you can catch any connection hiccups right away and handle them gracefully. For example:
try {
await room.connect(serverUrl, token);
} catch (error) {
console.error("Failed to connect to room:", error);
// Show a friendly error message to your user
}
1. Tap into SDK error events: Listen for events like onError
, onMediaDeviceFailure
, and onDisconnected
to catch specific issues as they happen. Here's how:
<LiveKitRoom
onError={(error) => {
console.error("Connection error:", error);
}}
onDisconnected={() => {
console.log("Disconnected from room");
}}
/>
1. Keep an eye on the room state: Check room.connectionState
to know what's going on with the connection and update your UI to keep users in the loop.
2. Run connection diagnostics: Use the ConnectionCheck
tool to test things like WebRTC, WebSocket, and TURN server connectivity. Here's a quick example:
import { ConnectionCheck } from '@livekit/client-sdk';
const checker = new ConnectionCheck({ url, token });
const webrtcResult = await checker.checkWebRTC();
const turnResult = await checker.checkTURN();
1. Keep your users informed: Show clear, friendly error messages—maybe with toast alerts or modals—and give them easy options to try reconnecting.
Following these steps will help you handle connection issues smoothly and make the experience better for everyone. If you want to chat more or need a hand, just let me know!
Sources: Web and mobile frontends | LiveKit Docs | Diagnosing Connection Errors with Connection Test Utility | Web Embed Example | livekit/livekit_composite | DeepWiki | src/room/errors.ts | Swift quickstart | LiveKit Docs