private void RenderingControl_OnUPnPEvent(UPnPService sender, long SEQ) { Match match; string lastChange = (string)sender.GetStateVariable("LastChange"); // Volume change // <Event xmlns="urn:schemas-upnp-org:metadata-1-0/RCS/"><InstanceID val="0"><Volume Channel="Master" val="61"/><VolumeDB Channel="Master" val="-1829"/></InstanceID></Event> if ((match = rcVolumeRegex.Match(lastChange)).Success) { string volume = match.Groups["volume"].Value; Console.WriteLine("Volume Change: " + volume); if (OnVolumeChanged != null) { OnVolumeChanged(this, int.Parse(volume)); } } // Mute change // <Event xmlns="urn:schemas-upnp-org:metadata-1-0/RCS/"><InstanceID val="0"><Mute Channel="Master" val="1"/></InstanceID></Event> else if ((match = rcMuteRegex.Match(lastChange)).Success) { string mute = match.Groups["mute"].Value; Console.WriteLine("Mute Change: " + mute); if (OnMuteChanged != null) { OnMuteChanged(this, int.Parse(mute) == 1); } } // other events... else { Console.WriteLine("RenderingControl Event " + SEQ + " " + sender.ServiceID + " " + lastChange); } }
private void AVTransport_OnUPnPEvent(UPnPService sender, long SEQ) { Match match; string lastChange = (string)sender.GetStateVariable("LastChange"); // TransportState change // <Event xmlns="urn:schemas-upnp-org:metadata-1-0/AVT/"><InstanceID val="0"><TransportState val="PLAYING"/></InstanceID></Event> // <Event xmlns="urn:schemas-upnp-org:metadata-1-0/AVT/"><InstanceID val="0"><TransportState val="PAUSED_PLAYBACK"/></InstanceID></Event> // <Event xmlns="urn:schemas-upnp-org:metadata-1-0/AVT/"><InstanceID val="0"><TransportState val="STOPPED"/></InstanceID></Event> if ((match = avTransportStateRegex.Match(lastChange)).Success) { string state = match.Groups["state"].Value; Console.WriteLine("TransportState Change: " + state); if (OnPlaybackChanged != null) { OnPlaybackChanged(this, (state == "PLAYING" || state == "PAUSED_PLAYBACK")); } } // other events... else { Console.WriteLine("AVTransport Event " + SEQ + " " + sender.ServiceID + " " + lastChange); } }
public object GetStateVariable(string VarName) { return(S.GetStateVariable(VarName)); }
private static void AddWeMoSwitch() { var localDevice = UPnPDevice.CreateRootDevice(/* expiration */ 3600, /* version*/ 1, /* web dir */ null); localDevice.StandardDeviceType = "urn:Belkin:device:controllee"; localDevice.UniqueDeviceName = "Lightswitch-32f9a52c-79d2-4ae2-8957-1f5a0f044e36"; localDevice.FriendlyName = "Test Lamp"; //localDevice.Icon = null; //localDevice.HasPresentation = true; //localDevice.PresentationURL = presentationUrl; localDevice.Major = 1; localDevice.Minor = 0; localDevice.SerialNumber = "1234567890"; localDevice.ModelNumber = "3.1234"; localDevice.Manufacturer = "Belkin International Inc."; localDevice.ManufacturerURL = "http://www.belkin.com"; localDevice.ModelName = "Socket"; localDevice.ModelDescription = "Belkin Plugin Socket 1.0"; /*if (Uri.IsWellFormedUriString(manufacturerUrl, UriKind.Absolute)) * { * localDevice.ModelURL = new Uri(manufacturerUrl); * } */ localDevice.UserAgentTag = "redsonic"; // Create an instance of the BasicEvent service dynamic instance = new ExpandoObject(); // Declare the "BasicEvent1" service var service = new UPnPService( // Version 1.0, // Service ID "urn:Belkin:serviceId:basicevent1", // Service Type "urn:Belkin:service:basicevent:1", // Standard Service? true, // Service Object Instance instance ); service.ControlURL = "/upnp/control/basicevent1"; service.EventURL = "/upnp/event/basicevent1"; service.SCPDURL = "/eventservice.xml"; string stateVarName = "BinaryState"; var stateVariable = new UPnPStateVariable(stateVarName, typeof(bool), true); stateVariable.AddAssociation("GetBinaryState", stateVarName); stateVariable.AddAssociation("SetBinaryState", stateVarName); stateVariable.Value = false; service.AddStateVariable(stateVariable); instance.GetBinaryState = new Func <bool>(() => (bool)service.GetStateVariable(stateVarName)); instance.SetBinaryState = new Action <int>((BinaryState) => { Console.WriteLine("SetBinaryState({0})", BinaryState); service.SetStateVariable(stateVarName, BinaryState != 0); }); // Add the methods service.AddMethod("GetBinaryState", stateVarName); service.AddMethod("SetBinaryState", stateVarName); // Add the service localDevice.AddService(service); // Start the WeMo switch device UPnP simulator localDevice.StartDevice(); }