예제 #1
0
    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.");

            StartCoroutine(MyCoroutine());
        };

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

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

        ddpConnection.OnConnectionClosed += (DdpConnection connection) => {
            Debug.Log("Connection closed.");
        };

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

        ddpConnection.OnAdded += (collection, id, fields) => {
            Debug.Log("Added docId " + id +
                      " in collection " + collection);
        };

        ddpConnection.OnRemoved += (collection, id) => {
            Debug.Log("Removed docId " + id +
                      " in collection " + collection);
        };

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

        ddpConnection.OnAddedBefore += (collection, id, fields, before) => {
            Debug.Log("Added docId " + id +
                      " before docId " + before +
                      " in collection " + collection +
                      " fields: " + fields);
        };

        ddpConnection.OnMovedBefore += (collection, id, before) => {
            Debug.Log("Moved docId " + id +
                      " before docId " + before +
                      " in collection " + collection);
        };
    }
        private void Run()
        {
            try
            {
                this.Connect();

                while (!this.IsConnected)
                {
                    Thread.Sleep(100);
                }

                this.Handle();
            }
            catch (ThreadAbortException) { }
            catch (Exception e)
            {
                Logs.Error("[Story] Thread error: " + e.Message);
            }
            finally
            {
                if (this.Connection != null)
                {
                    this.Connection.Close();
                    this.Connection = null;
                }

                this.End?.Invoke(this, new EventArgs());
            }
        }
        private void OnClose(object sender, EventArgs eventArgs)
        {
            this.Subscriptions.Clear();

            this.Connection  = null;
            this.IsConnected = false;
            this.Stop();
        }
예제 #4
0
 public void Connect(string url, bool ssl)
 {
     _client            = new DdpConnection();
     _client.Login     += OnLogin;
     _client.Connected += OnConnected;
     _client.Connect(url, ssl);
     _client.Error  += OnError;
     _client.Closed += OnClosed;
 }
예제 #5
0
        static void Main(string [] args)
        {
            _client            = new DdpConnection("localhost:3000");
            _client.Retry      = true;
            _client.Login     += Login;
            _client.Connected += OnConnected;
            _client.Connect();

            Console.ReadKey();
            _client.Close();
        }
예제 #6
0
        private static void Main(string[] args)
        {
            _client            = new DdpConnection();
            _client.Login     += OnLogin;
            _client.Closed    += OnClose;
            _client.Error     += OnError;
            _client.Connected += OnConnected;
            _client.Connect("localhost:3000");

            Console.ReadKey();
            _client.Close();
        }
예제 #7
0
        private static void Main(string[] args)
        {
            _client = new DdpConnection();
            _client.Login += OnLogin;
            _client.Closed += OnClose;
            _client.Error += OnError;
            _client.Connected += OnConnected;
            _client.Connect("localhost:3000");

            Console.ReadKey();
            _client.Close();
        }
        private void Connect()
        {
            this.Connection = new DdpConnection();

            this.Connection.Error     += this.OnError;
            this.Connection.Connected += this.OnConnected;
            this.Connection.Closed    += this.OnClose;
            this.Connection.Login     += this.OnLogin;
            this.Connection.Message   += this.OnMessage;

            this.Connection.ConnectAsync(this.URL, this.SSL);
        }
예제 #9
0
    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);
        };
    }
예제 #10
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();
    }
        public void Connect()
        {
            if (this.IsConnected)
            {
                return;
            }

            this.State.Set("Connecting...");

            this.Connection            = new DdpConnection();
            this.Connection.Error     += this.OnError;
            this.Connection.Connected += this.OnConnected;
            this.Connection.Closed    += this.OnClose;

            this.Connection.GetSubscriber <ConfigDoc>("config").Subscribers.Add(this.Collections.Config);
            this.Connection.GetSubscriber <ControlDoc>("control").Subscribers.Add(this.Collections.Control);
            this.Connection.GetSubscriber <TestUserDoc>("test-users").Subscribers.Add(this.Collections.TestUsers);

            this.Connection.ConnectAsync(this.URL, this.SSL);
        }
        private void OnClose(object sender, EventArgs eventArgs)
        {
            this.IsConnected = false;

            if (TestManager.Instance.IsRunning)
            {
                TestManager.Instance.Stop();
            }

            this.Subscriptions.Clear();
            this.Collections.Clear();

            this.Connection   = null;
            this.ConnectionID = null;
            this.Reconnect();

            if (this.IsClosing)
            {
                this.IsClosing = false;
            }
        }
예제 #13
0
 public void Setup()
 {
     _mock       = new Mock <WebSocketAdapterBase>();
     _connection = new DdpConnection(_mock.Object);
 }
 public void Setup()
 {
     _mock = new Mock<IDdpWebSocket>();
     _connection = new DdpConnection(_mock.Object);
 }
 public void Setup()
 {
     _mock = new Mock<WebSocketAdapterBase>();
     _connection = new DdpConnection(_mock.Object);
 }
 public void Setup()
 {
     _mock       = new Mock <IDdpWebSocket>();
     _connection = new DdpConnection(_mock.Object);
 }