facebook twitter hatena line email

Unity/Agora/voicechat community/token取得

提供: 初心者エンジニアの簡易メモ
2022年12月13日 (火) 16:35時点におけるAdmin (トーク | 投稿記録)による版

移動: 案内検索

1日有効な本番token取得

  1. https://console.agora.io/ にアクセス
  2. stageをliveに
  3. Generate temp RTC tokenを選択して、チャンネル名を入れてtokenを取得
  4. サンプルのClientManagerTestシーンの、CanvasVideoのInspectorにあるuseTokenを、falseにして、token文字列を設置するとつながる

本番tokenをワンタイムtoken経由で取得する

  1. サンプルのClientManagerTestシーンだと、"VideoCanvas"のGameObjectとかに、TokenClientを、AddComponentする
  2. ServerURLを入れる。(ttp://localhost:8080/ な感じ。この場合ttp://localhost:8080/rte/testing/publisher/uid/1234/?3600 にアクセスされる)

useTokenをtrueにすることでエラーになる

ArgumentNullException: String reference not set to an instance of a String.
Parameter name: source

GetRtcToken()内の以下場所で、serverURLが、nullなので、エラーが出てるっぽい。

if (!serverURL.StartsWith("http"))

TokenClientを、どこかのGameObjectにAddComponentしてServerURLを設定すれば良い。

serverURLを入れる必要がありそう

///    The helper class gets the token from a server endpoint conformed to
/// format like this:
///   http://localhost:8080/rte/testing/publisher/uid/1234/?3600
/// See the GitHub project for compatible server code in GoLang:
///   https://github.com/AgoraIO-Community/agora-token-service

golangでワンタイムtokenを設定

https://github.com/AgoraIO-Community/agora-token-service

agora-token-service設定

$ git clone https://github.com/AgoraIO-Community/agora-token-service.git
$ cp .env.example .env

.envを設定

APP_ID=
APP_CERTIFICATE=
$ go run cmd/main.go

phpでワンタイムtokenを取得する

git clone https://github.com/AgoraIO/Tools.git
$ agora-token/Tools/DynamicKey/AgoraDynamicKey/php をサーバーへ設置する。
  1. AccessToken2Sample.phpを確認する
  2. serverURLにttp://localhost:8080/php/sample/AccessToken2Sample.php?を設置する
  3. 処理すると、ttp://localhost:8080/php/sample/AccessToken2Sample.php?/rtc/unity3d/publisher/uid/0/?expiry=3600 が実行される。
  4. このときrtcとuidの取得方法は、以下の通り。
if (preg_match("!/rtc/([\d\w]+)!", $_SERVER['QUERY_STRING'], $matches)) {
    $channelName = $matches[0];
}
if (preg_match("!/uid/([\d\w]+)!", $_SERVER['QUERY_STRING'], $matches)) {
    $uid = $matches[0];
    $uidStr = $matches[0];
}

戻り値はjsonで

echo json_encode(array('rtcToken' => $token, 'rtmToken' => $token));