Esempio n. 1
0
    public void Connect()
    {
        Debug.Log("connecting to " + serverUrl);
        ddpConnection = new DdpConnection(serverUrl);
        ddpConnection.OnDebugMessage += (string message) =>
        {
            Debug.Log(message);
        };
        ddpConnection.OnConnected += (DdpConnection connection) => {
            Debug.Log("connected!");
            ddpConnection.Subscribe("cube");
            ddpConnection.Subscribe("sphere");
            ddpConnection.Subscribe("monkey");
        };

        ddpConnection.OnError += DdpConnection_OnError;
        SetupDB();
        ddpConnection.Connect();
    }
Esempio n. 2
0
    public void Update()
    {
        if (Input.GetKeyDown(KeyCode.C))
        {
            Debug.Log("Connecting ...");
            ddpConnection.Connect();
        }

        if (Input.GetKeyDown(KeyCode.V))
        {
            Debug.Log("Closing connection ...");
            ddpConnection.Close();
        }

        if (Input.GetKeyDown(KeyCode.S))
        {
            friendSub         = ddpConnection.Subscribe("friends");
            friendSub.OnReady = (Subscription obj) => {
                Debug.Log("Ready subscription: " + obj.id);
            };
        }

        if (Input.GetKeyDown(KeyCode.U))
        {
            ddpConnection.Unsubscribe(friendSub);
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            ddpConnection.Call("friends.removeAll");
        }

        if (Input.GetKeyDown(KeyCode.F))
        {
            MethodCall methodCall = ddpConnection.Call("friends.create", JSONObject.CreateStringObject("Coco"));
            methodCall.OnUpdated = (MethodCall obj) => {
                Debug.Log("Updated, methodId=" + obj.id);
            };
            methodCall.OnResult = (MethodCall obj) => {
                Debug.Log("Result = " + obj.result);
            };
        }

        if (Input.GetKeyDown(KeyCode.A))
        {
            MethodCall methodCall = ddpConnection.Call("friends.add", JSONObject.Create(7), JSONObject.Create(5));
            methodCall.OnUpdated = (MethodCall obj) => {
                Debug.Log("Updated, methodId=" + obj.id);
            };
            methodCall.OnResult = (MethodCall obj) => {
                Debug.Log("Result = " + obj.result);
            };
        }
    }
Esempio n. 3
0
    public void Update()
    {
        if (Input.GetKeyDown(KeyCode.C))
        {
            Debug.Log("Connecting ...");
            ddpConnection.Connect();
        }

        if (Input.GetKeyDown(KeyCode.V))
        {
            ddpConnection.Close();
        }

        if (Input.GetKeyDown(KeyCode.S))
        {
            friendSub         = ddpConnection.Subscribe("friends");
            friendSub.OnReady = (Subscription obj) => {
                Debug.Log("Ready subscription: " + obj.id);
            };
        }

        if (Input.GetKeyDown(KeyCode.U))
        {
            ddpConnection.Unsubscribe(friendSub);
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            ddpConnection.Call("friends.removeAll");
        }

        if (Input.GetKeyDown(KeyCode.F))
        {
            ddpConnection.Call("friends.create", JSONObject.CreateStringObject("Coco"));
        }

        if (Input.GetKeyDown(KeyCode.D))
        {
            foreach (var entry in friendCollection.documents)
            {
                Debug.Log(entry.Key + " " + entry.Value);
            }
        }

        if (Input.GetKeyDown(KeyCode.O))
        {
            JSONObject parents = new JSONObject();
            parents.AddField("mother", "wonder woman");
            parents.AddField("father", "batman");
            JSONObject attr = new JSONObject();
            attr.AddField("age", 24);
            attr.AddField("height", 180);
            attr.AddField("parents", parents);
            ddpConnection.Call("friends.addAttributes", JSONObject.StringObject("Coco"), attr);
        }

        if (Input.GetKeyDown(KeyCode.P))
        {
            JSONObject attr = new JSONObject();
            attr.AddField("age", 1);
            attr.AddField("height", 1);
            attr.AddField("parents.mother", 1);
            ddpConnection.Call("friends.removeAttributes", JSONObject.StringObject("Coco"), attr);
        }
    }