public SimpleChromecast(ILogger logger, ChromecastDevice device, Uri playUri, TimeSpan?duration, double?volume)
 {
     this.volume   = volume;
     this.duration = duration;
     this.playUri  = playUri;
     this.device   = device;
     this.logger   = logger;
 }
예제 #2
0
        private string BuildAddNewWebPageBody([AllowNull] ChromecastDevice device)
        {
            string name = device != null?device.Name.ToString() : string.Empty;

            string ip = device != null?device.DeviceIP.ToString() : string.Empty;

            string id          = device != null ? device.Id : string.Empty;
            string buttonLabel = device != null ? "Save" : "Add";
            string header      = device != null ? "Edit" : "Add New";
            int    volume      = device != null ? (device.Volume ?? -1) : -1;

            StringBuilder stb = new StringBuilder();

            stb.Append(FormStart("ftmDeviceChange", "IdChange", "Post"));

            stb.Append(@"<div>");
            stb.Append(@"<table class='full_width_table'>");
            stb.Append("<tr height='5'><td style='width:25%'></td><td style='width:20%'></td><td style='width:55%'></td></tr>");
            stb.Append(Invariant($"<tr><td class='tableheader' colspan=3>{header}</td></tr>"));
            stb.Append(Invariant($"<tr><td class='tablecell'>Name:</td><td class='tablecell' colspan=2>{HtmlTextBox(NameId, name, @readonly: !string.IsNullOrEmpty(id))}</td></tr>"));
            stb.Append(Invariant($"<tr><td class='tablecell'>DeviceIP:</td><td class='tablecell' colspan=2>{HtmlTextBox(DeviceIPId, ip)}</td></tr>"));
            stb.Append("<tr><td class='tablecell'>Volume:</td><td class='tablecell' colspan=2>");

            var volumeDropDown = new clsJQuery.jqDropList(NameToId(VolumeId), PageName, false)
            {
                toolTip      = "Select Volume of device when Spoken",
                autoPostBack = false,
            };

            volumeDropDown.AddItem("Don't Change", NoValueForVoice, volume == -1);

            foreach (var value in Enumerable.Range(1, 100))
            {
                var stringValue = value.ToString(CultureInfo.InvariantCulture);
                volumeDropDown.AddItem(stringValue, stringValue, volume == value);
            }

            stb.Append(volumeDropDown.Build());
            stb.Append("</td></tr>");
            stb.Append(Invariant($"<tr><td colspan=3>{HtmlTextBox(DeviceIdId, id, type: "hidden")}<div id='{SaveErrorDivId}' style='color:Red'></div></td><td></td></tr>"));
            stb.Append(Invariant($"<tr><td colspan=3>{FormPageButton(SaveDeviceName, buttonLabel)}"));

            if (device != null)
            {
                stb.Append(FormPageButton(DeleteDeviceName, "Delete"));
            }

            stb.Append(FormPageButton(CancelDeviceName, "Cancel"));
            stb.Append(Invariant($"</td><td></td></tr>"));
            stb.Append("<tr height='5'><td colspan=3></td></tr>");
            stb.Append(@"</table>");
            stb.Append(@"</div>");
            stb.Append(FormEnd());

            return(stb.ToString());
        }
 public SimpleChromecast(ChromecastDevice device,
                         Uri playUri,
                         string contentType            = null,
                         bool live                     = false,
                         [AllowNull] TimeSpan?duration = null,
                         [AllowNull] double?volume     = null)
 {
     this.volume      = volume;
     this.duration    = duration;
     this.playUri     = playUri;
     this.contentType = contentType;
     this.live        = live;
     this.device      = device;
 }
예제 #4
0
        public virtual async Task StartDevice()
        {
            var chromeCastReport = Report as ChromecastDeviceDiscoveryReportItem;

            Device = new ChromecastDevice(chromeCastReport);
            Client = new ChromecastClient(chromeCastReport.EndPoint.Address, 8009);   // <-- dat port number :(

            ConnectionChannel = Client.CreateChannel(DialConstants.DialConnectionUrn);
            HeartbeatChannel  = Client.CreateChannel(DialConstants.DialHeartbeatUrn);
            ReceiverChannel   = Client.CreateChannel(DialConstants.DialReceiverUrn);
            MediaChannel      = Client.CreateChannel(DialConstants.DialMediaUrn);

            await Client.Connect();

            Client.Listen();

            // Send the connect message
            Client.Write(MessageFactory.Connect());

            Client.StartHeartbeat();
        }
