Пример #1
0
        public async Task SendAsync(string connectionId, WebSocketMessageContext context)
        {
            if (!Connections.Any())
            {
                return;
            }

            _headerProvider.Invoke(context.Header);
            using (var stream = context.ToMemoryStream())
            {
                await SendDataAsync(stream, WebSocketMessageType.Text, connectionId);
            }
        }
Пример #2
0
        public async Task BroadcastBinaryAsync(WebSocketMessageContext context)
        {
            if (!Connections.Any())
            {
                return;
            }

            using (var ms = context.ToMemoryStream())
            {
                var bytes = await ToBytesAsync(ms.ToArray());

                using (var stream = new MemoryStream(bytes))
                {
                    await SendDataAsync(stream, WebSocketMessageType.Binary, Connections.Select(c => c.Key).ToArray());
                }
            }
        }
Пример #3
0
        public async Task BroadcastAsync(WebSocketMessageContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (context.Value == null)
            {
                throw new ArgumentNullException(nameof(context.Value));
            }

            if (!Connections.Any())
            {
                return;
            }

            using (var stream = context.ToMemoryStream())
            {
                await SendDataAsync(stream, WebSocketMessageType.Text, Connections.Select(c => c.Key).ToArray());
            }
        }