Ejemplo n.º 1
0
    private void ParseReturn <T>(HTTPRequest originalRequest, HTTPResponse response, SendTypes type, Action <ReturnTypes, T, int> action)
    {
        if (response == null)
        {
            RKLog.LogError("Parsereturn, response null ", "apicontroller");
            action(ReturnTypes.ERROR, (T)(object)null, 1);
            return;
        }

        GenericData       returnResponse = new GenericData();
        SendValueResponse res;
        int returnerror;

        //Debug.Log("parsereturn 2!");
        //        Debug.LogError("dit is iets ervoor");
        //        Debug.LogError(response.DataAsText);



        ReturnTypes returntype;

        switch (type)
        {
        default:
            RKLog.Log("response: " + response.DataAsText);

            res = JsonUtility.FromJson <SendValueResponse>(response.DataAsText);
            foreach (ResponseStringList val in res.strings)
            {
                Debug.Log("set3: " + val.key + " to " + val.value);
                returnResponse.Set(val.key, val.value);
            }

            foreach (ResponseIntList val in res.ints)
            {
                returnResponse.Set(val.key, val.value);
            }

            returntype  = ReturnTypes.ERROR;
            returnerror = -1;

            if (res.success)
            {
                returntype = ReturnTypes.SUCCESS;
            }

            RKLog.Log("returntype: " + returntype + " returnresponse: " + returnResponse + " res error: " + res.error);
            action(returntype, (T)(object)returnResponse, res.error);


            break;
        }
    }
Ejemplo n.º 2
0
    public void Send(int userid, string type, GenericData data)
    {
        GenericData send = new GenericData();

        send.Set("to", userid);
        send.Set("type", type);
        send.Set("msg", JsonConvert.SerializeObject(data.GetValues()));
        string finaldata = JsonConvert.SerializeObject(send.GetValues());

        RKLog.Log("send request to socket " + finaldata, "socketcontroller");

        _websocket.Send(finaldata);
    }
Ejemplo n.º 3
0
    private void OnMessageReceived(WebSocket webSocket, string message)
    {
        RKLog.Log("OnMessageReceived: " + message, "socketcontroller");
        SocketResponse data = JsonUtility.FromJson <SocketResponse>(message);

        GenericData gd = new GenericData();

        foreach (ResponseStringList item in data.data)
        {
            gd.Set(item.key, item.value);
        }

        RKLog.Log("invoke: " + gd.ToString(), "socketcontroller");

        MessageReceived.Invoke(data.type, gd);

        if (data.type == "update")
        {
            RKLog.Log("onmessagereceived, update: " + gd.ToString() + " dus poll", "socketcontroller");
        }
    }