示例#1
0
        public async Task SendUserRelatedEvents(WebSocket webSocket)
        {
            var authorizedUser = await _authorizedUserHelper.GetAuthorizedUserAsync();

            var cursor = _eventStore.GetChangeFeedCursorForUserId(authorizedUser.Id);

            foreach (EventChangeResult result in cursor)
            {
                var @event = result.NewValue;

                await _socketStream.SendObjectAsync(webSocket, @event);
            }
        }
示例#2
0
        public async Task <WebSocketReceiveResult> ReceiveMessages(WebSocket webSocket)
        {
            // get authorized user only once before starting loop
            var authorizedUser = await _authorizedUserHelper.GetAuthorizedUserAsync();

            var socketMessage = await _socketStream.ReceiveAsync(webSocket);

            while (!socketMessage.Result.CloseStatus.HasValue)
            {
                var processingResult = await ProcessSocketMessage(socketMessage, authorizedUser);

                // send processing result back to the User
                await _socketStream.SendObjectAsync(webSocket, processingResult);

                // receive/wait for next message
                socketMessage = await _socketStream.ReceiveAsync(webSocket);
            }

            return(socketMessage.Result);
        }
示例#3
0
        public async Task SendUserRelatedMessages(WebSocket webSocket)
        {
            // get authorized user only once before starting loop
            var authorizedUser = await _authorizedUserHelper.GetAuthorizedUserAsync();

            var cursor = _messageStore.GetChangeFeedCursorForUserId(authorizedUser.Id);

            foreach (MessageChangeResult result in cursor)
            {
                var chatId    = result.NewValue.ChatId;
                var channelId = result.NewValue.ChannelId;

                if (chatId != Guid.Empty)
                {
                    var chatMessage = _mapper.Map <ChatMessage>(result.NewValue);
                    await _socketStream.SendObjectAsync(webSocket, chatMessage);
                }
                else if (channelId != Guid.Empty)
                {
                    var channelMessage = _mapper.Map <ChannelMessage>(result.NewValue);
                    await _socketStream.SendObjectAsync(webSocket, channelMessage);
                }
            }
        }