public void ConnectedState_UpdatesConnectionInformation()
            {
                // Act
                var connectedProtocolMessage = new ProtocolMessage(ProtocolMessage.MessageAction.Connected)
                {
                    ConnectionId      = "1",
                    ConnectionSerial  = 100,
                    ConnectionDetails = new ConnectionDetails
                    {
                        ClientId      = "client1",
                        ConnectionKey = "validKey"
                    },
                };
                var client = GetRealtimeClient(options => options.AutoConnect = false);

                client.Workflow.ProcessCommand(SetConnectedStateCommand.Create(connectedProtocolMessage, false));

                // Assert
                var connection = client.Connection;

                connection.Id.Should().Be("1");
                connection.Serial.Should().Be(100);
                connection.Key.Should().Be("validKey");
                client.Auth.ClientId.Should().Be("client1");
            }
Beispiel #2
0
        public override async Task <bool> OnMessageReceived(ProtocolMessage message, RealtimeState state)
        {
            switch (message.Action)
            {
            case ProtocolMessage.MessageAction.Auth:
                Context.ExecuteCommand(RetryAuthCommand.Create(false).TriggeredBy("ConnectedState.OnMessageReceived()"));
                return(true);

            case ProtocolMessage.MessageAction.Connected:
                Context.ExecuteCommand(SetConnectedStateCommand.Create(message, isUpdate: true).TriggeredBy("ConnectedState.OnMessageReceived()"));
                return(true);

            case ProtocolMessage.MessageAction.Close:
                Context.ExecuteCommand(SetClosedStateCommand.Create(message.Error).TriggeredBy("ConnectedState.OnMessageReceived()"));
                return(true);

            case ProtocolMessage.MessageAction.Disconnected:
                if (message.Error?.IsTokenError ?? false)
                {
                    if (Context.ShouldWeRenewToken(message.Error, state))
                    {
                        Context.ExecuteCommand(RetryAuthCommand.Create(message.Error, true).TriggeredBy("ConnectedState.OnMessageReceived()"));
                    }
                    else
                    {
                        Context.ExecuteCommand(SetFailedStateCommand.Create(message.Error).TriggeredBy("ConnectedState.OnMessageReceived()"));
                    }

                    return(true);
                }

                Context.ExecuteCommand(SetDisconnectedStateCommand.Create(message.Error).TriggeredBy("ConnectedState.OnMessageReceived()"));
                return(true);

            case ProtocolMessage.MessageAction.Error:
                // an error message may signify an error state in the connection or in a channel
                // Only handle connection errors here.
                if (message.Channel.IsEmpty())
                {
                    Context.ExecuteCommand(SetFailedStateCommand.Create(message.Error).TriggeredBy("ConnectedState.OnMessageReceived()"));
                }

                return(true);
            }

            return(false);
        }
        public override async Task <bool> OnMessageReceived(ProtocolMessage message, RealtimeState state)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message), "Null message passed to Connection Connecting State");
            }

            switch (message.Action)
            {
            case ProtocolMessage.MessageAction.Connected:
            {
                if (Context.Transport.State == TransportState.Connected)
                {
                    TransitionState(SetConnectedStateCommand.Create(message, false)
                                    .TriggeredBy("ConnectingState.OnMessageReceived(Connected)"));
                }

                return(true);
            }

            case ProtocolMessage.MessageAction.Disconnected:
            {
                Context.ExecuteCommand(HandleConnectingDisconnectedCommand.Create(message.Error)
                                       .TriggeredBy("ConnectingState.OnMessageReceived(Disconnected)"));
                return(true);
            }

            case ProtocolMessage.MessageAction.Error:
            {
                Context.ExecuteCommand(HandleConnectingErrorCommand.Create(message.Error)
                                       .TriggeredBy("ConnectingState.OnMessageReceived(Error)"));
                return(true);
            }
            }

            return(false);
        }