Exemple #1
0
        /// <summary>
        /// Connect to server
        /// </summary>
        /// <param name="login">user jid i.e.(my_user@domain/resource)</param>
        /// <param name="password"></param>
        /// <param name="options"></param>
        /// <param name="context"></param>
        public void Connect(string login, string password, HOptions options, JObject context)
        {
            bool shouldConnect     = false;
            bool connInprogress    = false;
            bool disconnInprogress = false;

            this.options = new HOptions(options);

            if (this.connectionStatus == ConnectionStatus.DISCONNECTED)
            {
                shouldConnect    = true;
                connectionStatus = ConnectionStatus.CONNECTING;
            }
            if (this.connectionStatus == ConnectionStatus.CONNECTING)
            {
                connInprogress = true;
            }
            if (this.connectionStatus == ConnectionStatus.DISCONNECTING)
            {
                disconnInprogress = true;
            }

            if (shouldConnect)
            {
                fillTransportOptions(login, password, options, context);

                if (options.GetTransport() == "socketio")
                {
                    if (transport == null || !(transport is HTransportSocketIO))
                    {
                        this.transport = new HTransportSocketIO();
                    }
                    if (transportManager == null)
                    {
                        this.transportManager = new HTransportManager(this.transport);
                    }
                    if (!isEventHandlerAdded)
                    {
                        this.transportManager.onStatus = transport_onStatus;
                        this.transportManager.onData   = transport_onData;
                        isEventHandlerAdded            = true;
                    }
                    notifyStatus(ConnectionStatus.CONNECTING, ConnectionErrors.NO_ERROR, null);
                    this.transportManager.Connect(this.transportOptions);
                }
            }
            else
            {
                if (connInprogress)
                {
                    notifyStatus(ConnectionStatus.CONNECTING, ConnectionErrors.CONN_PROGRESS, null);
                }
                else if (disconnInprogress)
                {
                    notifyStatus(ConnectionStatus.DISCONNECTING, ConnectionErrors.ALREADY_CONNECTED, null);
                }
                else
                {
                    notifyStatus(ConnectionStatus.CONNECTED, ConnectionErrors.ALREADY_CONNECTED, null);
                }
            }
        }