public async Task ConnectAsync(string token, string channelId, CancellationToken cancellationToken)
        {
            await _webSocketClient.ConnectAsync(_webSocketServerUri, cancellationToken);

            if (_webSocketClient.State == WebSocketState.Open)
            {
                ListenRequest     lr  = new ListenRequest();
                ListenRequestData lrd = new ListenRequestData();
                lrd.auth_token = token;
                String[] lrdt = { "channel-points-channel-v1." + channelId, "channel-bits-events-v2." + channelId };
                lrd.topics = lrdt;
                lr.data    = lrd;
                lr.nonce   = "lkjsdhfiusdagf";
                lr.type    = "LISTEN";
                String jlr = JsonConvert.SerializeObject(lr);
                await SendMessageAsync(jlr, cancellationToken);

                var timer = new Timer(async(e) =>
                {
                    await SendMessageAsync("{\"type\":  \"PING\"}", cancellationToken);
                }, null, TimeSpan.Zero, TimeSpan.FromMinutes(5));

                // start receiving messages in separeted thread
                var receive = ReceiveAsync(cancellationToken).ConfigureAwait(false);
            }
        }
Exemplo n.º 2
0
        public async Task ConnectAsync(string token, string channelId, CancellationToken cancellationToken)
        {
            await _webSocketClient.ConnectAsync(_webSocketServerUri, cancellationToken);

            if (_webSocketClient.State == WebSocketState.Open)
            {
                ListenRequest     lr  = new ListenRequest();
                ListenRequestData lrd = new ListenRequestData();
                lrd.AuthToken = token;
                String[] lrdt = { "channel-points-channel-v1." + channelId, "channel-bits-events-v2." + channelId };
                lrd.Topics = lrdt;
                lr.Data    = lrd;
                lr.Nonce   = "lkjsdhfiusdagf";
                lr.Type    = "LISTEN";
                String jlr = JsonSerializer.Serialize <ListenRequest>(lr);
                await SendMessageAsync(jlr, cancellationToken);

                // start receiving messages in separeted thread
                var receive = ReceiveAsync(cancellationToken).ConfigureAwait(false);
            }
        }