Ejemplo n.º 1
0
        public async Task <bool> SendMessageToParticipant(string message, RemoteSystemSessionParticipant participant)
        {
            bool status = false;

            if (m_msgChannel == null)
            {
                m_msgChannel = new RemoteSystemSessionMessageChannel(m_currentSession, "ParticipantChannel");
            }
            byte[] data;
            using (var stream = new MemoryStream())
            {
                new DataContractJsonSerializer(message.GetType()).WriteObject(stream, message);
                data = stream.ToArray();
            }
            // Send message to specific participant, in this case, the host.
            ValueSet sentMessage = new ValueSet
            {
                [Key] = data
            };
            await m_msgChannel.SendValueSetAsync(sentMessage, participant);

            //Debug.WriteLine($"Message successfully sent to {Particpant}");
            status = true;
            return(status);
        }
Ejemplo n.º 2
0
        // Send simple message to all session participants
        // Send simple message to specific session participants
        // Receive message

        public async Task SendMessageToParticipantsAsync(object message)
        {
            try
            {
                // The messaging channel accepts a string, channel name - "Everyone" - all
                if (m_appMessageChannel == null)
                {
                    m_appMessageChannel = new RemoteSystemSessionMessageChannel(m_currentSession, "Everyone");
                }
            }

            catch (Win32Exception)
            {
                SendDebugMessage("Failed to send message to all paticipants.");
            }

            using (var stream = new MemoryStream())
            {
                new DataContractJsonSerializer(message.GetType()).WriteObject(stream, message);
                byte[] data = stream.ToArray();

                // Send message to all
                ValueSet sentMessage = new ValueSet {
                    [Key] = data
                };

                // Send specific participants
                await m_appMessageChannel.BroadcastValueSetAsync(sentMessage);
            }
        }
Ejemplo n.º 3
0
        public async Task <bool> SendMessageToHostAsync(string message)
        {
            bool status = false;

            try
            {
                if (m_msgChannel == null)
                {
                    m_msgChannel = new RemoteSystemSessionMessageChannel(m_currentSession, "OpenChannel");
                }

                byte[] data;
                using (var stream = new MemoryStream())
                {
                    new DataContractJsonSerializer(message.GetType()).WriteObject(stream, message);
                    data = stream.ToArray();
                }
                // Send message to specific participant, in this case, the host.
                ValueSet sentMessage = new ValueSet
                {
                    [Key] = data
                };
                // await m_msgChannel.SendValueSetAsync(sentMessage, SessionHost);
                await m_msgChannel.BroadcastValueSetAsync(sentMessage);

                Debug.WriteLine("Message successfully sent to host.");
                status = true;
            }
            catch (Win32Exception)
            {
                Debug.WriteLine("failed to end host msg");
            }
            return(status);
        }
        private void RegistMessageChannel(RemoteSystemSession session, string channelName)
        {
            if (appMessageChannel != null)
            {
                appMessageChannel.ValueSetReceived -= AppMessageChannel_ValueSetReceived;
                appMessageChannel = null;
            }

            appMessageChannel = new RemoteSystemSessionMessageChannel(session, channelName);
            appMessageChannel.ValueSetReceived += AppMessageChannel_ValueSetReceived;
        }
Ejemplo n.º 5
0
        private async void Event_ValueSetRecieved(RemoteSystemSessionMessageChannel sender, RemoteSystemSessionValueSetReceivedEventArgs args)
        {
            //code
            Debug.WriteLine("ValueSetRecieved");
            Debug.WriteLine(args.Message[Key]);
            byte[] by     = (byte[])args.Message[Key];
            string result = System.Text.Encoding.UTF8.GetString(by);

            Debug.WriteLine(result);
            //await BroadcastMessage("HelloWorld", "HelloWorld");
        }
Ejemplo n.º 6
0
 public void StartReceivingMessages()
 {
     m_appMessageChannel = new RemoteSystemSessionMessageChannel(m_currentSession, "Everyone");
     m_appMessageChannel.ValueSetReceived += (sender, args) =>
     {
         ValueSet receivedMessage = args.Message;
         MessageReceived(this, new MessageReceivedEventArgs()
         {
             ReceivedMessage = receivedMessage[Key], Id = args.Sender.RemoteSystem.Id
         });
     };
 }
        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;
            }
        }
