Skip to content

Repository files navigation

UnityTokenPrefab

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.

How to use this prefab

  1. Download the ClientToken.unitypackage from the release here. Which belongs to the GitHub repo for this prefab’s source.

  2. On Unity Editor, import the package from Assets->Import Package->Custom Package

  3. Drag the TokenClient prefab from Assets/AgoraEngine/Utils to the scene.

  4. Fill the information in the TokenClient’s properties (See picture below)

  5. Client Type - select Publisher or Subscriber. Note you may also assign this in code. E.g.
    TokenClient.Instance.SetClient(ClientType.publisher);

  6. AppID: the App ID for your project. It is assumed you use the same AppID for both RTC and RTM engines.

  7. serverURL: the endpoint that serves the query

  8. ExpiractionSecs: how long the token lives

  9. 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);

Server Side

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:

  1. set up your GoLang environment,
  2. clone the Repo,
  3. install Gin framework,
  4. set your environment variable (AppID and AppCertificate)
  5. run main.go

About

[TokenClient] A low code prefab helps token get and renew

Resources

Stars

1 star

Watchers

4 watching

Forks

Releases

Packages

Contributors

Languages