예제 #1
0
        private void OnReceiveReceiverStatus(MessageReceiverStatus receiverStatusMessage)
        {
            if (receiverStatusMessage != null && receiverStatusMessage.status != null && receiverStatusMessage.status.applications != null)
            {
                onVolumeUpdate(receiverStatusMessage.status.volume);

                var deviceApplication = receiverStatusMessage.status.applications.Where(a => a.appId.Equals("CC1AD845"));
                if (deviceApplication.Any())
                {
                    chromeCastDestination          = deviceApplication.First().transportId;
                    chromeCastApplicationSessionNr = deviceApplication.First().sessionId;

                    if (getDeviceState().Equals(DeviceState.LaunchingApplication))
                    {
                        setDeviceState(DeviceState.LaunchedApplication, null);
                        Connect(chromeCastSource, chromeCastDestination);
                        LoadMedia();
                    }
                }
            }

            if (lastVolumeSetItem != null && lastVolumeSetItem.RequestId == receiverStatusMessage.requestId)
            {
                lastVolumeSetItem = null;
                SendVolumeSet();
            }
        }
 public void VolumeSet(Volume volumeSetting)
 {
     nextVolumeSetItem = new VolumeSetItem {
         Setting = volumeSetting
     };
     SendVolumeSet();
 }
예제 #3
0
 public void VolumeSet(Volume volumeSetting)
 {
     if (isConnected())
     {
         nextVolumeSetItem = new VolumeSetItem {
             Setting = volumeSetting
         };
         SendVolumeSet();
     }
 }
예제 #4
0
        /// <summary>
        /// Set the volume to the new level.
        /// </summary>
        /// <param name="volumeSetting">the new volume level</param>
        public void VolumeSet(Volume volumeSetting)
        {
            if (volumeSetting == null || IsDisposed)
            {
                return;
            }

            nextVolumeSetItem = new VolumeSetItem {
                Setting = volumeSetting
            };
            SendVolumeSet();
        }
예제 #5
0
 private void SendVolumeSet()
 {
     if ((nextVolumeSetItem != null && lastVolumeSetItem == null) ||
         (lastVolumeSetItem != null && DateTime.Now.Subtract(lastVolumeSetItem.SendAt) > new TimeSpan(0, 0, 1)))
     {
         lastVolumeSetItem           = nextVolumeSetItem;
         lastVolumeSetItem.RequestId = GetNextRequestId();
         lastVolumeSetItem.SendAt    = DateTime.Now;
         SendMessage(chromeCastMessages.GetVolumeSetMessage(lastVolumeSetItem.Setting, lastVolumeSetItem.RequestId));
         nextVolumeSetItem = null;
     }
 }
예제 #6
0
        /// <summary>
        /// Handle a receiver status message from the device.
        /// </summary>
        /// <param name="receiverStatusMessage">a receiver status message</param>
        private void OnReceiveReceiverStatus(MessageReceiverStatus receiverStatusMessage)
        {
            if (receiverStatusMessage == null)
            {
                return;
            }

            if (receiverStatusMessage?.status?.volume != null)
            {
                device.OnVolumeUpdate(receiverStatusMessage.status.volume);
            }

            var statusText = receiverStatusMessage?.status?.applications?.FirstOrDefault()?.statusText;

            statusText = statusText?.Replace("Default Media Receiver", string.Empty);
            var state = device.GetDeviceState();

            if (state == DeviceState.ConnectError || state == DeviceState.NotConnected || state == DeviceState.Closed)
            {
                device.SetDeviceState(DeviceState.Connected, null);
                Connected = true;
            }
            device.SetDeviceState(device.GetDeviceState(), $" {statusText}");

            if (receiverStatusMessage != null && receiverStatusMessage.status != null && receiverStatusMessage.status.applications != null)
            {
                var deviceApplication = receiverStatusMessage.status.applications.Where(a => a.appId.Equals("CC1AD845"));
                if (deviceApplication.Any())
                {
                    chromeCastDestination          = deviceApplication.First().transportId;
                    chromeCastApplicationSessionNr = deviceApplication.First().sessionId;

                    if (device.GetDeviceState().Equals(DeviceState.LaunchingApplication))
                    {
                        device.SetDeviceState(DeviceState.LaunchedApplication, null);
                        Connect(chromeCastSource, chromeCastDestination);
                        LoadMedia();
                    }
                }
            }

            if (lastVolumeSetItem != null && lastVolumeSetItem.RequestId == receiverStatusMessage.requestId)
            {
                lastVolumeSetItem = null;
                SendVolumeSet();
            }
        }