Ejemplo n.º 8
0
        private async void Event_ValueSetRecieved(RemoteSystemSessionMessageChannel sender, RemoteSystemSessionValueSetReceivedEventArgs args)
        {
            string senderdisplayname = args.Sender.RemoteSystem.DisplayName;

            //Debug.WriteLine(args.Message[Key]);
            byte[] by     = (byte[])args.Message[Key];
            string result = System.Text.Encoding.UTF8.GetString(by);
            //Debug.WriteLine(result);
            //Debug.WriteLine(sender.ToString());
            string recv = senderdisplayname + ": " + result;

            receivedtext.DataContext = new TextboxText()
            {
                textdata = recv
            };
        }
        private void AppMessageChannel_ValueSetReceived(RemoteSystemSessionMessageChannel sender, RemoteSystemSessionValueSetReceivedEventArgs args)
        {
            ValueSet receivedMessage = args.Message;

            if (receivedMessage != null)
            {
                MessageData msgData = new MessageData();
                byte[]      data    = receivedMessage["Key"] as byte[];
                using (MemoryStream ms = new MemoryStream(data))
                {
                    DataContractJsonSerializer ser = new DataContractJsonSerializer(msgData.GetType());
                    msgData = ser.ReadObject(ms) as MessageData;
                }

                Log = msgData.Content;
            }
        }
Ejemplo n.º 10
0
        public async Task <bool> SendMessageToHostAsync(object message)
        {
            bool status = false;

            // Host isn't enumerated, so message can't be sent.
            if (!EnumerationCompleted)
            {
                return(status);
            }

            try
            {
                if (m_appMessageChannel == null)
                {
                    m_appMessageChannel = new RemoteSystemSessionMessageChannel(m_currentSession, "Everyone");
                }

                byte[] data;
                using (var stream = new MemoryStream())
                {
                    new DataContractJsonSerializer(message.GetType()).WriteObject(stream, message);
                    data = stream.ToArray();
                }

                // Send message to specific participant, in this case, the host.
                ValueSet sentMessage = new ValueSet
                {
                    [Key] = data
                };
                await m_appMessageChannel.SendValueSetAsync(sentMessage, SessionHost);

                SendDebugMessage("Message successfully sent to host.");
                status = true;
            }
            catch (Win32Exception)
            {
                SendDebugMessage("Failed to send message to host.");
                status = false;
            }

            return(status);
        }
        private static void OnChannelValueSetReceived(RemoteSystemSessionMessageChannel sender, RemoteSystemSessionValueSetReceivedEventArgs args)
        {
            DebugString($"Received Message {args.Sender.RemoteSystem.DisplayName}: {args.Sender.GetHostNames()[0]}");
            var messageTypeString = args.Message["Type"] as string;

            switch (messageTypeString)
            {
            case "PositionData":
                var dragPosition = float.Parse(args.Message["DragPosition"].ToString());
                PositionDataUpdated?.Invoke(sender, dragPosition);
                break;

            case "MediaData":
                var cardJson            = args.Message["CardJson"].ToString();
                var mediaPlayedPosition = TimeSpan.Parse(args.Message["MediaPlayedPosition"].ToString());
                var mediaUrl            = args.Message["MediaUrl"].ToString();
                MediaDataUpdated?.Invoke(sender, new MediaDataEventArgs(cardJson, mediaPlayedPosition, mediaUrl));
                break;
            }
        }
        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;
                }
            }
        }
Ejemplo n.º 13
0
 //MOVE TO CREATESESSION PAGE
 //THIS IS FOR THE CONTROLLER TO RECIEVE MESSAGES
 public async void StartRecievingMessages()
 {
     Debug.WriteLine("StartRecievingMessages");
     m_msgChannel = new RemoteSystemSessionMessageChannel(m_currentSession, "OpenChannel");
     m_msgChannel.ValueSetReceived += Event_ValueSetRecieved; //raises event that data was received
 }