big-controller-60015
05/16/2025, 9:23 AMtall-airline-16756
05/16/2025, 9:23 AMtall-airline-16756
05/16/2025, 9:24 AMAccessToken
class from the LiveKit server SDK. Here’s an example:
import { AccessToken } from 'livekit-server-sdk';
const roomName = 'name-of-room';
const participantName = 'user-name';
const at = new AccessToken('api-key', 'secret-key', {
identity: participantName,
});
at.addGrant({ roomJoin: true, room: roomName });
const token = await at.toJwt();
By default, tokens expire after 6 hours, but this can be customized by setting a TTL (time to live) value.
Sources: Connecting to LiveKit | LiveKit Docs | LiveKit JS Server SDK - v2.9.7big-controller-60015
05/16/2025, 9:28 AMtall-airline-16756
05/16/2025, 9:28 AMfrom livekit_server_sdk import AccessToken, VideoGrant
# Define your API key and secret key
api_key = "your-api-key"
secret_key = "your-secret-key"
# Define room and participant details
room_name = "example-room"
participant_identity = "example-user"
# Create a VideoGrant object with permissions
grant = VideoGrant(
room_join=True, # Allow joining the room
room=room_name, # Specify the room name
can_publish=True, # Allow publishing tracks
can_subscribe=True, # Allow subscribing to tracks
can_publish_data=True # Allow publishing data
)
# Create an AccessToken object
token = AccessToken(
api_key=api_key,
secret_key=secret_key,
identity=participant_identity,
grant=grant
)
# Optionally, set additional options
token.ttl = 3600 # Token expiration time in seconds (1 hour)
# Generate the token
jwt_token = token.to_jwt()
print("Generated Token:", jwt_token)
This example includes options for joining a room, publishing tracks, subscribing to tracks, and publishing data. You can modify the permissions and add other options as needed. Let me know if you need further assistance!big-controller-60015
05/16/2025, 9:39 AMtall-airline-16756
05/16/2025, 9:39 AMroom_create
option in VideoGrants
is a boolean parameter that grants permission to create rooms in LiveKit. When this permission is set to True
, the token holder is allowed to create rooms in the LiveKit system.
Let me know if you need further clarification or assistance!
Sources: livekit.api.access_token API documentationbig-controller-60015
05/16/2025, 10:29 AMtall-airline-16756
05/16/2025, 10:30 AMttl
(time-to-live) parameter when creating the token.
The ttl
can be defined in seconds or as a string describing a time span, such as '2 days'
or '10h'
. For example:
const at = new AccessToken('api-key', 'secret-key', {
identity: participantName,
ttl: '10h' // Sets expiration to 10 hours
});
Let me know if you need further assistance!
Sources: LiveKit JS Server SDK - v2.9.7 | AccessTokenOptions | LiveKit JS Server SDK - v2.9.7