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!
}
}
ノート: サーバー側トークンベンディングの設定がない場合は、Vivox 秘密鍵を InitializationOptions().SetVivoxCredentials()
呼び出しに配置して、テスト用にローカルでトークンを生成できます。
クライアント上で秘密鍵のキャッシュが必要になるため、ローカルトークンの生成は開発外で使用しないでください。
ローカルトークンを生成する際に、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();
}
}