コード例 #1
0
        private async Task RegisterServerEndpoints()
        {
            var cacheLength = _config.GetDlnaConfiguration().BlastAliveMessageIntervalSeconds;

            var addresses = (await _appHost.GetLocalIpAddresses(CancellationToken.None).ConfigureAwait(false)).ToList();

            var udn = CreateUuid(_appHost.SystemId);

            foreach (var address in addresses)
            {
                // TODO: Remove this condition on platforms that support it
                //if (address.AddressFamily == IpAddressFamily.InterNetworkV6)
                //{
                //    continue;
                //}

                var fullService = "urn:schemas-upnp-org:device:MediaServer:1";

                _logger.Info("Registering publisher for {0} on {1}", fullService, address.ToString());

                var descriptorUri = "/dlna/" + udn + "/description.xml";
                var uri           = new Uri(_appHost.GetLocalApiUrl(address) + descriptorUri);

                var device = new SsdpRootDevice
                {
                    CacheLifetime = TimeSpan.FromSeconds(cacheLength), //How long SSDP clients can cache this info.
                    Location      = uri,                               // Must point to the URL that serves your devices UPnP description document.
                    FriendlyName  = "Emby Server",
                    Manufacturer  = "Emby",
                    ModelName     = "Emby Server",
                    Uuid          = udn
                                    // This must be a globally unique value that survives reboots etc. Get from storage or embedded hardware etc.
                };

                SetProperies(device, fullService);
                _Publisher.AddDevice(device);

                var embeddedDevices = new []
                {
                    "urn:schemas-upnp-org:service:ContentDirectory:1",
                    "urn:schemas-upnp-org:service:ConnectionManager:1",
                    //"urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:1"
                };

                foreach (var subDevice in embeddedDevices)
                {
                    var embeddedDevice = new SsdpEmbeddedDevice
                    {
                        FriendlyName = device.FriendlyName,
                        Manufacturer = device.Manufacturer,
                        ModelName    = device.ModelName,
                        Uuid         = udn
                                       // This must be a globally unique value that survives reboots etc. Get from storage or embedded hardware etc.
                    };

                    SetProperies(embeddedDevice, subDevice);
                    device.AddDevice(embeddedDevice);
                }
            }
        }
コード例 #2
0
        private async Task RegisterServerEndpoints()
        {
            var addresses = await _appHost.GetLocalIpAddresses(CancellationToken.None).ConfigureAwait(false);

            var udn = CreateUuid(_appHost.SystemId);

            foreach (var address in addresses)
            {
                if (address.AddressFamily == AddressFamily.InterNetworkV6)
                {
                    // Not support IPv6 right now
                    continue;
                }

                var fullService = "urn:schemas-upnp-org:device:MediaServer:1";

                _logger.LogInformation("Registering publisher for {0} on {1}", fullService, address);

                var descriptorUri = "/dlna/" + udn + "/description.xml";
                var uri           = new Uri(_appHost.GetLocalApiUrl(address) + descriptorUri);

                var device = new SsdpRootDevice
                {
                    CacheLifetime = TimeSpan.FromSeconds(1800), //How long SSDP clients can cache this info.
                    Location      = uri,                        // Must point to the URL that serves your devices UPnP description document.
                    Address       = address,
                    SubnetMask    = _networkManager.GetLocalIpSubnetMask(address),
                    FriendlyName  = "Veso",
                    Manufacturer  = "Veso",
                    ModelName     = "Veso Server",
                    Uuid          = udn
                                    // This must be a globally unique value that survives reboots etc. Get from storage or embedded hardware etc.
                };

                SetProperies(device, fullService);
                _Publisher.AddDevice(device);

                var embeddedDevices = new[]
                {
                    "urn:schemas-upnp-org:service:ContentDirectory:1",
                    "urn:schemas-upnp-org:service:ConnectionManager:1",
                    //"urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:1"
                };

                foreach (var subDevice in embeddedDevices)
                {
                    var embeddedDevice = new SsdpEmbeddedDevice
                    {
                        FriendlyName = device.FriendlyName,
                        Manufacturer = device.Manufacturer,
                        ModelName    = device.ModelName,
                        Uuid         = udn
                                       // This must be a globally unique value that survives reboots etc. Get from storage or embedded hardware etc.
                    };

                    SetProperies(embeddedDevice, subDevice);
                    device.AddDevice(embeddedDevice);
                }
            }
        }
コード例 #3
0
        public void SsdpDevice_DeviceToRootDeviceReturnsAssignedRootDevice()
        {
            var rootDevice = new SsdpRootDevice();
            var device     = new SsdpEmbeddedDevice();

            rootDevice.AddDevice(device);

            Assert.AreEqual(rootDevice, device.RootDevice);
        }
