Beispiel #1
0
        public override Task OnConnected(WebSocket socket)
        {
            WebSocketConnectionManager.AddSocket(socket);
            var socketID = WebSocketConnectionManager.GetId(socket);

            SendMessageAsync(socketID, socketID);
            return(base.OnConnected(socket));
        }
Beispiel #2
0
        public override async Task ReceiveAsync(WebSocket socket, WebSocketReceiveResult result, byte[] buffer)
        {
            var socketId = WebSocketConnectionManager.GetId(socket);
            var message  = Encoding.UTF8.GetString(buffer, 0, result.Count);

            try
            {
                var recieveJSON = JsonConvert.DeserializeObject <SocketJSON>(message);

                var existSocketUser = socketUsers.FirstOrDefault(x => x.ID.Equals(socketId));
                if (existSocketUser == null)
                {
                    socketUsers.Add(new SocketUser {
                        ID = socketId
                    });
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Beispiel #3
0
        public void NotifyToUser(string user, string message)
        {
            var socketID = WebSocketConnectionManager.GetSocketById(user);

            SendMessageAsync(socketID, message);
        }
Beispiel #4
0
 public void RemoveSocketUser(string user, string sockterId)
 {
     userID.Remove(user, out sockterId);
     WebSocketConnectionManager.RemoveSocket(sockterId);
 }
Beispiel #5
0
        public void addSocketUser(string user, string socketId)
        {
            var socketID = WebSocketConnectionManager.GetSocketById(socketId);

            userID.Add(user, socketId);
        }
Beispiel #6
0
 public NotificationsMessageHandler(WebSocketConnectionManager webSocketConnectionManager) : base(webSocketConnectionManager)
 {
 }
 public WebSocketHandler(WebSocketConnectionManager webSocketConnectionManager)
 {
     WebSocketConnectionManager = webSocketConnectionManager;
 }