/**
  * @param ServerClient $client
  * @param string $buffer
  * @return void
  */
 public function onIncoming(ServerClient $client, string $buffer)
 {
     if (preg_match('/^NOTIFY/', $buffer)) {
         $response = new SsdpResponse();
         $response->setFromString($buffer);
         if ($response->getHttpCode() !== 200) {
             return;
         }
         self::$eventHandler->fireEvent(EventDiscover::EVENT_NAME, new EventDiscover($response));
         return;
     }
     if (preg_match('/^(OPTIONS|M-SEARCH) /', $buffer)) {
         foreach ($this->services as $service) {
             $buffer = sprintf("HTTP/1.1 200 OK\n" . "LOCATION: %s\n" . "SERVER: %s\n" . "CACHE-CONTROL: max-age=%d\n" . "EXT:\n" . "ST: %s\n" . "USN: %s\n", $service['location'], $service['server'], $service['ttl'], $service['usn'], $service['usn']);
             $this->send($client, $buffer);
         }
     }
 }
Ejemplo n.º 2
0
 public function testStringServer()
 {
     $this->assertEquals('test upnp server', $this->ssdpResponseString->getServer());
 }