GetID() public method

public GetID ( ) : int
return int
 /// <summary>
 /// Called when a user is joining the current session.
 /// </summary>
 /// <param name="user">User that joined the current session.</param>
 private void UserJoinedSession(User user)
 {
     if (user.GetID() != SharingStage.Instance.Manager.GetLocalUser().GetID())
     {
         GetRemoteHeadInfo(user.GetID());
     }
 }
Exemplo n.º 2
0
        public User GetUserById(long userId)
        {
            User retval = null;

            userIdToUser.TryGetValue(userId, out retval);

            if (retval == null)
            {
                Session currentSession = this.sessionManager.GetCurrentSession();
                if (currentSession != null)
                {
                    int userCount = currentSession.GetUserCount();
                    for (int index = 0; index < userCount; index++)
                    {
                        User user = currentSession.GetUser(index);
                        if ((long)user.GetID() == userId)
                        {
                            retval = user;
                            break;
                        }
                    }
                }
            }

            return(retval);
        }
        public override void OnUserLeftSession(Session session, User user)
        {
            LogWriteLine(string.Format("********* USER {0} ({1}) LEFT SESSION  {2} ******", user.GetName().GetString(), user.GetID(), session.GetName().GetString()));

            if (SessionUserLeft != null)
            {
                SessionUserLeft(session, user);
            }
        }
        /// <summary>
        /// Called when a new user is leaving the current session.
        /// </summary>
        /// <param name="user">User that left the current session.</param>
        private void UserLeftSession(User user)
        {
            int userId = user.GetID();

            if (userId != SharingStage.Instance.Manager.GetLocalUser().GetID())
            {
                RemoveRemoteHead(this.remoteHeads[userId].HeadObject);
                this.remoteHeads.Remove(userId);
            }
        }
Exemplo n.º 5
0
 public void UpdateUser(User user)
 {
     var myUser = _users.FirstOrDefault(u => u.GetID() == user.GetID());
     if (myUser != null)
     {
         _users.Remove(myUser);
         _users.Add(user);
     }
     UpdateUserNames();
 }
Exemplo n.º 6
0
        private bool IsLocalUser(User user)
        {
            int changedUserId = user.GetID();

            using (User localUser = sessionManager.GetCurrentUser())
            {
                int localUserId = localUser.GetID();
                return(localUserId == changedUserId);
            }
        }
Exemplo n.º 7
0
        void SendJoinEvent(User user)
        {
            Debug.Log("User joining session: " + user.GetID());

            EventHandler <SessionJoinedEventArgs> joinEvent = SessionJoined;

            if (joinEvent != null)
            {
                SessionJoinedEventArgs sjea = new SessionJoinedEventArgs();
                sjea.joiningUser = user;
                joinEvent(this, sjea);
            }

            long userId = user.GetID();

            if (userIdToUser.ContainsKey(userId) == false)
            {
                userIdToUser.Add(userId, user);
            }
        }
 /// <summary>
 /// Finds and returns an object representing a user who has the supplied id number. Returns null if the user is not found.
 /// </summary>
 /// <param Name="userId">The numerical id of the session User to find</param>
 /// <returns>The User with the specified id or null (if not found)</returns>
 public User GetUserById(int userId)
 {
     for (int u = 0; u < CurrentUsers.Count; u++)
     {
         User user = CurrentUsers[u];
         if (user.GetID() == userId)
         {
             return(user);
         }
     }
     return(null);
 }
Exemplo n.º 9
0
        private void OnUserLeftSession(Session session, User user)
        {
            if (!session.IsJoined())
            {
                return;
            }

            if (CurrentUsers.RemoveAll(x => x.GetID() == user.GetID()) > 0)
            {
                //Debug.LogFormat("User {0} left current session.", user.GetName());
                UserLeft.RaiseEvent(user);
            }
        }
