Exemple #1
0
        private void NotifyAllOnlineUsersAboutNewlyJoinedUser(string connecting_user)
        {
            // Inform all of the clients of the new message
            List <string> callbackKeys = loggedInUsers?.Keys.ToList();

            // Loops through each logged in user
            foreach (string key in callbackKeys)
            {
                if (key != connecting_user)
                {
                    try
                    {
                        IOneToOneChatCallback callback = loggedInUsers[key];
                        callback.SendNewConnectedUserNameToAllOnlineUsers(connecting_user);
                        Console.WriteLine($"Notifying user {key} about joining of {connecting_user}");
                    }
                    // catches an issue with a user disconnect and loggs off that user
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace + "." + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name);
                        // Remove the disconnected client
                        LeaveServer(key);
                    }
                }
            } // end of foreach
        }