コード例 #4
0
        public void SsdpDevice_AddDevice_DuplicateAddDoesNothing()
        {
            var rootDevice = new SsdpRootDevice();

            var embeddedDevice = new SsdpEmbeddedDevice();

            rootDevice.AddDevice(embeddedDevice);
            rootDevice.AddDevice(embeddedDevice);
            Assert.AreEqual(1, rootDevice.Devices.Count());
        }
コード例 #5
0
        public void SsdpDevice_AddDevice_ThrowsAddingDeviceToMultipleParents()
        {
            var rootDevice1 = new SsdpRootDevice();
            var rootDevice2 = new SsdpRootDevice();

            var embeddedDevice = new SsdpEmbeddedDevice();


            rootDevice1.AddDevice(embeddedDevice);
            rootDevice2.AddDevice(embeddedDevice);
        }
コード例 #6
0
        public void SsdpDevice_RemoveDevice_DuplicateRemoveDoesNothing()
        {
            var rootDevice = new SsdpRootDevice();

            var embeddedDevice = new SsdpEmbeddedDevice()
            {
                Uuid = System.Guid.NewGuid().ToString()
            };

            rootDevice.AddDevice(embeddedDevice);
            Assert.AreEqual(1, rootDevice.Devices.Count());
            rootDevice.RemoveDevice(embeddedDevice);
            rootDevice.RemoveDevice(embeddedDevice);
            Assert.AreEqual(0, rootDevice.Devices.Count());
        }
コード例 #7
0
        public void SsdpDevice_AddDevice_SetsRootDeviceOnDescendants()
        {
            var rootDevice = new SsdpRootDevice();

            var embeddedDevice  = new SsdpEmbeddedDevice();
            var embeddedDevice2 = new SsdpEmbeddedDevice();

            embeddedDevice.AddDevice(embeddedDevice2);
            Assert.IsNull(embeddedDevice2.RootDevice);

            rootDevice.AddDevice(embeddedDevice);

            Assert.AreEqual(rootDevice, embeddedDevice.RootDevice);
            Assert.AreEqual(rootDevice, embeddedDevice2.RootDevice);
        }
コード例 #8
0
ファイル: DeviceLocatorTests.cs プロジェクト: noex/RSSDP
        private SsdpEmbeddedDevice CreateValidEmbeddedDevice(SsdpRootDevice rootDevice)
        {
            var uuid = Guid.NewGuid().ToString();

            var retVal = new SsdpEmbeddedDevice()
            {
                DeviceType   = "TestEmbeddedDevice",
                FriendlyName = "Test Embedded Device " + uuid,
                Manufacturer = "Test Manufacturer",
                ModelName    = "Test Model",
                Uuid         = uuid
            };

            rootDevice.AddDevice(retVal);

            return(retVal);
        }
コード例 #9
0
        public void SsdpDevice_AddDevice_RaisesDeviceAdded()
        {
            var rootDevice = new SsdpRootDevice();

            bool       eventRaised = false;
            SsdpDevice eventDevice = null;

            rootDevice.DeviceAdded += (sender, e) =>
            {
                eventRaised = true;
                eventDevice = e.Device;
            };

            var embeddedDevice = new SsdpEmbeddedDevice();

            rootDevice.AddDevice(embeddedDevice);
            Assert.IsTrue(eventRaised);
            Assert.AreEqual(embeddedDevice, eventDevice);
        }
コード例 #10
0
        private SsdpEmbeddedDevice CreateEmbeddedDevice(SsdpRootDevice rootDevice)
        {
            var retVal = new SsdpEmbeddedDevice()
            {
                DeviceType          = "TestEmbeddedDeviceType",
                DeviceTypeNamespace = "test-device-ns",
                FriendlyName        = "Test Embedded Device 1",
                Manufacturer        = "Test Manufacturer",
                ManufacturerUrl     = new Uri("http://testman.com"),
                ModelDescription    = "A test embeddeddevice",
                ModelName           = "Test Model",
                ModelNumber         = "1234",
                ModelUrl            = new Uri("http://testmodel.com"),
                PresentationUrl     = new Uri("http://testmodel.com/embedded/presentation"),
                SerialNumber        = "TM-12345",
                Upc  = "123456789012",
                Uuid = Guid.NewGuid().ToString()
            };

            rootDevice.AddDevice(retVal);

            return(retVal);
        }
