void Update()
    {
        if (wwwcall != null && wwwcall.IsDone && meshKey == 0 && isRegistered == false)
        {
            if (wwwcall.Error != null)
            {
                Debug.Log("error registering: " + wwwcall.Error);
            }
            else
            {
                var result = Json.Deserialize(wwwcall.Text) as Dictionary <string, object>;

                if ((bool)result["result"])
                {
                    isRegistered = true;
                    meshKey      = (int)((long)result["key"]);
                    meshSlot     = (int)((long)result["index"]);

                    if (sendDataTimer == null)
                    {
                        sendDataTimer = new System.Threading.Timer(SendData, null, 1000, 100);
                    }
                }
                else
                {
                    isRegistered = false;
                    Debug.Log("Unable to register: " + (string)result["error"]);
                }
            }
            wwwcall = null;
        }

        //Debug.LogFormat("meshKey {0} isRegistered {1} needsToSend {2} meshToSend {3} wwwcall{4}", meshKey, isRegistered, needsToSend, meshToSend, wwwcall);
    }
Exemple #2
0
        public IRequest Recognize(string audioFilePath, string lang, int sampleRate = 0)
        {
            string url              = string.Format(URL_V2, lang, config.key);
            string audioFileName    = Path.GetFileName(audioFilePath);
            string audioContentType = NetworkUtils.MapContentTypeFromPath(audioFileName) + ((sampleRate != 0) ? ("; rate=" + sampleRate) : (""));

            FileStream audioFileStream = null;

            audioFileStream = new FileStream(audioFilePath, FileMode.Open, FileAccess.Read);
            BinaryReader reader = new BinaryReader(audioFileStream);

            byte[] binaryData = reader.ReadBytes((int)audioFileStream.Length);

            reader.Close();
            audioFileStream.Close();

            if (null != binaryData)
            {
                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Content-Type", audioContentType);

                IRequest request = new RequestWWW(url, binaryData, headers);

                return(request);
            }
            else
            {
                Log.Error("binaryData is null");
                return(null);
            }
        }
 public void Update()
 {
     if (wwwcall != null && wwwcall.IsDone)
     {
         Debug.Log(wwwcall.Error);
         Debug.Log(wwwcall.Text);
         wwwcall = null;
     }
 }
    public void Register()
    {
        var regMsg = new Dictionary <string, object>();

        regMsg.Add("author", authorName);
        regMsg.Add("title", title);
        regMsg.Add("platform", "Unity3D");

        byte[] registration = Encoding.UTF8.GetBytes(Json.Serialize(regMsg));

        wwwcall = new RequestWWW();
        StartCoroutine(wwwcall.doHttpPost(rootServerUrl + "/mesh/register", registration, -1));
    }
    void Update()
    {
        if (wwwcall != null && wwwcall.IsDone && meshKey == 0 && isRegistered == false)
        {
            if (wwwcall.Error != null)
            {
                Debug.Log("error registering: " + wwwcall.Error);
            }
            else
            {
                var result = Json.Deserialize(wwwcall.Text) as Dictionary <string, object>;

                if ((bool)result["result"])
                {
                    isRegistered = true;
                    meshKey      = (int)((long)result["key"]);
                    meshSlot     = (int)((long)result["index"]);
                }
                else
                {
                    isRegistered = false;
                    Debug.Log("Unable to register: " + (string)result["error"]);
                }
            }
            wwwcall = null;
        }
        else if (meshKey != 0 && isRegistered == true && needsToSend == true && meshToSend != null)
        {
            if (wwwcall == null)
            {
                wwwcall = new RequestWWW();
                serializer.Serialize(meshToSend);
                StartCoroutine(wwwcall.doHttpPost(rootServerUrl + "/mesh/" + meshSlot + "/frame", serializer.packet, meshKey));
            }
            else if (wwwcall != null && wwwcall.IsDone)
            {
                wwwcall = null;
            }
        }
    }
 private void SomeMethod()
 {
     wwwcall = new RequestWWW();
     StartCoroutine(wwwcall.GetXMLCoroutine("http://ya.ru"));
 }
Exemple #7
0
 private void SomeMethod()
 {
     StartCoroutine(RequestWWW.GetXMLCoroutine("http://ya.ru/", RequestFinished));
 }