예제 #1
0
        public AblyClientService(IConfiguration _configuration)
        {
            var realtime = new AblyRealtime(_configuration.GetValue <string>("ably"));

            realtime.Connect();
            Client = realtime;
        }
예제 #2
0
        public async Task <bool> InitializeAsync()
        {
            var task = new TaskCompletionSource <bool>();

            _client = new AblyRealtime(new ClientOptions()
            {
                Key          = AblyApiKey,
                EchoMessages = false // prevent messages the client sends echoing back
            });

            _client.Connection.On(args =>
            {
                if (args.Current == IO.Ably.Realtime.ConnectionState.Connected)
                {
                    // channels don't get automatically reattached
                    // if the connection drop, so do that manually
                    foreach (var channel in _client.Channels)
                    {
                        channel.Attach();
                    }

                    _channel = _client.Channels.Get("general");
                    _channel.Subscribe(MessageEvent, (IO.Ably.Message msg) => {
                        Console.WriteLine(msg.ClientId);
                    });
                    task.SetResult(true);
                }
                if (args.Current == IO.Ably.Realtime.ConnectionState.Disconnected)
                {
                    _client.Connect();
                }
            });

            return(await task.Task.ConfigureAwait(false));
        }
예제 #3
0
 private void ConnectClickHandler()
 {
     _clientOptions.ClientId = _clientId.text;
     if (_isConnected)
     {
         _ably.Close();
     }
     else
     {
         _ably.Connect();
     }
 }
예제 #4
0
        public void AutoConnectOff()
        {
            var realtime = new AblyRealtime(new ClientOptions(PlaceholderKey)
            {
                AutoConnect = false
            });

            realtime.Connect();

            realtime.Connection.On(args =>
            {
                var currentState  = args.Current;     // Current state the connection transitioned to
                var previousState = args.Previous;    // Previous state
                var error         = args.Reason;      // If the connection error-ed the 'Reason' object will be populated.
            });
        }
예제 #5
0
 public void Connect()
 {
     _ably.Connect();
 }