コード例 #1
0
        public static async Task JoinSessionAsync(RemoteSystemSessionInfo sessionInfo)
        {
            var info = await sessionInfo.JoinAsync();

            if (info.Status == RemoteSystemSessionJoinStatus.Success)
            {
                _currentSession?.Dispose();
                _currentSession = info.Session;

                _mediaChannel = new RemoteSystemSessionMessageChannel(_currentSession, ChannelName);
                _mediaChannel.ValueSetReceived += OnChannelValueSetReceived;
            }
        }
コード例 #2
0
        public void OnDescoverSessionAsync(object sender, RoutedEventArgs e)
        {
            if (sessionWatcher != null)
            {
                return;
            }

            // 建立 Watcher 來查看有哪些 Sessions 被建立或是刪除
            sessionWatcher = RemoteSystemSession.CreateWatcher();

            sessionWatcher.Added += (s, a) => {
                // 將找到的 RemoteSystemInfo 加入 UI 顯示
                RemoteSystemSessionInfo sessionInfo = a.SessionInfo;

                var addedTask = dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    sessionList.Add(sessionInfo);
                });
            };

            sessionWatcher.Removed += (s, a) => {
                // 將已經結束的 session 從 UI 移除
                var removedSession = a.SessionInfo;
                var exist          = sessionList.Where(x => x.ControllerDisplayName == removedSession.ControllerDisplayName && x.DisplayName == removedSession.DisplayName).FirstOrDefault();

                if (exist != null)
                {
                    var removedTask = dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        sessionList.Remove(exist);
                    });
                }
            };

            sessionWatcher.Updated += (s, a) => {
                // 講更新的 RemoteSystemInfo 加入到 UI
                var updatedSession = a.SessionInfo;
                var exist          = sessionList.Where(x => x.ControllerDisplayName == updatedSession.ControllerDisplayName && x.DisplayName == updatedSession.DisplayName).FirstOrDefault();

                if (exist != null)
                {
                    var updatedTask = dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        sessionList.Remove(exist);
                        sessionList.Add(updatedSession);
                    });
                }
            };

            sessionWatcher.Start();
        }
コード例 #3
0
        // Joins the current session, handles session disconnect - rejoin TBD
        public async Task <bool> JoinSession(RemoteSystemSessionInfo session, string name)
        {
            bool status = false;

            RemoteSystemSessionJoinResult joinResult = await session.JoinAsync();

            var watcher = joinResult.Session.CreateParticipantWatcher();

            watcher.Added += (s, e) =>
            {
                if (e.Participant.RemoteSystem.DisplayName.Equals(session.ControllerDisplayName))
                {
                    SessionHost = e.Participant;
                }
            };

            watcher.EnumerationCompleted += (s, e) =>
            {
                EnumerationCompleted = true;

                if (SessionHost == null)
                {
                    SendDebugMessage("Session host was not found during enumeration.");
                }
            };

            watcher.Start();

            // Checking that remote system access is allowed - ensure capability in the project manifest is set
            if (joinResult.Status == RemoteSystemSessionJoinStatus.Success)
            {
                // Join session
                m_currentSession = joinResult.Session;

                // Handles disconnect
                m_currentSession.Disconnected += (sender, args) =>
                {
                    SendDebugMessage("Session was disconnected.");
                    SessionDisconnected(sender, args);
                };

                status = true;
            }
            else
            {
                status = false;
                SendDebugMessage("Failed to join.");
            }

            return(status);
        }
コード例 #4
0
        private async void selectSession(object sender, SelectionChangedEventArgs e)
        {
            //bool status = false;
            RemoteSystemSessionInfo sessionInfo = ((sender as ListBox).SelectedItem as RemoteSystemSessionInfo);

            Debug.WriteLine($"Session {sessionInfo.DisplayName} selected");
            //Request to Join
            RemoteSystemSessionJoinResult joinresult = await sessionInfo.JoinAsync();

            //create a particpant watcher
            //var watcher = joinresult.Session.CreateParticipantWatcher();
            //event that a watcher is added:

            /**
             * watcher.Added += (s, e1) => {
             *  if (e1.Participant.RemoteSystem.DisplayName.Equals(sessionInfo.ControllerDisplayName))
             *  {
             *      SessionHost = e1.Participant;
             *      Debug.WriteLine("added");
             *      Debug.WriteLine($"{e1.Participant.RemoteSystem.DisplayName}");
             *      Debug.WriteLine($"{s}");
             *      SessionHost = e1.Participant;
             *
             *  }
             * };
             * watcher.Start();
             **/
            //process the result to ensure remote system access is allowed
            if (joinresult.Status == RemoteSystemSessionJoinStatus.Success)
            {
                //successful join
                Debug.WriteLine($"Session {sessionInfo.DisplayName} Joined Successfully");
                m_currentSession = joinresult.Session;
                //status = true;
            }

            StartRecievingMessages();
            await SendMessageToHostAsync("hello world");

            // return status;
        }