예제 #5
0
        /// <summary>
        /// The user has selected a control on the configuration web page.
        /// The post data is provided to determine the control that initiated the post and the state of the other controls.
        /// </summary>
        /// <param name="data">The post data.</param>
        /// <param name="user">The name of logged in user.</param>
        /// <param name="userRights">The rights of the logged in user.</param>
        /// <returns>Any serialized data that needs to be passed back to the web page, generated by the clsPageBuilder class.</returns>
        public string PostBackProc(string data, [AllowNull] string user, int userRights)
        {
            NameValueCollection parts = HttpUtility.ParseQueryString(data);

            string form = parts["id"];

            if (form == NameToIdWithPrefix(SaveDeviceName))
            {
                StringBuilder results = new StringBuilder();

                // Validate
                IPAddress ipAddress = null;
                if (string.IsNullOrWhiteSpace(parts[DeviceIPId]) ||
                    !IPAddress.TryParse(parts[DeviceIPId], out ipAddress))
                {
                    results.AppendLine("IP Address is not Valid.<br>");
                }

                string name = parts[NameId];
                if (string.IsNullOrWhiteSpace(name))
                {
                    results.AppendLine("Name is not Valid.<br>");
                }

                if (results.Length > 0)
                {
                    divToUpdate.Add(SaveErrorDivId, results.ToString());
                }
                else
                {
                    string deviceId = parts[DeviceIdId];
                    if (string.IsNullOrWhiteSpace(deviceId))
                    {
                        deviceId = name.Replace(' ', '_').Replace('.', '_');
                    }

                    string volumeString = parts[VolumeId];
                    short  volume;

                    if (!short.TryParse(volumeString, NumberStyles.Any, CultureInfo.InvariantCulture, out volume))
                    {
                        volume = -1;
                    }

                    var device = new ChromecastDevice(deviceId, parts[NameId], ipAddress, volume == -1 ? null : (ushort?)volume);

                    pluginConfig.AddDevice(device);
                    pluginConfig.FireConfigChanged();
                    divToUpdate.Add(SaveErrorDivId, RedirectPageJS(Invariant($"/{HttpUtility.UrlEncode(ConfigPage.Name)}")));
                }
            }
            else if (form == NameToIdWithPrefix(CancelDeviceName))
            {
                divToUpdate.Add(SaveErrorDivId, RedirectPageJS(Invariant($"/{HttpUtility.UrlEncode(ConfigPage.Name)}")));
            }
            else if (form == NameToIdWithPrefix(DeleteDeviceName))
            {
                pluginConfig.RemoveDevice(parts[DeviceIdId]);
                pluginConfig.FireConfigChanged();
                divToUpdate.Add(SaveErrorDivId, RedirectPageJS(Invariant($"/{HttpUtility.UrlEncode(ConfigPage.Name)}")));
            }
            else if (form == NameToIdWithPrefix(SaveSettingName))
            {
                StringBuilder results = new StringBuilder();

                // Validate
                IPAddress ipAddress = null;
                if (!string.IsNullOrWhiteSpace(parts[ServerIPAddressId]))
                {
                    if (!IPAddress.TryParse(parts[ServerIPAddressId], out ipAddress))
                    {
                        results.AppendLine("Server IP Address is not Valid.<br>");
                    }
                }

                ushort port = 0;
                if (string.IsNullOrWhiteSpace(parts[ServerPortId]) ||
                    !ushort.TryParse(parts[ServerPortId], NumberStyles.Any, CultureInfo.InvariantCulture, out port))
                {
                    results.AppendLine("Port is not Valid.<br>");
                }

                if (results.Length > 0)
                {
                    divToUpdate.Add(SaveErrorDivId, results.ToString());
                }
                else
                {
                    string sapiVoice = parts[SapiVoiceId];

                    sapiVoice = (sapiVoice == null) || (sapiVoice == NoValueForVoice) ? null : sapiVoice;

                    pluginConfig.WebServerPort      = port;
                    pluginConfig.WebServerIPAddress = ipAddress;
                    pluginConfig.DebugLogging       = parts[NameToId(DebugLoggingId)] == "checked";
                    pluginConfig.ForwardSpeach      = parts[NameToId(FormatSpeechId)] == "checked";
                    pluginConfig.SAPIVoice          = sapiVoice;
                    pluginConfig.FireConfigChanged();
                    divToUpdate.Add(SaveErrorDivId, string.Empty);
                }
            }

            return(base.postBackProc(Name, data, user, userRights));
        }