facebook twitter hatena line email

「Unity/Agora/voicechat community/token取得」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(phpでワンタイムtokenを取得する)
(useTokenをtrueにすることでエラーになる)
行9: 行9:
 
#ServerURLを入れる。(ttp://localhost:8080/ な感じ。この場合ttp://localhost:8080/rte/testing/publisher/uid/1234/?3600 にアクセスされる)
 
#ServerURLを入れる。(ttp://localhost:8080/ な感じ。この場合ttp://localhost:8080/rte/testing/publisher/uid/1234/?3600 にアクセスされる)
  
===useTokenをtrueにすることでエラーになる===
+
===useTokenをtrueにすることでエラーになる場合===
 
<pre>
 
<pre>
 
ArgumentNullException: String reference not set to an instance of a String.
 
ArgumentNullException: String reference not set to an instance of a String.
 
Parameter name: source
 
Parameter name: source
 
</pre>
 
</pre>
 
GetRtcToken()内の以下場所で、serverURLが、nullなので、エラーが出てるっぽい。
 
if (!serverURL.StartsWith("http"))
 
 
 
TokenClientを、どこかのGameObjectにAddComponentしてServerURLを設定すれば良い。
 
TokenClientを、どこかのGameObjectにAddComponentしてServerURLを設定すれば良い。
  

2022年12月14日 (水) 17:58時点における版

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

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. RtcTokenBuilderSample.phpを確認する
  2. serverURLにttp://localhost:8080/php/sample/RtcTokenBuilderSample.php?を設置する
  3. 処理すると、ttp://localhost:8080/php/sample/RtcTokenBuilderSample.php?/rtc/unity3d/publisher/uid/0/?expiry=3600 が実行される。
  4. このときrtcとuidの取得方法は、以下の通り。
if (preg_match("!/rtc/([\d\w]+)!", $_SERVER['QUERY_STRING'], $matches)) {
    $channelName = $matches[1];
}
if (preg_match("!/uid/([\d\w]+)!", $_SERVER['QUERY_STRING'], $matches)) {
    $uid = $matches[1];
    $uidStr = $matches[1];
}

戻り値はjsonで

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

CAN_NOT_GET_GATEWAY_SERVERとなる場合

エラー詳細

Agora-SDK [ERROR]: [client-1513c] join number: 1, Joining channel failed, rollback AgoraRTCException: AgoraRTCError CAN_NOT_GET_GATEWAY_SERVER: flag: 4096, message: AgoraRTCError CAN_NOT_GET_GATEWAY_SERVER: invalid token, authorized failed
  • AccessToken2Sample.phpではなく、RtcTokenBuilderSample.phpの方を使う。
  • token文字列がおかしいので、channelNameがちゃんと設定されてるか確認する。