Пример #1
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);
        }
        public void OnSubscribeAndHandleInvoke(object sender, RoutedEventArgs args)
        {
            invitationListener = new RemoteSystemSessionInvitationListener();
            // 註冊處理來自其他 RemoteSystem 發出的 RemoteSession 邀請
            invitationListener.InvitationReceived += async(s, e) =>
            {
                // 未加入前,是利用 RemoteSystemInfo 做 JoinAsync()
                RemoteSystemSessionJoinResult joinResult = await e.Invitation.SessionInfo.JoinAsync();

                if (joinResult.Status == RemoteSystemSessionJoinStatus.Success)
                {
                    // 注冊訊息通道做資料傳遞
                    RegistMessageChannel(currentSession, currentSession.DisplayName);
                    // 註冊有哪些參與者加入或離開
                    SubscribeParticipantWatcher(currentSession);
                }
            };
        }
Пример #3
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;
        }