Esempio n. 1
0
        private 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;
            AblyRealtimeOptions options = new AblyRealtimeOptions(key)
            {
                UseBinaryProtocol = false, 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.ChannelStateChanged      += channel_ChannelStateChanged;
            this.channel.MessageReceived          += this.channel_MessageReceived;
            this.channel.Presence.MessageReceived += this.Presence_MessageReceived;
            this.channel.Attach();
            this.channel.Presence.Enter(null, null);
        }
Esempio n. 2
0
        public void When_HostNotSetInOptions_UseBinaryProtocol_TrueByDefault()
        {
            // Arrange
            AblyRealtimeOptions options = new AblyRealtimeOptions();

            // Act
            Assert.True(options.UseBinaryProtocol);
        }
Esempio n. 3
0
 public ConnectionManager(AblyRealtimeOptions options)
     : this()
 {
     this.options      = options;
     this.state        = new States.Connection.ConnectionInitializedState(this);
     this.ackProcessor = new AcknowledgementProcessor();
     this.connection   = new Connection(this);
 }
Esempio n. 4
0
        private AblyRealtime GetNotModifiedClient()
        {
            var options = new AblyRealtimeOptions()
            {
                Key = ApiKey, UseBinaryProtocol = false
            };
            var client = new AblyRealtime(options);

            client.InitAuth(new Rest.AblySimpleRestClient(options));

            Config.Now = () => Now;
            return(client);
        }
Esempio n. 5
0
        internal static TransportParams CreateTransportParameters(AblyRealtimeOptions options, Connection connection, bool useFallbackHost)
        {
            TransportParams transportParams = new TransportParams(options);

            transportParams.Host          = GetHost(options, useFallbackHost);
            transportParams.Port          = options.Tls ? Defaults.TlsPort : Transport.Defaults.Port;
            transportParams.FallbackHosts = Defaults.FallbackHosts;
            if (connection != null)
            {
                transportParams.ConnectionKey    = connection.Key;
                transportParams.ConnectionSerial = connection.Serial.ToString();
            }
            return(transportParams);
        }
Esempio n. 6
0
        private AblyRealtime GetClient(Func <AblyRequest, AblyResponse> executeHttpRequest)
        {
            var options = new AblyRealtimeOptions()
            {
                Key = ApiKey, UseBinaryProtocol = false
            };
            var client         = new AblyRealtime(options);
            var httpClientMock = new Moq.Mock <IAblyHttpClient>();

            httpClientMock.Setup(c => c.Execute(Moq.It.IsAny <AblyRequest>())).Returns(executeHttpRequest);

            client.InitAuth(new Rest.AblySimpleRestClient(options, httpClientMock.Object));

            Config.Now = () => Now;
            return(client);
        }
Esempio n. 7
0
        private static string GetHost(AblyRealtimeOptions options, bool useFallbackHost)
        {
            string defaultHost = Defaults.RealtimeHost;

            if (useFallbackHost)
            {
                Random r = new Random();
                defaultHost = Defaults.FallbackHosts[r.Next(0, 1000) % Defaults.FallbackHosts.Length];
            }
            string host = !string.IsNullOrEmpty(options.Host) ? options.Host : defaultHost;

            if (options.Environment.HasValue && options.Environment != AblyEnvironment.Live)
            {
                return(string.Format("{0}-{1}", options.Environment.ToString().ToLower(), host));
            }
            return(host);
        }
Esempio n. 8
0
 public TransportParams(AblyRealtimeOptions options)
 {
     this.Options = options;
 }