Пример #1
0
        public override async Task OnConnectedAsync()
        {
            await _presenceTracker.UserConnected(Context.User.GetUserName(), Context.ConnectionId);

            await Clients.Others.SendAsync("UserIsOnline", Context.User.GetUserName());

            var currentUser = await _presenceTracker.GetOnlineUsers();

            await Clients.All.SendAsync("GetOnlineUsers", currentUser);
        }
Пример #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.All.SendAsync("GetOnlineUsers", currentUsers);
        }
Пример #3
0
        // The Hub class we inherited above has a few virtual methods which we can override (placing
        // the virtual keyword before the method name enables you to overrride the method elsewhere)
        // We use the override keyword so that we can override the method from the class we have
        // inherited.

        // Inside the Hub, we have access to the Clients. These are the clients that are
        // connected to this hub. In this method, we send a message to all the 'others' (everybody  // except the connection that triggered the current invocation). 'Others' is a property we  // access on the Clients object. The "UserIsOnline" is the name of the method we
        // will use on the client. We have accesss to the context with our token inside here
        // so we can access the currently logged in users username. This is what we will pass
        // back to the other users. The Context here is off type HubCallerContext. HubCallerContext // has a property which is off type UserClaimsPrincipal, this is why we get access to the
        // User object of the claims principal
        public override async Task OnConnectedAsync()
        {
            // 1. When a client connects, we are going to update our presence tracker
            await _presenceTracker.UserConnected(Context.User.GetUsername(), Context.ConnectionId);

            // 2. We trigger the "UserIsOnline" method which is triggered in the client (this displays a toastr message). This sends a message to all the'other' users (all the other users that are currently logged in)
            await Clients.Others.SendAsync("UserIsOnline", Context.User.GetUsername());

            // 3. We get the list of currently logged in users
            var currentUsers = await _presenceTracker.GetOnlineUsers();

            // 4. We trigger the "GetOnlineUsers" method which is trigered on the client
            await Clients.All.SendAsync("GetOnlineUsers", currentUsers);
        }
Пример #4
0
        public override async Task OnConnectedAsync()
        {
            var isOnline = await _tracker.UserConnected(Context.User.GetUserName(), Context.ConnectionId); //atualiza o rastreador de presença

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

            var currentUsers = await _tracker.GetOnlineUsers();

            await Clients.Caller.SendAsync("GetOnlineUsers", currentUsers);
        }
Пример #5
0
        public override async Task OnConnectedAsync()
        {
            var user     = Context.User.GetUsername();
            var isOnline = await _presenceTracker.UserConnected(Context.User.GetUsername(), Context.ConnectionId);

            if (isOnline)
            {
                await Clients.Others.SendAsync("UserIsOnline", Context.User.GetUsername());
            }
            var onlineUsers = await _presenceTracker.GetOnlineUsers();

            await Clients.Caller.SendAsync("GetOnlineUsers", onlineUsers);
        }
Пример #6
0
        public override async Task OnConnectedAsync()
        {
            var isOnline = await _tracker.UserConnected(Context.User.GetUsername(), Context.ConnectionId);

            if (isOnline)
            {
                // send to everyone but the connection
                await Clients.Others.SendAsync("UserIsOnline", Context.User.GetUsername()); // only return if user is online
            }
            // display online users
            var currentUsers = await _tracker.GetOnlineUsers();

            await Clients.Caller.SendAsync("GetOnlineUsers", currentUsers); //who just connected
        }
Пример #7
0
        public override async Task OnConnectedAsync()
        {
            var userName = Context.User.GetUserName();
            var isOnline = await _tracker.UserConnected(userName, Context.ConnectionId);

            if (isOnline)
            {
                await Clients.Others.SendAsync("UserIsOnline", userName);
            }

            string[] onlineUsers = await _tracker.GetOnlineUsers();

            await Clients.Caller.SendAsync("GetOnlineUsers", onlineUsers);
        }
Пример #8
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());
            }

            //The caller needs to know the others who are online
            var currentUsers = await _tracker.GetOnlineUsers();

            await Clients.Caller.SendAsync("GetOnlineUsers", currentUsers);
        }