コード例 #11
0
        public void SsdpDevice_RemoveDevice_RaisesDeviceRemoved()
        {
            var rootDevice = new SsdpRootDevice();

            bool       eventRaised = false;
            SsdpDevice eventDevice = null;

            rootDevice.DeviceRemoved += (sender, e) =>
            {
                eventRaised = true;
                eventDevice = e.Device;
            };

            var embeddedDevice = new SsdpEmbeddedDevice()
            {
                Uuid = System.Guid.NewGuid().ToString()
            };

            rootDevice.AddDevice(embeddedDevice);
            rootDevice.RemoveDevice(embeddedDevice);

            Assert.IsTrue(eventRaised);
            Assert.AreEqual(embeddedDevice, eventDevice);
        }
コード例 #12
0
        public void SsdpDevice_DeviceToRootDeviceReturnsNullWhenNoRootAssigned()
        {
            var device = new SsdpEmbeddedDevice();

            Assert.AreEqual(null, device.RootDevice);
        }
コード例 #13
0
ファイル: DlnaEntryPoint.cs プロジェクト: ximliu/jellyfin
        private void RegisterServerEndpoints()
        {
            var udn           = CreateUuid(_appHost.SystemId);
            var descriptorUri = "/dlna/" + udn + "/description.xml";

            var bindAddresses = NetworkManager.CreateCollection(
                _networkManager.GetInternalBindAddresses()
                .Where(i => i.AddressFamily == AddressFamily.InterNetwork || (i.AddressFamily == AddressFamily.InterNetworkV6 && i.Address.ScopeId != 0)));

            if (bindAddresses.Count == 0)
            {
                // No interfaces returned, so use loopback.
                bindAddresses = _networkManager.GetLoopbacks();
            }

            foreach (IPNetAddress address in bindAddresses)
            {
                if (address.AddressFamily == AddressFamily.InterNetworkV6)
                {
                    // Not supporting IPv6 right now
                    continue;
                }

                // Limit to LAN addresses only
                if (!_networkManager.IsInLocalNetwork(address))
                {
                    continue;
                }

                var fullService = "urn:schemas-upnp-org:device:MediaServer:1";

                _logger.LogInformation("Registering publisher for {ResourceName} on {DeviceAddress}", fullService, address);

                var uri = new UriBuilder(_appHost.GetApiUrlForLocalAccess(false) + descriptorUri);

                var device = new SsdpRootDevice
                {
                    CacheLifetime = TimeSpan.FromSeconds(1800), // How long SSDP clients can cache this info.
                    Location      = uri.Uri,                    // Must point to the URL that serves your devices UPnP description document.
                    Address       = address.Address,
                    PrefixLength  = address.PrefixLength,
                    FriendlyName  = "Jellyfin",
                    Manufacturer  = "Jellyfin",
                    ModelName     = "Jellyfin Server",
                    Uuid          = udn
                                    // This must be a globally unique value that survives reboots etc. Get from storage or embedded hardware etc.
                };

                SetProperies(device, fullService);
                _publisher.AddDevice(device);

                var embeddedDevices = new[]
                {
                    "urn:schemas-upnp-org:service:ContentDirectory:1",
                    "urn:schemas-upnp-org:service:ConnectionManager:1",
                    // "urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:1"
                };

                foreach (var subDevice in embeddedDevices)
                {
                    var embeddedDevice = new SsdpEmbeddedDevice
                    {
                        FriendlyName = device.FriendlyName,
                        Manufacturer = device.Manufacturer,
                        ModelName    = device.ModelName,
                        Uuid         = udn
                                       // This must be a globally unique value that survives reboots etc. Get from storage or embedded hardware etc.
                    };

                    SetProperies(embeddedDevice, subDevice);
                    device.AddDevice(embeddedDevice);
                }
            }
        }
コード例 #14
0
 public void DeserialisationConstructor_ThrowsOnEmptyDocument()
 {
     var rootDevice = new SsdpRootDevice();
     var device     = new SsdpEmbeddedDevice(String.Empty);
 }
コード例 #15
0
        public void SsdpDevice_AddDevice_ThrowsAddingDeviceToSelf()
        {
            var embeddedDevice = new SsdpEmbeddedDevice();

            embeddedDevice.AddDevice(embeddedDevice);
        }
コード例 #16
0
 public void SsdpDevice_ConstructorThrowsArgumentNullIfNotRootDevice()
 {
     var device = new SsdpEmbeddedDevice(null);
 }
コード例 #17
0
 public void DeserialisationConstructor_ThrowsOnNullDocument()
 {
     var rootDevice = new SsdpRootDevice();
     var device     = new SsdpEmbeddedDevice(null);
 }