Hi LiveKit Team,
One of my users experienced an issue where the interview session was suddenly closed during an ongoing interview. In the browser console, I observed the following error:
error in room ConnectionError: could not establish signal connection: invalid token
at nc. (6295.dd10fa3c.chunk.js:1:417095)
at Generator.next ()
at a (6295.dd10fa3c.chunk.js:1:120778)
Could you please help me understand the possible reasons for this error and how to prevent it? This is very critical for us since interviews should not be interrupted once they start.
Room Id : RM_Z2UGUdvv7E9y
Perhaps an expired token? There are some troubleshooting steps in this guide: Troubleshooting 401 Unauthorized and Token Errors | LiveKit
Could this be the issue?
Currently I am generating the token like this:
const at = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET, {
identity: participantName,
name: participantName,
ttl: 5 * 60
});
I set the TTL to only 5 minutes, but my interviews sometimes last longer (10 minutes, 25 minutes, or even 60 minutes).
I am planning to change the code to the following. Could you please confirm if this approach is correct?
const at = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET, {
identity: participantName,
name: participantName,
ttl: duration * 60 + 300 // interview duration in minutes converted to seconds + 5 minutes buffer
});
The token only needs to be valid for the initial join, you don’t need to set the TTL to cover the entire expected duration of the call. Client reconnects should be handled automatically by refreshed tokens: Tokens & grants | LiveKit Documentation
If you look at the events for the room (the link you shared above), it says the participant left with CONNECTION_TIMEOUT, I wonder if the participant left for whatever reason (network?) and then tried to join at a later time after the room was closed, which resulted in the token errors.
Should I change the logic to: Do not delete the room when a participant leaves,
but delete it if they did not re-join within 1 minute?
If yes, how can I do that?
Yes, that will work. You can set the departure_timeout on the Room options: Room service API | LiveKit Documentation
If you are creating the room manually, you can set it on CreateRoom: Room service API | LiveKit Documentation
If you are creating the room automatically, you can set it on the participant’s token: Tokens & grants | LiveKit Documentation
1 Like
Could you plz confirm if I’m correct
await roomService.createRoom({ name: roomName, maxParticipants: 3, departureTimeout : 60 })
const egressInfo = await egressClient
.startRoomCompositeEgress(roomName, output, {
audioOnly: true,
audioMixing: AudioMixing.DUAL_CHANNEL_AGENT, // agent-left, others-right
})
const agentDispatchClient = new AgentDispatchClient(
LIVEKIT_URL,
LIVEKIT_API_KEY,
LIVEKIT_API_SECRET,
);
await agentDispatchClient.createDispatch(roomName, agentName, {
metadata,
});
const at = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET, {
identity: participantName,
name: participantName,
ttl: duration * 60 + 300, // duration in minutes for token validity + 5 minutes buffer
});
at.addGrant({ roomJoin: true, room: roomName });
const token = await at.toJwt();
return { liveKitUrl: LIVEKIT_URL, token, roomName, agentName };
I am using the above token in Frontend SDK
-
It will allow the user to re-join within 1 minute if they leave the room.
-
I want to start recording the room when the participant joins. This means the recording should start from the frontend as soon as the user enters the room.
const room = useRoomContext()
room.state === "connected"
For egress, it might be easier to use the egress parameter in the CreateRoom API, Room service API | LiveKit Documentation, which will trigger Auto egress, Auto egress | LiveKit Documentation
Also, now you have set departure_timeout, it should not be necessary for your token ttl to exceed the duration of the call.