php-upnp/README.md

99 lines
2.9 KiB
Markdown

UPnP Library for PHP
====================
This is a UPnP client implementation in native PHP. It currently supports
basic discovery and device enumeration.
## Implemented Features
### HTTPU
The HTTPU implementation is used by UPnP to send HTTP-like messages over
UDP. It consist of an `Endpoint` class that creates a listening socket and
classes and subclasses for `Request` and `Response`.
Currently only `MSearchRequest` and `MSearchResponse` is implemented. These
classes are used to send `M-SEARCH` messages for discovery, and to parse the
response.
### SSDP
The SSDP (Simple Service Discovery Protocol) implementation is used to find
devices on the local network, and to enumerate child devices and defined
services.
To discover devices, use the `Discovery` class, and call `discover()` with
the search target as the first parameter. The `SearchTarget` class contains
constants and methods to help with resolving and constructing search types.
Once the discovery has completed, you can iterate over the `Discovery`
object to get the devices.
use NoccyLabs\UPnP\SSDP\Discovery;
use NoccyLabs\UPnP\SSDP\SearchTarget;
$discovery = new Discovery();
$discovery->discover(SearchTarget::URN_SCHEMA_DEVICE_IGD_2);
foreach ($discovery as $device) {
print_r($device);
}
## Experimental Features
### DCP
The DCPs (Device Control Protocol) are used to interact with services. This
can be f.ex. managing UPnP portmapping in your router or controlling a media
player.
## Search targets
To find everything, use `ALL`:
SearchTarget::ALL
Find all root devices:
SearchTarget::ROOT_DEVICE
Find *Internet Gateway Devices* (routers). This equates to the type string
`urn:schemas-upnp-org:device:InternetGatewayDevice:<version>`. Version 1 of
the IGD specification has been deprecated, so you probably want to use version
2 when discovering devices:
SearchTarget::URN_SCHEMA_DEVICE_IGD_1
SearchTarget::URN_SCHEMA_DEVICE_IGD_2
You can also find devices based on UUIDs:
SearchTarget::UUID(<uuid>)
-> "uuid:<uuid>"
Or devices based on the core UPnP schemas or device classes:
SearchTarget::URN_SCHEMA_DEVICE(<type>, <version>)
-> "urn:schemas-upnp-org:device:<type>:<version>"
SearchTarget::URN_SCHEMA_SERVICE(<type>, <version>)
-> "urn:schemas-upnp-org:service:<type>:<version>"
For example, to find the devices returned by `URN_SCHEMA_DEVICE_IGD_2` you could
use:
SearchTarget::URN_SCHEMA_DEVICE('InternetGatewayDevice',2);
Additionally, you can search for vendor specific services or device classes:
SearchTarget::URN_DEVICE(<domain>, <type>, <version>)
-> "urn:<domain>:device:<type>:<version>"
SearchTarget::URN_SERVICE(<domain>, <type>, <version>)
-> "urn:<domain>:service:<type>:<version>"
For example, to find *DIAL* devices (for "casting" Netflix, YouTube etc. on TV)
you could use:
SearchTarget::URN_DEVICE('dial-multiscreen-org', 'dialreceiver', 1)