This is an example of a simple Node/Express server that generates tokens for Agora applications.
- Install the dependencies
npm install
- Create a copy of the
.env.example
file and save it as.env
- Add your Agora App ID and App Certificate:
APP_ID=ca123xxxxxx
APP_CERTIFICATE=12za123xxxxxx
You can obtain these values by selecting your project in the Agora console projects section. Optionally, you can also define a port.
- Start the service
npm start
endpoint structure
/ping
response:
{"message":"pong"}
The rtc
token endpoint requires a channelName
, role
('publisher' or 'audience'), tokentype
('uid' || 'userAccount') and the user's uid
(type varies based on tokentype
(example: 1000
for uid, ekaansh
for userAccount).
(optional)
Pass an integer to represent the token lifetime in seconds.
endpoint structure
/rtc/:channelName/:role/:tokentype/:uid/?expiry=
response:
{"rtcToken":" "}
The rtm
token endpoint requires the user's uid
.
(optional)
Pass an integer to represent the privelege lifetime in seconds.
endpoint structure
/rtm/:uid/?expiry=
response:
{"rtmToken":" "}
The rte
token endpoint generates both the rtc
and rtm
tokens with a single request.
(optional)
Pass an integer to represent the token lifetime in seconds.
endpoint structure
/rte/:channelName/:role/:tokentype/:uid/?expiry=
response:
{
"rtcToken":" ",
"rtmToken":" "
}