Bugfixes in SSDP Device and Discovery

This commit is contained in:
Chris 2017-02-16 22:57:13 +01:00
parent e44becfa23
commit ccc70650f2
2 changed files with 10 additions and 2 deletions

View File

@ -47,7 +47,11 @@ class Device
public static function createFromSchema($url, $ip) public static function createFromSchema($url, $ip)
{ {
$xml = simplexml_load_file($url); $xml = @simplexml_load_file($url);
if (empty($xml)) {
error_log("Unable to retrieve UPnP schema from {$url}");
return null;
}
$spec = $xml->children('urn:schemas-upnp-org:device-1-0'); $spec = $xml->children('urn:schemas-upnp-org:device-1-0');
if (count($spec)>0) { if (count($spec)>0) {

View File

@ -47,8 +47,12 @@ class Discovery implements IteratorAggregate
foreach ($responses as $response) { foreach ($responses as $response) {
// Add the relevant responses to the list // Add the relevant responses to the list
if ($response instanceof MSearchResponse) { if ($response instanceof MSearchResponse) {
$loc = $response->getLocation();
if (array_key_exists($loc, $this->devices)) {
continue;
}
$device = Device::createFromSchema($response->getLocation(), $response->getIp()); $device = Device::createFromSchema($response->getLocation(), $response->getIp());
$this->devices[] = $device; $this->devices[$loc] = $device;
} }
} }