// Call this method from somewhere to actually do the publish. private static void PublishDevice() { var ip4 = GetLocalIp4Address(); var version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); var deviceDefinition4 = new SsdpRootDevice() { Location = new Uri($"http://{ip4}/home/service"), PresentationUrl = new Uri($"http://{ip4}/"), FriendlyName = "Milwaukee Makerspace Api", Manufacturer = "Milwaukee Makerspace", ModelName = "Milwaukee Makerspace Api", Uuid = "6111f321-2cee-455e-b203-4abfaf14b516", ManufacturerUrl = new Uri("https://milwaukeemakerspace.org/"), ModelUrl = new Uri("https://github.com/DanDude0/MilwaukeeMakerspaceApi/"), ModelNumber = version, }; // Have to bind to all addresses on Linux, or broadcasts don't work! if (!System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows)) { ip4 = IPAddress.Any.ToString(); } Console.WriteLine($"Publishing SSDP on {ip4}"); SsdpPublisher4 = new SsdpDevicePublisher(new SsdpCommunicationsServer(new SocketFactory(ip4))); SsdpPublisher4.StandardsMode = SsdpStandardsMode.Relaxed; SsdpPublisher4.AddDevice(deviceDefinition4); SsdpDescription = deviceDefinition4.ToDescriptionDocument(); }
public Task StartAsync(CancellationToken cancellationToken) { _publishers = NetworkInterface .GetAllNetworkInterfaces() .Select(x => x.GetIPProperties()) .Select(@interface => @interface.UnicastAddresses .Where(address => (address.Address.AddressFamily == AddressFamily.InterNetwork || address.Address.AddressFamily == AddressFamily.InterNetworkV6) && !IPAddress.IsLoopback(address.Address) ) .Select(address => address.Address)) .Where(x => x.Any()) .Aggregate(new List <IPAddress>(), (x, y) => x.Concat(y).ToList()) .Select(address => { try { var locator = new SsdpDevicePublisher( new SsdpCommunicationsServer(new SocketFactory(address.ToString()))); return(locator); } catch (Exception) { return(null); } }) .Where(x => x != null) .ToArray(); _startCallback = _lifetime.ApplicationStarted.Register(AddDevices); return(Task.CompletedTask); }
private static void PublishDevices() { if (_DevicePublisher != null) { Console.WriteLine("Stopping previous publisher."); _DevicePublisher.Dispose(); } // Create a device publisher _DevicePublisher = new SsdpDevicePublisher(); // Create the device(s) we want to publish. var rootDevice = new SsdpRootDevice() { CacheLifetime = TimeSpan.FromMinutes(30), FriendlyName = "Sample RSSDP Device", Manufacturer = "RSSDP", ModelNumber = "123", ModelName = "RSSDP Sample Device", SerialNumber = "123", Uuid = System.Guid.NewGuid().ToString() }; rootDevice.CustomResponseHeaders.Add(new CustomHttpHeader("X-MachineName", Environment.MachineName)); // Now publish by adding them to the publisher. _DevicePublisher.AddDevice(rootDevice); Console.WriteLine("Publishing devices: "); WriteOutDevices(rootDevice); Console.WriteLine(); }
public void StartDevicePublisher(Configuration.DlnaOptions options) { if (!options.BlastAliveMessages) { return; } if (_publisher != null) { return; } try { _publisher = new SsdpDevicePublisher( _communicationsServer, MediaBrowser.Common.System.OperatingSystem.Name, Environment.OSVersion.VersionString, _config.GetDlnaConfiguration().SendOnlyMatchedHost) { LogFunction = (msg) => _logger.LogDebug("{Msg}", msg), SupportPnpRootDevice = false }; RegisterServerEndpoints(); _publisher.StartBroadcastingAliveMessages(TimeSpan.FromSeconds(options.BlastAliveMessageIntervalSeconds)); } catch (Exception ex) { _logger.LogError(ex, "Error registering endpoint"); } }
public async Task StartDevicePublisher() { if (!_config.GetDlnaConfiguration().BlastAliveMessages) { return; } if (_Publisher != null) { return; } try { _Publisher = new SsdpDevicePublisher(_communicationsServer, _timerFactory, _environmentInfo.OperatingSystemName, _environmentInfo.OperatingSystemVersion); _Publisher.LogFunction = LogMessage; _Publisher.SupportPnpRootDevice = false; await RegisterServerEndpoints().ConfigureAwait(false); } catch (Exception ex) { _logger.ErrorException("Error registering endpoint", ex); } }
public void Start() { _publisher = new SsdpDevicePublisher(); //var rootDevice = new SsdpRootDevice //{ // Uuid = "c6faa85a-d7e9-48b7-8c54-7459c4d9c329", // CacheLifetime = TimeSpan.Zero, // //UrlBase = new Uri("http://localhost"), // //PresentationUrl = new Uri("configurator", UriKind.Relative), // FriendlyName = "Wirehome.Core", // Manufacturer = "Wirehome", // //ManufacturerUrl = new Uri("https://github.com/chkr1011/Wirehome.Core/"), // ModelNumber = WirehomeCoreVersion.Version, // //ModelUrl = new Uri("app", UriKind.Relative), // ModelName = "Wirehome.Core", // ModelDescription = "Wirehome.Core", //}; //_publisher.AddDevice(rootDevice); ParallelTask.Start(SearchAsync, CancellationToken.None, _logger); }
public async Task StartDevicePublisher(Configuration.DlnaOptions options) { if (!options.BlastAliveMessages) { return; } if (_Publisher != null) { return; } try { Func <int> deviceCacheSecondsFn = () => _config.GetDlnaConfiguration().AliveMessageIntervalSeconds; _Publisher = new SsdpDevicePublisher(_communicationsServer, _timerFactory, _environmentInfo.OperatingSystemName, _environmentInfo.OperatingSystemVersion, deviceCacheSecondsFn); _Publisher.LogFunction = LogMessage; await RegisterServerEndpoints().ConfigureAwait(false); _Publisher.StartBroadcastingAliveMessages(TimeSpan.FromSeconds(deviceCacheSecondsFn())); } catch (Exception ex) { _logger.ErrorException("Error registering endpoint", ex); } }
public async Task StartDevicePublisher(Configuration.DlnaOptions options) { if (!options.BlastAliveMessages) { return; } if (_Publisher != null) { return; } try { _Publisher = new SsdpDevicePublisher(_communicationsServer, _networkManager, OperatingSystem.Name, Environment.OSVersion.VersionString, _config.GetDlnaConfiguration().SendOnlyMatchedHost); _Publisher.LogFunction = LogMessage; _Publisher.SupportPnpRootDevice = false; await RegisterServerEndpoints().ConfigureAwait(false); _Publisher.StartBroadcastingAliveMessages(TimeSpan.FromSeconds(options.BlastAliveMessageIntervalSeconds)); } catch (Exception ex) { _logger.LogError(ex, "Error registering endpoint"); } }
public static void PublishThisDevice(string ip) { if (string.IsNullOrEmpty(ip)) { ConsoleLogger.Log("[rssdp] cannot publish device: ip address not valid"); return; } var appPort = Application.CurrentConfiguration.WebService.GuiWebServicePort; var deviceDefinition = new SsdpRootDevice() { CacheLifetime = TimeSpan.FromMinutes(30), Uuid = Application.CurrentConfiguration.Host.MachineUid.ToString(), Location = new Uri($"http://{ip}:{appPort}/device/description"), DeviceTypeNamespace = "antd", ModelUrl = new Uri($"http://{ip}:{appPort}/"), DeviceType = Application.CurrentConfiguration.Host.PartNumber.ToString(), FriendlyName = $"{ip} as {Application.CurrentConfiguration.Host.HostName}", Manufacturer = "Anthilla SRL", ModelName = Application.CurrentConfiguration.Host.SerialNumber.ToString().Replace("-", ""), SerialNumber = Application.CurrentConfiguration.Host.SerialNumber.ToString() }; _Publisher = new SsdpDevicePublisher(); _Publisher.AddDevice(deviceDefinition); ConsoleLogger.Log($"[rssdp] publishing this device on '{ip}'"); }
public async Task StartDevicePublisher(Configuration.DlnaOptions options) { if (!options.BlastAliveMessages) { return; } if (_Publisher != null) { return; } try { _Publisher = new SsdpDevicePublisher(_communicationsServer, _timerFactory, _environmentInfo.OperatingSystemName, _environmentInfo.OperatingSystemVersion); _Publisher.LogFunction = LogMessage; _Publisher.SupportPnpRootDevice = false; await RegisterServerEndpoints().ConfigureAwait(false); _Publisher.StartBroadcastingAliveMessages(TimeSpan.FromSeconds(options.BlastAliveMessageIntervalSeconds)); } catch (Exception ex) { _logger.LogError(ex, "Error registering endpoint"); } }
public void DisposeDevicePublisher() { if (_Publisher != null) { _logger.LogInformation("Disposing SsdpDevicePublisher"); _Publisher.Dispose(); _Publisher = null; } }
private async void Page_Loaded(object sender, RoutedEventArgs e) { //Note, you can use deviceDefinition.ToDescriptionDocumentText() to retrieve the data to //return from the Location end point, you just need to get that data to your service //implementation somehow. Depends on how you've implemented your service. _Publisher = new SsdpDevicePublisher(); _device = PublishDevice(); _Publisher.AddDevice(_device); await StartWebserverAsync(); }
public void ApplyTo(SsdpDevicePublisher publisher) { var type = typeof(SsdpDevicePublisherBase); var field = type.GetField("_Log", BindingFlags.NonPublic | BindingFlags.Instance); if (field == null) { throw new NullReferenceException("Cannot find _Log private field in SsdpDevicePublisher class."); } field.SetValue(publisher, this); }
public Controller() { _Publisher = new SsdpDevicePublisher(); var deviceDefinition = new SsdpRootDevice() { CacheLifetime = TimeSpan.FromMinutes(30), //How long SSDP clients can cache this info. Location = new Uri("http://mydevice/descriptiondocument.xml"), // Must point to the URL that serves your devices UPnP description document. DeviceTypeNamespace = "my-namespace", DeviceType = "MyCustomDevice", FriendlyName = "Custom Device 1", Manufacturer = "Me", ModelName = "MyCustomDevice", Uuid = "Andrew-PC" // This must be a globally unique value that survives reboots etc. Get from storage or embedded hardware etc. }; _Publisher.AddDevice(deviceDefinition); }
private static void PublishDevices() { if (_DevicePublisher != null) { Console.WriteLine("Stopping previous publisher."); _DevicePublisher.Dispose(); } // Create a device publisher _DevicePublisher = new SsdpDevicePublisher(); // Create the device(s) we want to publish. var rootDevice = new SsdpRootDevice() { CacheLifetime = TimeSpan.FromMinutes(30), FriendlyName = "Sample RSSDP Device", Manufacturer = "RSSDP", ModelNumber = "123", ModelName = "RSSDP Sample Device", SerialNumber = "123", Uuid = System.Guid.NewGuid().ToString() }; rootDevice.CustomResponseHeaders.Add(new CustomHttpHeader("X-MachineName", Environment.MachineName)); var service = new SsdpService() { Uuid = System.Guid.NewGuid().ToString(), ServiceType = "test-service-type", ServiceTypeNamespace = "rssdp-test-namespace", ControlUrl = new Uri("/test/control", UriKind.Relative), EventSubUrl = new Uri("/test/event", UriKind.Relative), ScpdUrl = new Uri("/test", UriKind.Relative) }; rootDevice.AddService(service); // Now publish by adding them to the publisher. _DevicePublisher.AddDevice(rootDevice); Console.WriteLine("Publishing devices: "); WriteOutDevices(rootDevice); Console.WriteLine(); }
public DiscoveryService() { try { _publisher = new SsdpDevicePublisher(); _deviceLocator = new SsdpDeviceLocator { NotificationFilter = UrnSearch }; _deviceLocator.StartListeningForNotifications(); _port = Convert.ToInt32(ServerInfo.WebPort); AutomaticaUuid = ServerInfo.ServerUid.ToString(); Location = new Uri($"http://{NetworkHelper.GetActiveIp()}:{_port}/webapi/discovery"); } catch (Exception e) { SystemLogger.Instance.LogError($"Could not init SSDP Publisher {e}"); } }
public static void PublishThisDevice() { var appPort = new AppConfiguration().Get().AntdUiPort; var localIps = IPv4.GetAllLocalAddress().Where(_ => _ != "127.0.0.1").OrderBy(_ => _).ToList(); foreach (var ip in localIps) { var deviceDefinition = new SsdpRootDevice() { CacheLifetime = TimeSpan.FromMinutes(60), Uuid = MachineUid, Location = new Uri($"http://{ip}:{appPort}/device/description"), DeviceTypeNamespace = "antd", ModelUrl = new Uri($"http://{ip}:{appPort}/"), DeviceType = PartNumber, FriendlyName = $"{ip} as {Hostname}", Manufacturer = "Anthilla SRL", ModelName = SerialNumber }; _Publisher = new SsdpDevicePublisher(); _Publisher.AddDevice(deviceDefinition); } }
public void Publish() { // As this is a sample, we are only setting the minimum required properties. SsdpRootDevice deviceDefinition = new SsdpRootDevice() { CacheLifetime = TimeSpan.FromMinutes(30), //How long SSDP clients can cache this info. //Location = new Uri("http://mydevice/descriptiondocument.xml"), // Must point to the URL that serves your devices UPnP description document. DeviceTypeNamespace = "my-namespace", DeviceType = "BattleShip.Server", FriendlyName = "Battleship Server", Manufacturer = "Me", ModelName = "MyCustomDevice", Uuid = m_StorageManager.InstanceID.ToString() // This must be a globally unique value that survives reboots etc. Get from storage or embedded hardware etc. }; m_HTTPServer.Start(deviceDefinition); if (m_Publisher == null) { m_Publisher = new SsdpDevicePublisher(); } m_Publisher.AddDevice(deviceDefinition); }
private static void PublishDevices() { if (_DevicePublisher != null) { Console.WriteLine("Stopping previous publisher."); _DevicePublisher.Dispose(); } if (_HttpServer != null) { _HttpServer.Close(); } // Create a device publisher _DevicePublisher = new SsdpDevicePublisher(); //These settings make RSSDP play nicely with Windows Explorer //and some badly behaved clients. _DevicePublisher.StandardsMode = SsdpStandardsMode.Relaxed; // Create the device(s) we want to publish. var url = new Uri("http://" + Environment.MachineName + ":8181/"); var rootDevice = new SsdpRootDevice() { CacheLifetime = TimeSpan.FromMinutes(30), FriendlyName = "Sample RSSDP Device", Manufacturer = "RSSDP", ModelNumber = "123", ModelName = "RSSDP Sample Device", ModelDescription = "Test Device from RSSDP Console App", ManufacturerUrl = new Uri("https://github.com/Yortw/RSSDP"), SerialNumber = "123", Uuid = System.Guid.NewGuid().ToString(), UrlBase = url }; rootDevice.CustomResponseHeaders.Add(new CustomHttpHeader("X-MachineName", Environment.MachineName)); var service = new SsdpService() { Uuid = System.Guid.NewGuid().ToString(), ServiceType = "test-service-type", ServiceTypeNamespace = "rssdp-test-namespace", ControlUrl = new Uri("/test/control", UriKind.Relative), EventSubUrl = new Uri("/test/event", UriKind.Relative), ScpdUrl = new Uri("/test", UriKind.Relative) }; rootDevice.AddService(service); rootDevice.Location = new Uri(url, "ddd"); //Some 3rd party tools won't show the device unless they can get //the device description document, so this sample uses a really simple HTTP //server just to serve that. StartHttpServerForDdd(rootDevice, url); // Now publish by adding them to the publisher. _DevicePublisher.AddDevice(rootDevice); Console.WriteLine("Publishing devices: "); WriteOutDevices(rootDevice); Console.WriteLine(); }
private static void PublishDevices() { if (_DevicePublisher != null) { Console.WriteLine("Stopping previous publisher."); _DevicePublisher.Dispose(); } // Create a device publisher _DevicePublisher = new SsdpDevicePublisher(); // Create the device(s) we want to publish. var rootDevice = new SsdpRootDevice() { CacheLifetime = TimeSpan.FromMinutes(30), FriendlyName = "Sample RSSDP Device", Manufacturer = "RSSDP", ModelNumber = "123", ModelName = "RSSDP Sample Device", SerialNumber = "123", Uuid = System.Guid.NewGuid().ToString() }; // Now publish by adding them to the publisher. _DevicePublisher.AddDevice(rootDevice); Console.WriteLine("Publishing devices: "); WriteOutDevices(rootDevice); Console.WriteLine(); }
private void StartPublishing(ISsdpCommunicationsServer communicationsServer) { SsdpDevicePublisherBase.LogFunction = LogMessage; _Publisher = new SsdpDevicePublisher(communicationsServer, _timerFactory, _environmentInfo.OperatingSystemName, _environmentInfo.OperatingSystemVersion); }
private void ConfigureSsdp( IOptions <LocalServerOptions> localServerOptions, SsdpLogger logger) { var device = new SsdpRootDevice() { CacheLifetime = TimeSpan.FromHours(1), Location = new Uri($"{localServerOptions.Value.RootUrl}/"), UrlBase = new Uri($"{localServerOptions.Value.RootUrl}/"), DeviceType = "urn:roku-com:device:player:1-0:1", DeviceTypeNamespace = "schemas-upnp-org", DeviceVersion = 1, Uuid = "29600009-5406-1005-8080-1234567890ab", Udn = "uuid:29600009-5406-1005-8080-1234567890ab", FriendlyName = "Ukor Server", Manufacturer = "Roku", ManufacturerUrl = new Uri("http://www.roku.com/"), ModelDescription = "Roku Streaming Player Network Media", ModelName = "Ukor Server", ModelNumber = "3810EU", ModelUrl = new Uri("http://www.roku.com/"), SerialNumber = "YH009E000001", Usn = "uuid:roku:ecp:YH009E000001", NotificationType = "roku:ecp" }; device.CustomResponseHeaders.Add(new CustomHttpHeader("Server", "Roku/9.2.0, UPnP/1.0")); device.CustomResponseHeaders.Add(new CustomHttpHeader("device-group.roku.com", "1E3DE502613555ACA315")); device.CustomResponseHeaders.Add(new CustomHttpHeader("WAKEUP", "MAC=ac:ae:01:02:03:04, Timeout=10")); var ecpService = new SsdpService { ServiceType = "ecp", ServiceTypeNamespace = "roku-com", ServiceVersion = 1, Uuid = "ecp1-0", ScpdUrl = new Uri("ecp_SCPD.xml", UriKind.Relative), ControlUrl = new Uri("roku:0") }; device.AddService(ecpService); var dialService = new SsdpService { ServiceType = "dial", ServiceTypeNamespace = "dial-multiscreen-org", ServiceVersion = 1, Uuid = "dial1-0", ScpdUrl = new Uri("dial_SCPD.xml", UriKind.Relative), ControlUrl = new Uri("roku:1") }; device.AddService(dialService); _publisher = new SsdpDevicePublisher { StandardsMode = SsdpStandardsMode.Relaxed, Log = logger }; _publisher.AddDevice(device); _publisher.NotificationBroadcastInterval = TimeSpan.FromMinutes(10); }
private void StartPublishing() { SsdpDevicePublisherBase.LogFunction = LogMessage; _Publisher = new SsdpDevicePublisher(); }
private void StartPublishing() { _Publisher = new SsdpDevicePublisher(); }