[11:24:59.011] INFO (35643): received job request ...
# ask-ai
r
[112459.011] INFO (35643): received job request version: "0.1.0" job: { "id": "AJ_j4pzPxHc97dP", "type": "JT_ROOM", "room": { "sid": "RM_y8Qxf6nSWbny", "name": "a471bad1-69a3-497b-a1ac-883960556eab", "emptyTimeout": 300, "maxParticipants": 0, "creationTime": "1757915698", "turnPassword": "", "enabledCodecs": [ { "mime": "video/H264", "fmtpLine": "" }, { "mime": "video/VP8", "fmtpLine": "" }, { "mime": "video/VP9", "fmtpLine": "" }, { "mime": "video/AV1", "fmtpLine": "" }, { "mime": "audio/red", "fmtpLine": "" }, { "mime": "audio/opus", "fmtpLine": "" } ], "metadata": "", "numParticipants": 0, "activeRecording": false, "numPublishers": 0, "version": { "unixMicro": "1757915698994033", "ticks": 0 }, "departureTimeout": 20, "creationTimeMs": "1757915698749" }, "namespace": "", "metadata": "", "agentName": "", "state": { "status": "JS_RUNNING", "error": "", "startedAt": "1757915699114912222", "endedAt": "0", "updatedAt": "1757915699114912222", "participantIdentity": "", "workerId": "AW_VCuGsuy3iMxS", "agentId": "A_PZpBBGPqP8sv" }, "dispatchId": "" } resuming: false agentName: "" [112459.809] ERROR (35975): room is not connected jobID: "AJ_j4pzPxHc97dP" err: { "type": "Error", "message": "room is not connected", "stack": Error: room is not connected at JobContext.waitForParticipant (file:///Users/hrithiksampson/livekit-app/backend/node_modules/.pnpm/@livekit+agents@1.0.3_@livekit+rtc-node@0.13.18/node_modules/@livekit/agents/dist/job.js8213) at entry (file///Users/hrithiksampson/livekit app/backend/dist/agent.js102:39) at file:///Users/hrithiksampson/livekit-app/backend/node_modules/.pnpm/@livekit+agents@1.0.3_@livekit+rtc-node@0.13.18/node_modules/@livekit/agents/dist/ipc/job_proc_lazy_main.js7245 at AsyncLocalStorage.run (nodeasync hooks346:14) at runWithJobContextAsync (file:///Users/hrithiksampson/livekit-app/backend/node_modules/.pnpm/@livekit+agents@1.0.3_@livekit+rtc-node@0.13.18/node_modules/@livekit/agents/dist/job.js1628) at file:///Users/hrithiksampson/livekit-app/backend/node_modules/.pnpm/@livekit+agents@1.0.3_@livekit+rtc-node@0.13.18/node_modules/@livekit/agents/dist/ipc/job_proc_lazy_main.js7211 at new Promise (<anonymous>) at startJob (file:///Users/hrithiksampson/livekit-app/backend/node_modules/.pnpm/@livekit+agents@1.0.3_@livekit+rtc-node@0.13.18/node_modules/@livekit/agents/dist/ipc/job_proc_lazy_main.js6316) at process.messageHandler (file:///Users/hrithiksampson/livekit-app/backend/node_modules/.pnpm/@livekit+agents@1.0.3_@livekit+rtc-node@0.13.18/node_modules/@livekit/agents/dist/ipc/job_proc_lazy_main.js15117) at process.emit (nodeevents518:28) } why is this errror coming
t
Thanks for reaching out, Hrithik. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Could you please let me know which LiveKit SDK you're using (like JavaScript, React Native, Flutter, or Swift) when you come across this error? Also, is this error happening while the app is running, showing up as a log message, or popping up as a specific exception? If you have the full error message or stack trace handy, sharing that would really help me understand what's going on and assist you better. Sources: quickstart/src/userfriendlyerror.js | docs/interfaces/LiveKitRoomProps.html | Sources/LiveKit/Core/Room.swift | livekit-rtc/livekit/rtc/room.py | Flutter SDK | livekit/livekit_composite | DeepWiki
r
javascript
t
It looks like you’re encountering the 'room is not connected' error in the LiveKit JavaScript SDK. This usually happens when you try to perform actions that need an active connection, but the room is still disconnected or in the process of connecting. Let’s walk through some common reasons and how you can fix them: • Common Causes: ◦ Trying to do things before
room.connect()
has finished. ◦ Performing actions after the room got disconnected, maybe due to network hiccups or the server disconnecting. ◦ Connection problems during
room.connect()
, like an invalid token or network troubles. ◦ Managing connection state incorrectly or running into race conditions. • Helpful Solutions: ◦ Make sure to await
room.connect()
before doing anything else. ◦ Use event listeners like
RoomEvent.SignalConnected
to know exactly when the room is ready. ◦ Check the
room.state
to confirm you’re connected before proceeding. ◦ Handle disconnections smoothly by listening for
RoomEvent.Disconnected
. ◦ Turn on debug logging to get more insight into what’s happening during connection attempts. ◦ Double-check that your browser and WebRTC setup support LiveKit properly. If you’re still running into trouble, it’s a good idea to verify your connection details like the
url
and
token
are correct, and make sure there aren’t any network or firewall issues blocking the WebSocket connection. I’m here to help, so please feel free to reach out if you want to go over this together or if you have any more questions! Sources: src/api/SignalClient.ts | Connecting to LiveKit | LiveKit Docs | example/sample.ts | docs/interfaces/LiveKitRoomProps.html
r
"use client"; import { ControlBar, RoomAudioRenderer, RoomContext } from '@livekit/components-react'; import { Room } from 'livekit-client'; import { useEffect, useState } from 'react'; import { twMerge } from 'tailwind-merge'; type RoomInfo = { id: string; roomName: string; userId: string; request: "PENDING" | "RESOLVED"; }; const serverUrl = "wss://call-gpt-g9awkea8.livekit.cloud"; export default function SupervisorDashboard() { const [rooms, setRooms] = useState<RoomInfo[]>([]); const [joinedRoom, setJoinedRoom] = useState<Room | null>(null); const [isMicOn, setIsMicOn] = useState(false); useEffect(() => { const fetchRooms = async () => { const res = await fetch("/api/getPendingRooms"); const data = await res.json(); setRooms(data.rooms || []); }; fetchRooms(); }, []); const joinRoom = async (_roomName_: string) => { const room = new Room({ adaptiveStream: true, dynacast: true, }); const participantName = `${roomName}-supervisor`; const tokenRes = await fetch("/api/createToken", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ participantName, roomName }), }); const { token } = await tokenRes.json(); await room.connect(serverUrl, token); console.log("Supervisor connected to room", roomName); setJoinedRoom(room); await fetch("/api/updateRoomStatus", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ roomName, status: "RESOLVED" }), }); }; const toggleMic = async () => { if (!joinedRoom) return; const enabled = !isMicOn; await joinedRoom.localParticipant.setMicrophoneEnabled(enabled); setIsMicOn(enabled); }; if (joinedRoom) { return ( <RoomContext.Provider value={joinedRoom}> <div className="text-center p-10"> <h2 className="text-xl font-bold mb-4">Supervisor Joined</h2> <button className={twMerge( "px-6 py-2 rounded text-white font-medium", isMicOn ? "bg-red-600" : "bg-green-600" )} onClick={toggleMic} > {isMicOn ? "Stop Mic" : "Start Mic"} </button> <div className="mt-10 w-full h-[300px]" data-lk-theme="default"> <RoomAudioRenderer /> <ControlBar controls={{ microphone: true, camera: false, screenShare: false }} /> </div> </div> </RoomContext.Provider> ); } return ( <div className="p-10 text-center"> <h1 className="text-2xl font-semibold mb-6">Pending Rooms</h1> {rooms.length === 0 ? ( <p>No pending rooms</p> ) : ( <ul className="space-y-4"> {rooms.map((room) => ( <li key={room.id} className="flex justify-between items-center bg-gray-100 p-4 rounded"> <span className="text-lg text-gray-800 font-serif">{room.roomName}</span> <button onClick={() => joinRoom(room.roomName)} className="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700" > Join </button> </li> ))} </ul> )} </div> ); } show me where
t
It seems the issue might be happening in the
joinRoom
function, especially when calling
room.connect(serverUrl, token)
. If the connection doesn’t go through successfully, actions like toggling the microphone or interacting with the room could run into the 'room is not connected' error. Let’s walk through some steps that can help you debug and resolve this: 1. Validate the Token: Double-check that the token generated by
/api/createToken
is valid and properly scoped for both the room and participant. 2. Check the Server URL: Make sure
wss://call-gpt-g9awkea8.livekit.cloud
is accessible and correctly set up. 3. Handle Connection Errors: It’s a great idea to wrap the
room.connect
call in a
try/catch
block. This way, you can catch and log any errors during the connection attempt:
Copy code
try {
  await room.connect(serverUrl, token);
  console.log("Supervisor connected to room", roomName);
} catch (error) {
  console.error("Failed to connect to room:", error.message);
}
1. Use Event Listeners: Adding listeners for
RoomEvent.SignalConnected
and
RoomEvent.Disconnected
can really help you keep track of the connection status and handle any disconnects smoothly. 2. Debug Logging: Turning on debug logging in the LiveKit client can give you more insights into what’s happening during connection:
Copy code
import { setLogLevel } from 'livekit-client';
setLogLevel('debug');
If you’d like, I’m here to help you with any of these steps or clarify anything further—just let me know!
r
"use client"; import { RoomContext, } from '@livekit/components-react'; import { useEffect, useState } from 'react'; import { Room } from 'livekit-client'; import '@livekit/components-styles'; import { v4 as uuidv4 } from 'uuid'; import LiveAudio from './LiveAudio'; const serverUrl = 'wss://call-gpt-g9awkea8.livekit.cloud'; // function MyVideoConference() { // //
useTracks
returns all camera and screen share tracks. If a user
// // joins without a published camera track, a placeholder track is returned. // const tracks = useTracks( // [ // { source: Track.Source.Microphone, withPlaceholder: true }, // ], // { onlySubscribed: false }, // ); // const trackRef = useEnsureTrackRef(); // return ( // <GridLayout tracks={tracks}> // {/* The GridLayout accepts zero or one child. The child is used // as a template to render all passed in tracks. */} // <ParticipantTile> // <AudioTrack trackRef={trackRef} /> // </ParticipantTile> // </GridLayout> // ); // } export default function LivekitRoom({roomName}: {roomName?: string}) { const [room] = useState(() => { return new Room({ adaptiveStream: true, dynacast: true, }) }); useEffect(() => { let mounted = true; if(!roomName) { roomName = uuidv4(); } const token = async () => { if(localStorage.getItem("call_gpt_token")) { return localStorage.getItem("call_gpt_token"); } const response = await fetch('/api/createToken', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ participantName:
${roomName}-user
, roomName: roomName, }), }); const data = await response.json(); return data.token; }; const connect = async () => { if (mounted) { await room.connect(serverUrl, await token()); console.log("Connected to room", roomName); } }; connect(); return () => { mounted = false; room.disconnect(); }; }, [room]); return ( <RoomContext.Provider value={room}> <LiveAudio room={room} /> </RoomContext.Provider> ); } can you dfind any mostake here
t
Thanks for sharing your code! Let’s walk through some areas that might be causing trouble: 1. Token Retrieval: First, double-check that your
/api/createToken
endpoint is working smoothly and giving back a valid token. If the token is expired or invalid, the connection won’t go through. 2. Local Storage Token: If you’re grabbing the token from
localStorage
, it’s a good idea to confirm it’s still valid. You might want to add a way to refresh the token automatically when needed. 3. Room Connection: I noticed the
room.connect
call is inside a check for
mounted
. Make sure
mounted
is set to
false
properly during cleanup to prevent any memory leaks or unexpected behavior. 4. Dependency Array: Your
useEffect
hook only depends on
room
. If
roomName
can change, consider adding it to the dependency array so the effect runs again when it updates. 5. Cleanup: The cleanup function calls
room.disconnect()
. Just double-check that this fully releases all resources and listeners tied to the room. To help narrow down the issue, you could add some error handling around your
room.connect
call like this:
Copy code
try {
  await room.connect(serverUrl, await token());
  console.log("Connected to room", roomName);
} catch (error) {
  console.error("Failed to connect to room:", error.message);
}
If you’d like, I’m here to help you dig deeper or clarify anything. Just let me know!