Access Token

Access Token

Access Token is a JWT token that is used to authenticate a peer to join a room. It contains the roomId, apiKey, role, permissions, and metadata.

💡

You can generate roomId using Create Room API.

To join a Huddle01 room, every peer needs a unique access token. You need apiKey and roomId to generate an access Token.

Make sure that you are using the same apiKey which you used to generate roomId.

Permissions

Access Token gives an ability to set your own custom permissions. Let's see each permission in detail.

PermissionDescription
adminThe peer will have admin privileges. Admins can perform all actions on the room.
canConsumeThe peer will be able to consume tracks from other peers.
canProduceThe peer will be able to publish tracks to the room.
canProduceSourcesThe peer will be able to publish tracks from the specified sources such as `cam`, `mic`, and `screen`.
canRecvDataThe peer will be able to receive data messages from other peers.
canSendDatathe peer will be able to send data messages to other peers.
canUpdateMetadataThe peer will be able to update its own metadata.

Role

You can set a role from the following list of roles, or you can create your own custom role as well.

If you create a custom role, you can give custom permission. Predifined roles have predefined permissions.

RoleDescription
hostHosts can perform all actions on the room, they have `admin` as a true in permissions.
coHostCo-hosts can perform all actions on the room just like `host`, but they can't update role to `host`.
guestGuests can can publish all tracks and send/receive data to the room, but can't perform admin actions.
speakerSpeakers can publish only `audio` tracks to the room, and remaining same as `guest` role.
listenerListeners can consume tracks and send/receive data from other peers.
botThis can only consume tracks from other peers and won't able to send/receive data unlike `listener`

To get access these pre-defined roles, you can import Role from Server SDK.

import { Role } from '@huddle01/server-sdk/auth';
 
// Access Host Role 
console.log(Role.HOST);

Generating Access Token

You need to create an instance of AccessToken where you can pass permission, role and metadata.

💡

metadata can be of any type.

import { AccessToken, Role } from '@huddle01/server-sdk/auth';
 
const accessToken = new AccessToken({
    apiKey: 'YOUR_API_KEY',
    roomId: 'YOUR_ROOM_ID',
    //available roles: Role.HOST, Role.CO_HOST, Role.SPEAKER, Role.LISTENER, Role.GUEST - depending on the privileges you want to give to the user
    role: Role.HOST,
    //custom permissions give you more flexibility in terms of the user privileges than a pre-defined role
    permissions: {
          admin: true,
          canConsume: true,
          canProduce: true,
          canProduceSources: {
            cam: true,
            mic: true,
            screen: true,
          },
          canRecvData: true,
          canSendData: true,
          canUpdateMetadata: true,
        },
        options: {
          metadata: { 
             // you can add any custom attributes here which you want to associate with the user
            walletAddress: "mizanxali.eth"
          },
        },
  });
 
const token = accessToken.toJwt();
 
Audio/Video Infrastructure designed for the developers to empower them ship simple yet powerful Audio/Video Apps.
support
company
Copyright © 2024 Graphene 01, Inc. All Rights Reserved.