예제 #1
0
            public async Task WhenConnectionIsClosed_AttachingOrAttachedChannelsShouldTrasitionToDetached(ChannelState state)
            {
                (_channel as RealtimeChannel).SetChannelState(state);

                _client.Close();

                await _client.FakeProtocolMessageReceived(new ProtocolMessage(ProtocolMessage.MessageAction.Closed));

                _client.Connection.State.Should().Be(ConnectionState.Closed);
                _channel.State.Should().Be(ChannelState.Detached);
            }
예제 #2
0
 private void ConnectClickHandler()
 {
     _clientOptions.ClientId = _clientId.text;
     if (_isConnected)
     {
         _ably.Close();
     }
     else
     {
         _ably.Connect();
     }
 }
        public async Task WithChannelInAttachingState_WhenTransportIsDisconnected_ShouldResendAttachMessageOnConnectionResumed(Protocol protocol)
        {
            var channelName  = "test-channel".AddRandomSuffix();
            var sentMessages = new List <ProtocolMessage>();

            int attachMessageCount = 0;

            AblyRealtime client = null;

            client = await GetRealtimeClient(protocol, (options, settings) =>
            {
                options.TransportFactory = new TestTransportFactory
                {
                    OnMessageSent = OnMessageSent,
                };
            });

            void OnMessageSent(ProtocolMessage message)
            {
                sentMessages.Add(message);
                if (message.Action == ProtocolMessage.MessageAction.Attach)
                {
                    if (attachMessageCount == 0)
                    {
                        attachMessageCount++;
                        client.GetTestTransport().Close(suppressClosedEvent: false);
                    }
                }
            }

            bool didDisconnect = false;

            client.Connection.Once(ConnectionEvent.Disconnected, change =>
            {
                didDisconnect = true;
            });

            await client.WaitForState(ConnectionState.Connected);

            var channel = client.Channels.Get(channelName);

            channel.Attach();

            await channel.WaitForState(ChannelState.Attaching);

            await client.WaitForState(ConnectionState.Disconnected);

            await client.WaitForState(ConnectionState.Connecting);

            await client.WaitForState(ConnectionState.Connected);

            client.Connection.State.Should().Be(ConnectionState.Connected);
            didDisconnect.Should().BeTrue();

            await channel.WaitForAttachedState();

            var attachCount = sentMessages.Count(x => x.Channel == channelName && x.Action == ProtocolMessage.MessageAction.Attach);

            attachCount.Should().Be(2);

            client.Close();
        }
예제 #4
0
 public void Close()
 {
     _channel.Unsubscribe();
     _ably.Close();
 }