Esempio n. 1
0
        public override async Task OnConnectedAsync()
        {
            var isOnline = await tracker.UserConnected(Context.User.GetUsername(), Context.ConnectionId); //when user connect we update tracker

            if (isOnline)
            {
                await Clients.Others.SendAsync("UserIsOnline", Context.User.GetUsername());
            }

            var currentUsers = await tracker.GetOnlineUsers();

            await Clients.Caller.SendAsync("GetOnlineUsers", currentUsers);    //we send updated list of current users to everyone that is connected
        }
Esempio n. 2
0
        public override async Task OnConnectedAsync()
        {
            var isOnline = await _tracker.UserConnected(Context.User.Getusername(), Context.ConnectionId);

            if (isOnline)
            {
                await Clients.Others.SendAsync("UserIsOnline", Context.User.Getusername());
            }

            var currentUsers = await _tracker.GetOnlineUsers();

            await Clients.Caller.SendAsync("GetOnlineUsers", currentUsers);
        }
Esempio n. 3
0
        // SignalR or WebSocket cannot send authentication header
        // what can be use is query string which is gonna be config in IdentityServiceExtensions class
        public override async Task OnConnectedAsync()
        {
            var isOnline = await tracker.UserConnected(Context.User.GetUsername(), Context.ConnectionId);

            if (isOnline)
            {
                // Send new online username to other user
                await Clients.Others.SendAsync("UserIsOnline", Context.User.GetUsername());
            }

            var currentUsers = await tracker.GetOnlineUsers();

            // Send a list of all connected users to user that just connect to hub
            await Clients.Caller.SendAsync("GetOnlineUsers", currentUsers);
        }