Tokens for Vivox Developer Portal users

If you are a developer coming from the Vivox Developer Portal and intend to continue using the credentials provided, there are steps needed before initializing the Vivox SDK.

The following code sample is an example of the setup:

public class VoiceManager : MonoBehaviour
{
    async void Start()
    {
        // Must be done before any other Vivox action otherwise tokens will not be generated for them properly.
        VivoxService.Instance.SetTokenProvider(new VivoxTokenProvider());
        InitializationOptions options = new InitializationOptions().SetVivoxCredentials(server, domain, issuer);
        await UnityServices.InitializeAsync(options);
        await VivoxService.Instance.InitializeAsync();
    }
}

class VivoxTokenProvider : IVivoxTokenProvider
{
    public Task<string> GetTokenAsync(string issuer = null, TimeSpan? expiration = null, string targetUserUri = null, string action = null, string channelUri = null, string fromUserUri = null, string realm = null)
    {
        // Implement token fetching logic here.
        // The method parameters contain the necessary information for crafting the request payload.
        // This will be called any time we need a token for a Vivox action!
    }
}

Note: If you do not have server-side token vending set up, you can generate tokens locally for testing by placing your Vivox Secret Key into the InitializationOptions().SetVivoxCredentials() call.

Outside of development, local token generation should not be used as it requires caching the secret key on the client.

When generating local tokens, you do not need to create an implementation of IVivoxTokenProvider and register it with the VivoxService.

The following code is an example of the setup without IVivoxTokenProvider:

public class VoiceManager : MonoBehaviour
{
    async void Start()
    {
        InitializationOptions options = new InitializationOptions().SetVivoxCredentials(server, domain, issuer, secretKey);
        await UnityServices.InitializeAsync(options);
        await VivoxService.Instance.InitializeAsync();
    }
}