void Update() { try { // 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(); } // If we are a Primary Client and can join sessions... if (this.sessionManager != null && sessionManager.GetSessionCount() > 0) { // Check to see if we aren't already in the desired session Session currentSession = this.sessionManager.GetCurrentSession(); if (currentSession == null || // We aren't in any session currentSession.GetName().GetString() != this.SessionName || // We're in the wrong session currentSession.GetMachineSessionState() == MachineSessionState.DISCONNECTED) // We aren't joined or joining the right session { Debug.Log("Session conn " + sessionManager.IsServerConnected() + " sessions: " + sessionManager.GetSessionCount()); Debug.Log("Looking for " + SessionName); bool sessionFound = false; for (int i = 0; i < this.sessionManager.GetSessionCount(); ++i) { Session s = this.sessionManager.GetSession(i); Debug.Log(string.Format("session {0}", s.GetName().GetString())); if (s.GetName().GetString() == this.SessionName) { s.Join(); sessionFound = true; break; } } if (sessionManager.IsServerConnected() && !sessionFound) { Debug.Log("Didn't find session, making a new one"); sessionManager.CreateSession(new XString(SessionName)); for (int i = 0; i < this.sessionManager.GetSessionCount(); ++i) { Session s = this.sessionManager.GetSession(i); if (s.GetName().GetString() == this.SessionName) { s.Join(); Debug.Log("Joining our new session"); sessionFound = true; break; } } } } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); } }
private void OnSessionCreatedSuccess(Session session) { using (session) { SessionCreated.RaiseEvent(true, session.GetName().GetString()); } }
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); } }
public override void OnSessionClosed(Session session) { LogWriteLine("********* SESSION " + session.GetName().GetString() + " CLOSED ******"); if (SessionClosed != null) { SessionClosed(session); } }
public override void OnSessionAdded(Session session) { Console.WriteLine("********* SESSION " + session.GetName().GetString() + " ADDED ******"); if (SessionAdded != null) { SessionAdded(session); } }
public override void OnCreateSucceeded(Session newSession) { LogWriteLine("********* SESSION " + newSession.GetName().GetString() + " CREATED ******"); if (CreateSucceeded != null) { CreateSucceeded(newSession); } }
private void OnSessionClosed(Session session) { for (int i = 0; i < Sessions.Count; i++) { if (Sessions[i].GetName().ToString().Equals(session.GetName().ToString())) { SessionClosed.RaiseEvent(Sessions[i]); Sessions.Remove(Sessions[i]); } } }
public SessionData(Session s) { SessionName = s.GetName().ToString(); SessionUserCount = s.GetUserCount().ToString(); SessionType = s.GetSessionType().ToString(); _users = new List<User>(); for (var i = 0; i < s.GetUserCount(); i++) { _users.Add(s.GetUser(i)); } UpdateUserNames(); }
void Update() { if (previousSessionName != SessionName) { sessionCreationRequested = false; previousSessionName = SessionName; } // If we are a Primary Client and can join sessions... if (this.sessionsTracker != null && this.sessionsTracker.Sessions.Count > 0) { // Check to see if we aren't already in the desired session Session currentSession = this.sessionsTracker.GetCurrentSession(); if (currentSession == null || // We aren't in any session currentSession.GetName().GetString() != this.SessionName || // We're in the wrong session currentSession.GetMachineSessionState() == MachineSessionState.DISCONNECTED) // We aren't joined or joining the right session { Debug.Log("Session conn " + this.sessionsTracker.IsServerConnected + " sessions: " + this.sessionsTracker.Sessions.Count); Debug.Log("Looking for " + SessionName); bool sessionFound = false; for (int i = 0; i < this.sessionsTracker.Sessions.Count; ++i) { Session session = this.sessionsTracker.Sessions[i]; if (session.GetName().GetString() == this.SessionName) { this.sessionsTracker.JoinSession(session); sessionFound = true; break; } } if (this.sessionsTracker.IsServerConnected && !sessionFound && !sessionCreationRequested) { Debug.Log("Didn't find session, making a new one"); if (this.sessionsTracker.CreateSession(new XString(SessionName))) { sessionCreationRequested = true; } } } } }
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); }
public override void OnSessionClosed(Session session) { LogWriteLine("********* SESSION " + session.GetName().GetString() + " CLOSED ******"); SessionClosed?.Invoke(session); }
public override void OnCreateSucceeded(Session newSession) { LogWriteLine("********* SESSION " + newSession.GetName().GetString() + " CREATED ******"); CreateSucceeded?.Invoke(newSession); }
private SessionData FindSession(Session session) { if (session == null) //TODO: log? return null; return _sessions.FirstOrDefault(s => s.SessionName == session.GetName()); }