// 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); }
/// <summary> /// Start a session for this device/app. This will always run in the background, /// allowing connecting from other devices, later if needed. /// </summary> /// <returns></returns> public async Task StartAsync() { // Check if we are aloud access var accessStatus = await RemoteSystem.RequestAccessAsync(); if (accessStatus != RemoteSystemAccessStatus.Allowed) { return; } // Get device info var deviceInfo = new EasClientDeviceInformation(); // Create new session of name "SoundByte on Dominic-PC" for example. _manager = new RemoteSystemSessionController($"SoundByte on {deviceInfo.FriendlyName}"); // Handle joining _manager.JoinRequested += async(sender, args) => { // Get the deferral var deferral = args.GetDeferral(); // Run on UI thread await DispatcherHelper.ExecuteOnUIThreadAsync(async() => { var dialog = new MessageDialog($"A device ({args.JoinRequest.Participant.RemoteSystem.DisplayName}) would like to connect to SoundByte and control features such as the current playing track. Do you want to accept this connection?", "SoundByte Connect"); dialog.Commands.Add(new UICommand("Accept", null, 0)); dialog.Commands.Add(new UICommand("Cancel", null, 1)); dialog.CancelCommandIndex = 1; dialog.DefaultCommandIndex = 1; var result = await dialog.ShowAsync(); if ((int)result.Id == 0) { args.JoinRequest.Accept(); } }); deferral.Complete(); }; // Create and start the session var creationResult = await _manager.CreateSessionAsync(); // Check if success, not too worried about failure if (creationResult.Status == RemoteSystemSessionCreationStatus.Success) { _currentSession = creationResult.Session; _currentSession.Disconnected += async(sender, args) => { await NavigationService.Current.CallMessageDialogAsync("Device disconnected: " + args.Reason, "SoundByte Connect"); }; } else { await NavigationService.Current.CallMessageDialogAsync("Failed to create session: " + creationResult.Status, "SoundByte Connect"); } }
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); }
public static async Task CreateSessionAsync() { var status = await RemoteSystem.RequestAccessAsync(); if (status == RemoteSystemAccessStatus.Allowed) { _sessionController = new RemoteSystemSessionController("Connected Experience"); _sessionController.JoinRequested += OnSessionControllerJoinRequested; var result = await _sessionController.CreateSessionAsync(); if (result.Status == RemoteSystemSessionCreationStatus.Success) { DebugString($"Create Session {result.Status}: {result.Session.ControllerDisplayName} {result.Session.DisplayName} {result.Session.Id}"); _currentSession?.Dispose(); _currentSession = result.Session; _mediaChannel = new RemoteSystemSessionMessageChannel(_currentSession, ChannelName); _mediaChannel.ValueSetReceived += OnChannelValueSetReceived; } } }