Exemplo n.º 1
0
 private void RegisterEventsOnConnection()
 {
     _connection.Connected += _connection_Connected;
     _connection.ConnectionStateChanged += _connection_ConnectionStateChanged;
     if (_errorEvent != null)
     {
         // subscribe to the connection's error handler
         foreach (ErrorEventHandler handler in _errorEvent.GetInvocationList())
         {
             _connection.Error += handler;
         }
     }
 }
Exemplo n.º 2
0
        public bool Connect()
        {
            // check current connection state
            if (Connection?.State == WebSocketState.Open)
            {
                return(false);
            }

            var url = Options.Encrypted ? "wss://" : "ws://" + Options.Host + "/app/" + _applicationKey + "?protocol=" + (int)Options.ProtocolVersion + "&client=" + PurePusherClientOptions.ClientName + "&version=" + PurePusherClientOptions.VersionNumber;

            Connection            = new WsConnection(this, url);
            Connection.Connected += _connection_Connected;
            Connection.ConnectionStateChanged += _connection_ConnectionStateChanged;

            if (_errorEvent != null)
            {
                foreach (var del in _errorEvent.GetInvocationList())
                {
                    var handler = (ErrorEventHandler)del;
                    Connection.Error += handler;
                }
            }

            return(Connection.Connect());
        }
Exemplo n.º 3
0
        private void RegisterEventsOnConnection()
        {
            connection.Connected += connection_Connected;
            connection.ConnectionStateChanged += connection_ConnectionStateChanged;

            if (errorEvent != null)
            {
                // subscribe to the connection's error handler
                foreach (var @delegate in errorEvent.GetInvocationList())
                {
                    if (@delegate is ErrorEventHandler handler)
                    {
                        connection.Error += handler;
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void Connect()
        {
            // Check current connection state
            if (_connection != null)
            {
                switch (_connection.State)
                {
                case ConnectionState.Connected:
                    Trace.TraceEvent(TraceEventType.Warning, 0, "Attempt to connect when connection is already in 'Connected' state. New attempt has been ignored.");
                    break;

                case ConnectionState.Connecting:
                    Trace.TraceEvent(TraceEventType.Warning, 0, "Attempt to connect when connection is already in 'Connecting' state. New attempt has been ignored.");
                    break;

                case ConnectionState.Failed:
                    Trace.TraceEvent(TraceEventType.Error, 0, "Cannot attempt re-connection once in 'Failed' state");
                    RaiseError(new PusherException("Cannot attempt re-connection once in 'Failed' state", ErrorCodes.ConnectionFailed));
                    break;
                }
            }

            var scheme = "ws://";

            if (_options.Encrypted)
            {
                scheme = "wss://";
            }

            // TODO: Fallback to secure?

            string url = String.Format("{0}{1}/app/{2}?protocol={3}&client={4}&version={5}",
                                       scheme, this.Host, _applicationKey, Settings.Default.ProtocolVersion, Settings.Default.ClientName,
                                       Settings.Default.VersionNumber);

            _connection            = new Connection(this, url);
            _connection.Connected += _connection_Connected;
            _connection.ConnectionStateChanged += _connection_ConnectionStateChanged;
            if (_errorEvent != null)
            {
                // subscribe to the connection's error handler
                foreach (ErrorEventHandler handler in _errorEvent.GetInvocationList())
                {
                    _connection.Error += handler;
                }
            }
            _connection.Connect();
        }
Exemplo n.º 5
0
        public void Connect()
        {
            // Prevent multiple concurrent connections
            lock (_lockingObject)
            {
                // Ensure we only ever attempt to connect once
                if (_connection != null)
                {
                    Trace.TraceEvent(TraceEventType.Warning, 0, "Attempt to connect when another connection has already started. New attempt has been ignored.");
                    return;
                }

                var scheme = "ws://";

                if (_options.Encrypted)
                {
                    scheme = "wss://";
                }

                // TODO: Fallback to secure?

                string url = String.Format("{0}{1}/app/{2}?protocol={3}&client={4}&version={5}",
                                           scheme, _options.Host, _applicationKey, Settings.Default.ProtocolVersion, Settings.Default.ClientName,
                                           Settings.Default.VersionNumber);

                _connection            = new Connection(this, url);
                _connection.Connected += _connection_Connected;
                _connection.ConnectionStateChanged += _connection_ConnectionStateChanged;
                if (_errorEvent != null)
                {
                    // subscribe to the connection's error handler
                    foreach (ErrorEventHandler handler in _errorEvent.GetInvocationList())
                    {
                        _connection.Error += handler;
                    }
                }
                _connection.Connect();
            }
        }