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 { auth_token = token, topics = new string[] { "channel-points-channel-v1." + channelId, "channel-bits-events-v2." + channelId, "channel-subscribe-events-v1." + channelId, "hype-train-events-v1." + channelId } }; lr.data = lrd; lr.nonce = "lkjsdhfiusdagf"; lr.type = "LISTEN"; StringBuilder stringBuilder = new StringBuilder(); JsonMapper.ToJson(lr, new JsonWriter(stringBuilder)); string jlr = stringBuilder.ToString(); //Controller._instance._log.LogMessage(jlr); await SendMessageAsync(jlr, cancellationToken); Timer timer = new Timer(async(e) => { Controller._instance._log.LogMessage("Sending PubSub Ping"); await SendMessageAsync("{\"type\": \"PING\"}", cancellationToken); }, null, TimeSpan.Zero, TimeSpan.FromMinutes(5)); // start receiving messages in separeted thread System.Runtime.CompilerServices.ConfiguredTaskAwaitable receive = ReceiveAsync(cancellationToken).ConfigureAwait(false); } }
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); 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); } }