1 | <?php |
||
11 | class Scanner implements \JsonSerializable |
||
12 | { |
||
13 | /** @var string */ |
||
14 | static protected $host = '239.255.255.250'; |
||
15 | |||
16 | /** @var int */ |
||
17 | static protected $port = 1900; |
||
18 | |||
19 | /** |
||
20 | * Maximum wait time in seconds. Should be between 1 and 120 inclusive. |
||
21 | * |
||
22 | * @var int |
||
23 | */ |
||
24 | protected $delayResponse = 1; |
||
25 | |||
26 | /** @var int */ |
||
27 | protected $timeout = 5; |
||
28 | |||
29 | /** @var string */ |
||
30 | protected $userAgent = 'iOS/5.0 UDAP/2.0 iPhone/4'; |
||
31 | |||
32 | /** @var array */ |
||
33 | protected $searchTypes = [ |
||
34 | 'ssdp:all', |
||
35 | 'upnp:rootdevice', |
||
36 | ]; |
||
37 | |||
38 | /** @var string */ |
||
39 | protected $searchType = 'ssdp:all'; |
||
40 | |||
41 | /** @var array */ |
||
42 | private $devices = []; |
||
43 | |||
44 | /** |
||
45 | * @param integer $delayResponse |
||
46 | * @return $this |
||
47 | */ |
||
48 | public function setDelayResponse($delayResponse) |
||
63 | |||
64 | /** |
||
65 | * @param int $timeout |
||
66 | * @return Scanner |
||
67 | */ |
||
68 | public function setTimeout($timeout) |
||
84 | |||
85 | /** |
||
86 | * @param string $userAgent |
||
87 | * @return Scanner |
||
88 | */ |
||
89 | public function setUserAgent($userAgent) |
||
95 | |||
96 | /** |
||
97 | * @param string $searchType |
||
98 | * @return $this |
||
99 | */ |
||
100 | public function setSearchType($searchType) |
||
116 | |||
117 | /** |
||
118 | * Main scan function |
||
119 | * |
||
120 | * @return array |
||
121 | */ |
||
122 | public function discover() |
||
144 | |||
145 | /** |
||
146 | * Fetch all available UPnP devices via unicast |
||
147 | * |
||
148 | * @return array |
||
149 | */ |
||
150 | protected function doMSearchRequest() |
||
177 | |||
178 | /** |
||
179 | * Prepare Msearch request string |
||
180 | * |
||
181 | * @return string |
||
182 | */ |
||
183 | protected function getMSearchRequest() |
||
196 | |||
197 | /** |
||
198 | * Parse response from device to a more readable format |
||
199 | * |
||
200 | * @param $response |
||
201 | * @return array |
||
202 | */ |
||
203 | protected function parseMSearchResponse($response) |
||
228 | |||
229 | /** |
||
230 | * @param $location |
||
231 | * @param $xml |
||
232 | */ |
||
233 | protected function parseXmlDeviceResponse($location, $xml) |
||
244 | |||
245 | /** |
||
246 | * Fetch XML's from all devices async |
||
247 | * |
||
248 | * @param array $targets |
||
249 | * @return array |
||
250 | */ |
||
251 | protected function fetchUpnpXmlDeviceInfo(array $targets) |
||
287 | |||
288 | /** |
||
289 | * @return array |
||
290 | */ |
||
291 | public function jsonSerialize() |
||
302 | } |
||
303 |
If you suppress an error, we recommend checking for the error condition explicitly: