コード例 #1
0
            public async Task WhenCallingAsyncMethod_ShouldSucceedWhenChannelReachesAttached()
            {
                var attachTask = _channel.AttachAsync();
                await Task.WhenAll(attachTask, ReceiveAttachedMessage());

                attachTask.Result.IsSuccess.Should().BeTrue();
                attachTask.Result.Error.Should().BeNull();
            }
コード例 #2
0
        private async void Subscribe_Click(object sender, RoutedEventArgs e)
        {
            string channelName = this.channelBox.Text.Trim();

            if (string.IsNullOrEmpty(channelName))
            {
                return;
            }

            string key      = RealtimeChat.Properties.Settings.Default.ApiKey;
            string clientId = RealtimeChat.Properties.Settings.Default.ClientId;
            var    options  = new ClientOptions(key)
            {
                UseBinaryProtocol = true, Tls = true, AutoConnect = false, ClientId = clientId
            };

            this.client = new AblyRealtime(options);
            this.client.Connection.ConnectionStateChanged += this.connection_ConnectionStateChanged;
            this.client.Connect();

            this.channel = this.client.Channels.Get(channelName);
            this.channel.StateChanged += channel_ChannelStateChanged;
            this.channel.Subscribe(Handler);
            this.channel.Presence.Subscribe(Presence_MessageReceived);
            await channel.AttachAsync();

            await channel.Presence.EnterAsync(new PresenceData()
            {
                Data = new [] { "data1", "data2" }
            });
        }
コード例 #3
0
        private async Task Connect()
        {
            string channelName = this.channelBox.Text.Trim();

            if (string.IsNullOrEmpty(channelName))
            {
                return;
            }

            string key      = "lNj80Q.iGyVcQ:2QKX7FFASfX-7H9H";
            string clientId = "Martin";
            var    options  = new ClientOptions(key)
            {
                UseBinaryProtocol = true, Tls = true, AutoConnect = false, ClientId = clientId
            };

            this.client = new AblyRealtime(options);
            this.client.Connection.ConnectionStateChanged += this.connection_ConnectionStateChanged;
            this.client.Connect();

            this.channel = this.client.Channels.Get(channelName);
            this.channel.StateChanged += channel_ChannelStateChanged;
            this.channel.Subscribe(Handler);
            this.channel.Presence.Subscribe(Presence_MessageReceived);
            try
            {
                await channel.AttachAsync();

                await channel.Presence.EnterAsync(new PresenceData()
                {
                    Data = new[] { "data1", "data2" }
                });
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }