Пример #1
0
        internal Task AddPlaybackAsync(ulong[] ids)
        {
            var topics  = ids.Select(x => $"video-playback.{x}");
            var request = new PubsubRequest("LISTEN")
                          .WithData(null, topics.ToArray());

            return(SendAsync(request));
        }
Пример #2
0
        internal Task RemoveBitsReceivedAsync(RestTokenInfo info)
        {
            string topic   = $"whispers.{info.UserId}";
            var    request = new PubsubRequest("UNLISTEN")
                             .WithData(info.Token, topic);

            return(SendAsync(request));
        }
Пример #3
0
        public async Task SendAsync(PubsubRequest request)
        {
            await Logger.DebugAsync("Pubsub", $"Attempting {request.Type}").ConfigureAwait(false);

            if (request.Nonce != null && !Requests.TryAdd(request.Nonce, request))
            {
                throw new Exception($"Unable to create nonce for {request.Type} {request.Data?.Topics.First()}");
            }

            await _client.SendAsync(request.ToString());

            await Logger.DebugAsync("Pubsub", $"{request.Type} success").ConfigureAwait(false);
        }
Пример #4
0
        internal Task RemoveWhisperAsync(RestTokenInfo info)
        {
            if (!info.Authorization?.Scopes.Contains("chat_login") ?? false)
            {
                throw new MissingScopeException("chat_login");
            }

            string topic   = $"whispers.{info.UserId}";
            var    request = new PubsubRequest("UNLISTEN")
                             .WithData(info.Token, topic);

            return(SendAsync(request));
        }
Пример #5
0
        public async Task SendSocketAsync(string type, object payload, string nonce = null, RequestOptions options = null)
        {
            CheckLoginState();
            if (ConnectionState == ConnectionState.Disconnected)
            {
                await ConnectAsync().ConfigureAwait(false);
            }

            byte[] bytes = null;
            if (payload != null)
            {
                bytes = Encoding.UTF8.GetBytes(SerializeJson(payload));
            }
            var request = new PubsubRequest(WebSocketClient, null, bytes, true, options);
            await request.SendAsync().ConfigureAwait(false);

            await _sentPusbubMessageEvent.InvokeAsync(type).ConfigureAwait(false);
        }