Пример #9
0
        // 223: If we had more than one server we would have no way of getting the connection infromation from the other server
        // this service is confined to the server it's running on
        public override async Task OnConnectedAsync()
        {
            var isOnline = await _tracker.UserConnected(Context.User.GetUsername(), Context.ConnectionId);

            // 220: Clients.Others means all the conncetions other than the one that invoked this
            if (isOnline)
            {
                await Clients.Others.SendAsync("UserIsOnline", Context.User.GetUsername());
            }

            var currentUsers = await _tracker.GetOnlineUsers();

            await Clients.Caller.SendAsync("GetOnlineUsers", currentUsers);
        }
Пример #10
0
        public override async Task OnConnectedAsync()
        {
            var isOnline = await _tracker.UserConnected(Context.User.GetUserName(), Context.ConnectionId);

            if (isOnline)
            {
                // these are clients connected to this hub
                await Clients.Others.SendAsync("UserIsOnline", Context.User.GetUserName());
            }

            var currentUsers = await _tracker.GetOnlineUsers();

            await Clients.Caller.SendAsync("GetOnlineUsers", currentUsers);
        }
Пример #11
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);

            //above Clients.All will send to all the available users
        }
Пример #12
0
        public override async Task OnConnectedAsync()
        {
            //await _tracker.UserConnected(Context.User.GetUsername(), Context.ConnectionId);
            var isOnline = await _tracker.UserConnected(Context.User.GetUsername(), Context.ConnectionId);      // adjusted with optimisation refactor

            if (isOnline)                                                                                       // optimisation addition
            {
                await Clients.Others.SendAsync("UserIsOnline", Context.User.GetUsername());
            }
            var currentUsers = await _tracker.GetOnlineUsers();                                                         // returns the update user when the user is online

            //   await Clients.All.SendAsync("GetOnlineUsers", currentUsers);
            await Clients.Caller.SendAsync("GetOnlineUsers", currentUsers);                                      // optimisation
        }
Пример #13
0
        public override async Task OnConnectedAsync()
        {
            var firstOnline = await _tracker.UserConnected(Context.User.GetUsername(), Context.ConnectionId);

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


            // tell caller who has connected
            var currentUsers = await _tracker.GetOnlineUsers();

            await Clients.Caller.SendAsync("GetOnlineUsers", currentUsers);
        }
Пример #14
0
        public override async Task OnConnectedAsync()
        {
            var isOnline = await _tracker.UserConnected(Context.User.GetUsername(), Context.ConnectionId);

            if (isOnline)
            {
                // sending message to all other connected user to notify them that the user is connected
                await Clients.Others.SendAsync("UserIsOnline", Context.User.GetUsername());
            }

            var currentUsers = await _tracker.GetOnlineUsers();

            // sending the users online to all of the clients online
            await Clients.Caller.SendAsync("GetOnlineUsers", currentUsers);
        }
        public override async Task OnConnectedAsync()
        {
            var username = Context.User.FindFirst(ClaimTypes.Name)?.Value;

            var isOnline = await _tracker.UserConnected(username, Context.ConnectionId);

            if (isOnline)
            {
                await Clients.Others.SendAsync("UserIsOnline", username);
            }

            var currentUsers = await _tracker.GetOnlineUsers();

            await Clients.Caller.SendAsync("GetOnlineUsers", currentUsers);
        }
Пример #16
0
        public override async Task OnConnectedAsync()
        {
            var isOnline = await __tracker.UserConnected(Context.User.GetUsername(), Context.ConnectionId);

            if (isOnline)
            {
                // "UserIsOnline" is the client method that will be used to inform users someone has connected
                await Clients.Others.SendAsync("UserIsOnline", Context.User.GetUsername());
            }

            // send the list cache of all online users
            var currentUsers = await __tracker.GetOnlineUsers();

            await Clients.Caller.SendAsync("GetOnlineUsers", currentUsers);
        }
