Vivox 开发者门户用户令牌
如果您是来自 Vivox 开发者门户的开发者,并且打算继续使用提供的凭据,则在初始化 Vivox SDK 之前需要执行一些步骤。
以下代码示例是设置的示例
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.
在开发之外,不应该使用本地令牌生成,因为它需要在客户端缓存密钥。
在生成本地令牌时,您不需要创建 IVivoxTokenProvider 的实现并在 VivoxService 中注册它。
以下代码是无 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();
}
}