"""Generate LiveKit access tokens for the camera participants.""" from livekit.api import AccessToken, VideoGrants def make_token(url: str, api_key: str, api_secret: str, room: str, identity: str, attributes: dict[str, str] | None = None) -> str: token = ( AccessToken(api_key, api_secret) .with_identity(identity) .with_name(identity) .with_grants(VideoGrants( room_join=True, room=room, can_publish=True, can_subscribe=False, can_publish_data=True, )) ) if attributes: token = token.with_attributes(attributes) return token.to_jwt() def make_speaker_token(api_key: str, api_secret: str, room: str, identity: str = "speaker", name: str = "") -> str: """Publisher token so a speaker can join and share their screen.""" token = ( AccessToken(api_key, api_secret) .with_identity(identity) .with_name(name or identity) .with_grants(VideoGrants( room_join=True, room=room, can_publish=True, can_subscribe=True, can_publish_data=True, )) ) return token.to_jwt() def make_viewer_token(api_key: str, api_secret: str, room: str, identity: str) -> str: """Subscribe-only token for headless display clients.""" token = ( AccessToken(api_key, api_secret) .with_identity(identity) .with_name(identity) .with_grants(VideoGrants( room_join=True, room=room, can_publish=False, can_subscribe=True, can_publish_data=False, )) ) return token.to_jwt()