Exemple #1
0
 public JsonObjectCollection GetCollection(string name)
 {
     if (localDB == null)
     {
         return(null);
     }
     return((JsonObjectCollection)localDB.GetCollection(name));
 }
    public void Start()
    {
        Application.runInBackground = true;         // Let the game run when the editor is not focused.

        ddpConnection             = new DdpConnection(serverUrl);
        ddpConnection.logMessages = logMessages;

        ddpConnection.OnConnected += (DdpConnection connection) => {
            Debug.Log("Connected.");
        };

        ddpConnection.OnDisconnected += (DdpConnection connection) => {
            Debug.Log("Disconnected.");

            StartCoroutine(CoroutineHelper.GetInstance().RunAfter(() => {
                Debug.Log("Try to reconnect ...");
                connection.Connect();
            }, 2.0f));
        };

        ddpConnection.OnError += (DdpError error) => {
            Debug.Log("Error: " + error.errorCode + " " + error.reason);
        };

        localDB = new LocalDB((db, collectionName) => {
            return(new JsonObjectCollection(db, collectionName));
        }, ddpConnection);

        friendCollection          = (JsonObjectCollection)localDB.GetCollection("friends");
        friendCollection.OnAdded += (id, fields) => {
            Debug.Log("Added docId " + id);
        };

        friendCollection.OnRemoved += (id) => {
            Debug.Log("Removed docId " + id);
        };

        friendCollection.OnChanged += (id, fields, cleared) => {
            Debug.Log("Changed docId " + id +
                      " fields: " + fields +
                      " cleared:" + cleared);
        };
    }