Пример #17
0
        public override async Task OnConnectedAsync()
        {
            //cuando se conecta un usuario actualizas el presence tracker
            var isOnline = await _presenceTracker.UserConnected(Context.User.GetUsername(), Context.ConnectionId);

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

            //y envias la lista actualizada de usuarios conectados a todos los que esten logeados
            var currentUsers = await _presenceTracker.GetOnlineUsers();

            await Clients.Caller.SendAsync("GetOnlineUsers", currentUsers);
        }
Пример #18
0
        public override async Task OnConnectedAsync()
        {
            // Update the presence tracker
            var isOnline = await _tracker.UserConncted(Context.User.GetUsername(), Context.ConnectionId);

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

            // send back all connected users
            var currentUSers = await _tracker.GetOnlineUsers();

            await Clients.Caller.SendAsync("GetOnlineUsers", currentUSers);
        }
Пример #19
0
        public override async Task OnConnectedAsync()
        {
            var isOnline = await _tracker.UserConnected(Context.User.GetUsername(), Context.ConnectionId);

            var unreadMessages = await _unitOfWork.MessageRepository.GetUnReadMessageCount(Context.User.GetUsername());

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

            var currentUsers = await _tracker.GetOnlineUsers();

            await Clients.Caller.SendAsync("GetOnlineUsers", currentUsers);
        }
Пример #20
0
        public override async Task OnConnectedAsync()
        {
            var isOnline = await _tracker.UserConnected(Context.User.GetUsername(), Context.ConnectionId);

            if (isOnline)
            {
                //Send to other clients when connected, a method (UserIsOnline) and the username of current user
                //Override the default on connectedAsync in order to pass data as we want it
                await Clients.Others.SendAsync("UserIsOnline", Context.User.GetUsername());
            }

            var currentUsers = await _tracker.GetOnlineUsers();

            //send the list only when connecting. We send only to the caller who connected
            //after that we will update the list of connected users
            await Clients.Caller.SendAsync("GetOnlineUsers", currentUsers);
        }
Пример #21
0
        public override async Task OnConnectedAsync()
        {
            var currentUser = Context.User.GetUsername();
            var connId      = Context.ConnectionId;

            var isOnline = await _tracker.UserConnected(currentUser, connId);

            if (isOnline)
            {
                await Clients.Others.SendAsync("UserIsOnline", currentUser);
            }

            // return the list of currently online users
            var currentUsers = await _tracker.GetOnlineUsers();

            await Clients.Caller.SendAsync("GetOnlineUsers", currentUsers);
        }
Пример #22
0
        public override async Task OnConnectedAsync()
        {
            var username = Context.User.FindFirst(ClaimTypes.Name)?.Value;
            await presenceTracker.UserConnected(username, Context.ConnectionId);

            var appUser = await unitOfWork.userRepository.GetUserByUsernameAsync(username);

            var messagesUnreadReceived = appUser.MessagesRecieved.Where(x => x.DateRead == null).Count();

            await Clients.All.SendAsync("userConnected", username, messagesUnreadReceived);

            //await Clients.Others.SendAsync("userConnected", username, messagesUnreadReceived); //userConnected na klijentu

            var currentUsers = await presenceTracker.GetOnlineUsers();

            await Clients.Caller.SendAsync("GetOnlineUsers", currentUsers); //samo calleru na klijentu GetOnlineUsers

            //a onda klijent od tamo poziva sa trackera ovo gono iz trackera
        }
Пример #23
0
        // OnConnectedAsync() is virtual so we can override it.
        public override async Task OnConnectedAsync()
        {
            // update our presence tracker with the connected user...
            var isOnline = await _tracker.UserConnected(Context.User.GetUsername(), Context.ConnectionId);


            // "UserIsOnline" is the name of the client-side method.
            // we have access to the Context with the token inside.
            // note that Signal R (or web sockets) cannot send an Authentication header.
            // We need to use a query string with Signal R
            // only send UserIsOnline to the connected clients, apart from the caller.
            if (isOnline)
            {
                await Clients.Others.SendAsync("UserIsOnline", Context.User.GetUsername());
            }
            // everytime a user connects to a hub, they are given a connection id.


            // send the updated list of current users back to everyone that is connected
            var currentUsers = await _tracker.GetOnlineUsers();

            await Clients.Caller.SendAsync("GetOnlineUsers", currentUsers);
        }