Exemplo n.º 1
0
        private void HandleChatRequestMsg(ChatRequest req, TalkBackDBContext dbContext)
        {
            // first check that the addressee is in the dictionary:
            WebSocket peer;

            if (!WebSocketMiddleware._sockets.TryGetValue(req.To, out peer))
            {
                // not found -> send a ChatRequestResponse with failure:
                ChatRequestResponse resp = new ChatRequestResponse {
                    Success = false, ErrorMessage = "Chat peer is not online"
                };
                WebSocketMiddleware.SendStringAsync(_webSocket, resp.ToXml().ToString());
                return;
            }

            string strMsg = req.ToXml().ToString();

            WebSocketMiddleware.SendStringAsync(peer, strMsg);

            return;
        }