I'm trying to regenerate token from server using golang
When I host this url in localhost i get rtc and rtm token both in chrome site
http://localhost:8080/rte/agora/publisher/uid/1234/
Later I tried to connect with unity this is my webrequest in unity
public static class HelperClass
{
public static IEnumerator FetchToken(string url, string channel, int userId, Action<string> callback = null)
{
Debug.Log("Hitting Web Request");
UnityWebRequest request = UnityWebRequest.Get(string.Format("{0}/rtc/{1}/publisher/uid/{2}/", url, channel, userId));
yield return request.SendWebRequest();
if (request.isNetworkError || request.isHttpError)
{
Debug.Log("request"+request.error);
callback(null);
yield break;
}
TokenObject tokenInfo = JsonUtility.FromJson<TokenObject>(request.downloadHandler.text);
callback(tokenInfo.rtcToken);
}
}
this is my url i tried to get
internal static string _tokenBase = "http://localhost:8080/rte/agora/publisher/uid/";
and I run this using
StartCoroutine(HelperClass.FetchToken(_tokenBase, _channelName, 0, this.RenewOrJoinToken));
I tried to get auto generate token but I'm getting below issue
InvalidOperationException: UnityWebRequest has already been sent; cannot begin sending the request again
UnityEngine.Networking.UnityWebRequest.SendWebRequest () (at /Users/bokken/buildslave/unity/build/Modules/UnityWebRequest/Public/UnityWebRequest.bindings.cs:266)
Agora.Util.HelperClass+<FetchToken>d__0.MoveNext () (at Assets/Agora-RTC-Plugin/API-Example/Tools/RequestToken.cs:27)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/Coroutines.cs:17)
Sounds like the Coroutine is firing twice. Attach the debugger and set a breakpoint inside the FetchToken coroutine and see whether it fires twice (and check the callstack to see where from and inspect why).