A low code prefab helps to get and renew tokens for RTC and RTM engine. Note that the RTM code is commented out. Uncommit to use with RTM.
-
Download the ClientToken.unitypackage from the release here. Which belongs to the GitHub repo for this prefab’s source.
-
On Unity Editor, import the package from Assets->Import Package->Custom Package
-
Drag the TokenClient prefab from Assets/AgoraEngine/Utils to the scene.
-
Fill the information in the TokenClient’s properties (See picture below)
-
Client Type - select Publisher or Subscriber. Note you may also assign this in code. E.g.
TokenClient.Instance.SetClient(ClientType.publisher); -
AppID: the App ID for your project. It is assumed you use the same AppID for both RTC and RTM engines.
-
serverURL: the endpoint that serves the query
-
ExpiractionSecs: how long the token lives
-
You will need to make calls from your main controller to assign the necessary engine instances and initiate GetToken. Sample code snippet below:
// assign user id here, or use 0 for local user uint uid = 0; string UserName = "Me"; TokenClient.Instance.RtcEngine = mRtcEngine; TokenClient.Instance.RtmClient = mRtmClient; TokenClient.Instance.GetTokens(channel, uid, (rtcToken, rtmToken) => { // join channel with token mRtcEngine.JoinChannelByKey(rtcToken, channel, null, uid); mRtmClient.Login(rtmToken, UserName); } ); // join channel without token // mRtcEngine.JoinChannel(channel, null, uid);
The endpoint query URLs that the Token Client are conforming to the sample server project as described in this blog: How to Build a Token Server for Agora Applications using GoLang Its GoLang example's complete server code is in this Repo. To recap, these are quick start steps:
- set up your GoLang environment,
- clone the Repo,
- install Gin framework,
- set your environment variable (AppID and AppCertificate)
- run main.go