Exemplo n.º 10
0
        private void Connect()
        {
            var config = new ClientConfig(ClientRole);

            config.SetIsAudioEndpoint(IsAudioEndpoint);
            config.SetLogWriter(logWriter);

            // Only set the server info is we are connecting on awake
            if (connectOnAwake)
            {
                config.SetServerAddress(ServerAddress);

                /*#if UNITY_EDITOR
                 *  config.SetServerAddress("localhost");
                 #endif*/
                config.SetServerPort(ServerPort);
            }

            Manager = SharingManager.Create(config);

            //set up callbacks so that we know when we've connected successfully
            networkConnection        = Manager.GetServerConnection();
            networkConnectionAdapter = new NetworkConnectionAdapter();
            networkConnectionAdapter.ConnectedCallback += NetworkConnectionAdapter_ConnectedCallback;
            networkConnection.AddListener((byte)MessageID.StatusOnly, networkConnectionAdapter);

            SyncStateListener = new SyncStateListener();
            Manager.RegisterSyncListener(SyncStateListener);

            Root = new SyncRoot(Manager.GetRootSyncObject());

            SessionsTracker     = new ServerSessionsTracker(Manager.GetSessionManager());
            SessionUsersTracker = new SessionUsersTracker(SessionsTracker);

            using (var userName = new XString(DefaultUserName))
            {
#if UNITY_WSA && !UNITY_EDITOR
                Manager.SetUserName(SystemInfo.deviceName);
#else
                if (!string.IsNullOrEmpty(Environment.UserName))
                {
                    Manager.SetUserName(Environment.UserName);
                }
                else
                {
                    User localUser = Manager.GetLocalUser();
                    Manager.SetUserName(userName + localUser.GetID().ToString());
                }
#endif
            }
        }
Exemplo n.º 11
0
        private void ManagerInit(bool setConnection)
        {
            var config = new ClientConfig(ClientRole);

            config.SetIsAudioEndpoint(IsAudioEndpoint);
            config.SetLogWriter(logWriter);

            if (setConnection)
            {
                config.SetServerAddress(ServerAddress);
                config.SetServerPort(ServerPort);
            }

            Manager = SharingManager.Create(config);

            // Set up callbacks so that we know when we've connected successfully.
            networkConnectionAdapter = new NetworkConnectionAdapter();
            networkConnectionAdapter.ConnectedCallback    += OnNetworkConnectionChanged;
            networkConnectionAdapter.DisconnectedCallback += OnNetworkConnectionChanged;
            Connection.AddListener((byte)MessageID.StatusOnly, networkConnectionAdapter);

            SyncStateListener = new SyncStateListener();
            Manager.RegisterSyncListener(SyncStateListener);

            Root = new SyncRoot(Manager.GetRootSyncObject());

            SessionsTracker     = new ServerSessionsTracker(Manager.GetSessionManager());
            SessionUsersTracker = new SessionUsersTracker(SessionsTracker);

            RoomManagerAdapter = new RoomManagerAdapter();

            CurrentRoomManager.AddListener(RoomManagerAdapter);

            using (var userName = new XString(DefaultUserName))
            {
#if UNITY_WSA && !UNITY_EDITOR
                Manager.SetUserName(SystemInfo.deviceName);
#else
                if (!string.IsNullOrEmpty(Environment.UserName))
                {
                    Manager.SetUserName(Environment.UserName);
                }
                else
                {
                    User localUser = Manager.GetLocalUser();
                    Manager.SetUserName(userName + localUser.GetID().ToString());
                }
#endif
            }
        }
Exemplo n.º 12
0
        private void OnUserJoinedSession(Session session, User user)
        {
            if (!session.IsJoined())
            {
                return;
            }

            if (!CurrentUsers.Contains(user))
            {
                //Debug.LogFormat("User {0} joined current session.", user.GetName());
                CurrentUsers.RemoveAll(x => x.GetID() == user.GetID());                 // in case there was an old user with the same ID
                CurrentUsers.Add(user);
                UserJoined.RaiseEvent(user);
            }
        }
