steep-balloon-41261
07/04/2025, 5:09 PMtall-airline-16756
07/04/2025, 5:09 PMtall-airline-16756
07/04/2025, 5:09 PMAccessToken
class from the livekit-server-sdk
package. Here's a step-by-step guide:
1. Install the SDK: npm install livekit-server-sdk --save
2. Use the following code to create a token with the necessary permissions: import { AccessToken } from 'livekit-server-sdk';
// Room name to join
const roomName = 'name-of-room';
// Participant identity
const participantName = 'user-name';
// Create the access token with your API key and secret
const at = new AccessToken('api-key', 'secret-key', {
identity: participantName,
});
// Add permissions to join the room
at.addGrant({
roomJoin: true,
room: roomName,
canPublish: true, // Allow publishing tracks
canSubscribe: true // Allow subscribing to tracks
});
// Generate the JWT
const token = await at.toJwt();
console.log('access token', token);
3. Ensure the roomJoin
permission is set to true
and the room
field matches the room name you want to join. You can also customize permissions like canPublish
and canSubscribe
as needed.
4. Verify that the token expiration (TTL) is appropriate for your use case. By default, tokens expire after 6 hours, but you can set a custom expiration when creating the token.
If you are still encountering issues, double-check the room name, API key, and secret, and ensure the permissions align with your intended use case.
Sources: LiveKit JS Server SDK - v2.9.7 | Authentication | LiveKit Docsbreezy-teacher-58847
07/04/2025, 5:12 PMtall-airline-16756
07/04/2025, 5:12 PMbreezy-teacher-58847
07/04/2025, 5:14 PMtall-airline-16756
07/04/2025, 5:14 PMjavascript async function createRoomAccessToken(env) { const encoder = new TextEncoder(); const secret = encoder.encode(env.LIVEKIT_API_SECRET); const payload = { grants: { roomJoin: true, // Permission to join a room canPublish: true, // Permission to publish tracks canSubscribe: true, // Permission to subscribe to tracks room: 'your-room-name' // Specify the room name } }; const token = await new SignJWT(payload) .setProtectedHeader({ alg: 'HS256' }) .setSubject('user-identity') // Unique identifier for the user .setIssuer(env.LIVEKIT_API_KEY) .setIssuedAt() .setExpirationTime('1h') // Token expiration time .sign(secret); return token; }
Just swap out 'your-room-name'
and 'user-identity'
with your actual details, and make sure those API key and secret are set up in your environment variables. Easy peasy! ๐ If you hit any snags or something doesn't look quite right, just drop me a line with the specifics, and we'll troubleshoot together. I'm here to help! ๐ Sources: LiveKit JS Server SDK - v2.9.7breezy-teacher-58847
07/04/2025, 5:21 PMbreezy-teacher-58847
07/04/2025, 5:22 PMBearer ${adminToken}
,
},
body: JSON.stringify({
room_name: roomName,
sip_trunk_id: sipTrunkId,
number: phoneNumber,
}),tall-airline-16756
07/04/2025, 5:22 PMCreateSIPParticipant
API. Let me help you break this down in a friendly way. Think of the token like a special key that needs the right permissions to unlock what you're trying to do. Here's what you'll want to make sure is in your token: javascript const payload = { grants: { 'sip-admin': true, // Admin permission for SIP call: true, // Permission to make SIP calls roomJoin: true, // Permission to join the room room: 'your-room-name' // Specify the room name } };
A couple of quick things to double-check: - Make sure your Authorization
header is set up as Bearer ${adminToken}
- Confirm the room_name
in your request matches what's in the token If you're still seeing some hiccups, let's troubleshoot: 1. Verify your LIVEKIT_API_KEY
and LIVEKIT_API_SECRET
are spot on 2. Check that your room_name
is consistent across the board 3. Confirm those sip-admin
and call
permissions are included Don't worry, we'll get this sorted out! If the error is giving you any more trouble, just shoot over the details, and I'll be happy to help you work through it. ๐ Sources: Authentication | LiveKit Docs | livekit.api.sip_service API documentation