// Creates a new session, shared experience, for particpants to join // Handles incoming requests to join the newly created session public async Task <bool> CreateSession(string sessionName) { bool status = false; RemoteSystemAccessStatus accessStatus = await RemoteSystem.RequestAccessAsync(); // Checking that remote system access is allowed - ensure capability in the project manifest is set if (accessStatus != RemoteSystemAccessStatus.Allowed) { return(status); } m_currentSessionName = sessionName; SendDebugMessage($"Creating session {m_currentSessionName}..."); var manager = new RemoteSystemSessionController(m_currentSessionName); // Handles incoming requests to join the session. manager.JoinRequested += Manager_JoinRequested; try { // Create session RemoteSystemSessionCreationResult createResult = await manager.CreateSessionAsync(); if (createResult.Status == RemoteSystemSessionCreationStatus.Success) { RemoteSystemSession currentSession = createResult.Session; // Handles disconnect currentSession.Disconnected += (sender, args) => { SessionDisconnected(sender, args); }; m_currentSession = currentSession; SendDebugMessage($"Session {m_currentSession.DisplayName} created successfully."); status = true; } // Session creation has reached a maximum - message user that there are too many sessions else if (createResult.Status == RemoteSystemSessionCreationStatus.SessionLimitsExceeded) { status = false; SendDebugMessage("Session limits exceeded."); } // Failed to create the session else { status = false; SendDebugMessage("Failed to create session."); } } catch (Win32Exception) { status = false; SendDebugMessage("Failed to create session."); } return(status); }
public async void OnCreateRemoteSystemSessionClick(object sender, RoutedEventArgs e) { if (sessionController != null) { return; } // 加入 option 限制只有被邀請的人才可以加入 //RemoteSystemSessionOptions options = new RemoteSystemSessionOptions() //{ // IsInviteOnly = true //}; sessionController = new RemoteSystemSessionController("today is happy day"); sessionController.JoinRequested += SessionController_JoinRequested; // 建立一個 Remote Session RemoteSystemSessionCreationResult result = await sessionController.CreateSessionAsync(); if (result.Status == RemoteSystemSessionCreationStatus.Success) { currentSession = result.Session; currentSession.Disconnected += (obj, args) => { // 代表從該 Session 離線了 Debug.WriteLine($"session_disconnected: {args.Reason.ToString()}"); }; RegistMessageChannel(currentSession, currentSession.DisplayName); // 註冊有哪些參與者加入或離開 SubscribeParticipantWatcher(currentSession); if (currentRemoteSystem != null) { try { var inviationResult = await currentSession.SendInvitationAsync(currentRemoteSystem); } catch (Exception ex) { Debug.WriteLine(ex); } } Log = currentSession.DisplayName; } }
public async Task <bool> createSession() { bool status = false; // m_currentSessionName = "JC Rome Sample"; var manager = new RemoteSystemSessionController("JC Rome Sample"); manager.JoinRequested += JoinRequested; try { RemoteSystemSessionCreationResult createResult = await manager.CreateSessionAsync(); if (createResult.Status == RemoteSystemSessionCreationStatus.Success) { RemoteSystemSession currentSession = createResult.Session; currentSession.Disconnected += (sender, args) => { //SessionDisconnected(sender, args); Debug.WriteLine("disconected"); }; m_currentSession = currentSession; printSessionStatus($"Session {m_currentSession.DisplayName} created successfully."); status = true; StartRecievingMessages(); } else if (createResult.Status == RemoteSystemSessionCreationStatus.SessionLimitsExceeded) { status = false; printSessionStatus("Session limits exceeded."); } else { status = false; printSessionStatus("Failed to create session."); } } catch (Win32Exception) { status = false; printSessionStatus("Failed to Create Session"); } return(status); }