private async Task subscribe(NetWorkSubscriberPayload payload) { if (string.IsNullOrEmpty(netWorkSocketListener.Hostname)) { return; } try { HttpClient httpClient = new HttpClient(); HttpRequestMessage request = new HttpRequestMessage(new HttpMethod("SUBSCRIBE"), new Uri(payload.URI)); request.Headers.Add("User-Agent", "RaumfeldControl/0.0 RaumfeldProtocol/1"); /* RaumfeldControl/3.6 RaumfeldProtocol/399 Build => https://github.com/masmu/pulseaudio-dlna/issues/227 */ request.Headers.Add("Accept-Language", "en"); request.Headers.Add("ContentType", "text/xml; charset=\"utf - 8\""); request.Headers.Add("CALLBACK", "<" + netWorkSocketListener.Hostname + ">"); request.Headers.Add("NT", "upnp:event"); request.Headers.Add("TIMEOUT", "Second-300"); HttpResponseMessage response = await httpClient.SendRequestAsync(request, HttpCompletionOption.ResponseHeadersRead); if (response.StatusCode == Windows.Web.Http.HttpStatusCode.Ok) { SubscriberDictionary[payload] = response.Headers["SID"]; if (Timer == null) { Timer = ThreadPoolTimer.CreatePeriodicTimer(async(t) => { await updateSubscribe(); }, TimeSpan.FromSeconds(240)); } } else { await messagingService.ShowErrorDialogAsync(string.Format("{0}: {1}", response.StatusCode, await response.Content.ReadAsStringAsync())); } } catch (Exception) { throw new Exception(); } }
private void onRaumFeldEventPropertySetReceived(RaumFeldEventPropertySet args) { NetWorkSubscriberPayload payload = SubscriberDictionary.Select(d => d).Where(d => d.Value == args.EventSID).FirstOrDefault().Key; if (payload == null) { return; } foreach (var property in args.Properties) { if (property.SystemUpdateID != null) { RaumFeldEvent raumFeldEvent = new RaumFeldEvent() { MediaDevice = payload.MediaDevice, EventSID = args.EventSID, }; raumFeldEvent.ChangedValues.Add("SystemUpdateID", property.SystemUpdateID); eventAggregator.GetEvent <SystemUpdateIDChangedEvent>().Publish(raumFeldEvent); } if (property.LastChange != null) { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(property.LastChange); XmlNodeList xmlNodes = xmlDocument.SelectNodes("//*"); foreach (var item in xmlNodes) { RaumFeldEvent raumFeldEvent = new RaumFeldEvent() { MediaDevice = payload.MediaDevice, EventSID = args.EventSID, }; switch ((string)item.NamespaceUri) { case "urn:schemas-upnp-org:metadata-1-0/RCS/": raumFeldEvent.SericeType = ServiceTypes.RENDERINGCONTROL; break; case "urn:schemas-upnp-org:metadata-1-0/AVT/": raumFeldEvent.SericeType = ServiceTypes.AVTRANSPORT; break; default: break; } var values = new Dictionary <string, string>(); foreach (var a in item.Attributes) { raumFeldEvent.ChangedValues.Add(a.NodeName, (string)a.NodeValue); } switch (item.NodeName) { // RenderingControlEvents case "Mute": eventAggregator.GetEvent <MuteChangedEvent>().Publish(raumFeldEvent); break; case "Volume": eventAggregator.GetEvent <VolumeChangedEvent>().Publish(raumFeldEvent); break; case "RoomMutes": eventAggregator.GetEvent <RoomMutesChangedEvent>().Publish(raumFeldEvent); break; case "RoomVolumes": eventAggregator.GetEvent <RoomVolumesChangedEvent>().Publish(raumFeldEvent); break; // AVTransportEvents case "AVTransportURI": eventAggregator.GetEvent <AVTransportURIChangedEvent>().Publish(raumFeldEvent); break; case "AVTransportURIMetaData": eventAggregator.GetEvent <AVTransportURIMetaDataChangedEvent>().Publish(raumFeldEvent); break; case "CurrentTrack": eventAggregator.GetEvent <CurrentTrackChangedEvent>().Publish(raumFeldEvent); break; case "CurrentTrackURI": eventAggregator.GetEvent <CurrentTrackURIChangedEvent>().Publish(raumFeldEvent); break; case "CurrentPlayMode": eventAggregator.GetEvent <CurrentPlayModeChangedEvent>().Publish(raumFeldEvent); break; case "CurrentTrackMetaData": eventAggregator.GetEvent <CurrentTrackMetaDataChangedEvent>().Publish(raumFeldEvent); break; case "CurrentTransportActions": eventAggregator.GetEvent <CurrentTransportActionsChangedEvent>().Publish(raumFeldEvent); break; case "NumberOfTracks": eventAggregator.GetEvent <NumberOfTracksChangedEvent>().Publish(raumFeldEvent); break; case "PowerState": eventAggregator.GetEvent <PowerStateChangedEvent>().Publish(raumFeldEvent); break; case "RoomStates": eventAggregator.GetEvent <RoomStatesChangedEvent>().Publish(raumFeldEvent); break; default: break; } } } } }