Vivox 开发者门户用户的令牌
Auto-generated from developer-portal-token-generation.md
阅读时间1 分钟最后更新于 2 天前
如果您是来自 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! }}
在开发之外,不应使用本地令牌生成功能,因为它需要在客户端上缓存密钥。
生成本地令牌时,无需创建 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(); }}