Exemplo n.º 13
0
        private void OnUserLeftSession(Session session, User user)
        {
            if (!session.IsJoined())
            {
                return;
            }

            for (int i = CurrentUsers.Count - 1; i >= 0; i--)
            {
                if (CurrentUsers[i].GetID() == user.GetID())
                {
                    CurrentUsers.RemoveAt(i);
                    UserLeft.RaiseEvent(user);
                    // Debug.LogFormat("User {0} left current session.", user.GetName());
                }
            }
        }
        private bool ShouldLocalUserCreateRoom()
        {
            if (sharingStage.SessionUsersTracker != null)
            {
                long localUserId = 0;
                using (User localUser = SharingStage.Instance.Manager.GetLocalUser())
                {
                    localUserId = localUser.GetID();
                }

                for (int i = 0; i < sharingStage.SessionUsersTracker.CurrentUsers.Count; i++)
                {
                    User user = sharingStage.SessionUsersTracker.CurrentUsers[i];
                    if (user.GetID() < localUserId)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 15
0
        private void OnUserJoinedSession(Session session, User user)
        {
            if (!session.IsJoined())
            {
                return;
            }

            if (!CurrentUsers.Contains(user))
            {
                // Remove any old users with the same ID
                for (int i = CurrentUsers.Count - 1; i >= 0; i--)
                {
                    if (CurrentUsers[i].GetID() == user.GetID())
                    {
                        CurrentUsers.RemoveAt(i);
                    }
                }

                CurrentUsers.Add(user);
                UserJoined.RaiseEvent(user);
                // Debug.LogFormat("User {0} joined current session.", user.GetName());
            }
        }
Exemplo n.º 16
0
        void Update()
        {
            // Get an instance of the SessionManager if one does not exist.
            if (sessionManager == null && SharingStage.Instance != null && SharingStage.Instance.Manager != null)
            {
                this.sessionManager = SharingStage.Instance.Manager.GetSessionManager();
            }

            // Only poll every second.
            if (Time.frameCount % pollingFrequency == 0 && this.sessionManager != null && sessionManager.GetSessionCount() > 0)
            {
                Session currentSession = this.sessionManager.GetCurrentSession();
                if (currentSession != null)
                {
                    int userCount = currentSession.GetUserCount();

                    // If we have fewer users in the current session than are
                    // tracked locally then one or more users have exited.
                    // We need to figure out which ones.
                    if (userCount < userIds.Count)
                    {
                        // Gather all of the new users into a new array.
                        List <long> updatedUserIds = new List <long>();

                        for (int index = 0; index < userCount; index++)
                        {
                            User user   = currentSession.GetUser(index);
                            long userId = user.GetID();
                            updatedUserIds.Add(userId);
                            Debug.Log(index + ": id: " + user.GetID() + " or: " + userId);

                            // It's an edge case, but if a user joins and a user exits at the same
                            // time, we need to handle that.
                            if (userIds.Contains(userId) == false)
                            {
                                SendJoinEvent(user);
                            }
                        }

                        // Now check to see which IDs are in the old userIds list, but not in the new updatedUserIds list.
                        for (int index = 0; index < userIds.Count; index++)
                        {
                            if (updatedUserIds.Contains(userIds[index]) == false)
                            {
                                SendLeaveEvent(userIds[index]);
                            }
                        }

                        userIds = updatedUserIds;
                    }
                    else // Same or more users in the session.
                    {
                        for (int index = 0; index < userCount; index++)
                        {
                            User user   = currentSession.GetUser(index);
                            long userId = user.GetID();
                            if (userIds.Contains(userId) == false)
                            {
                                userIds.Add(userId);
                                SendJoinEvent(user);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 17
0
 public void RemoveUser(User user)
 {
     _users.RemoveAll(u => u.GetID() == user.GetID());
     UpdateUserNames();
 }
        public override void OnUserJoinedSession(Session session, User user)
        {
            LogWriteLine(string.Format("********* USER {0} ({1}) JOINED SESSION  {2} ******", user.GetName().GetString(), user.GetID(), session.GetName().GetString()));

            SessionUserJoined?.Invoke(session, user);
        }