You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
45 lines
1.1 KiB
<?php |
|
|
|
namespace App\Component\Nginx; |
|
use App\Entity\Streams; |
|
|
|
/** |
|
* Class Stats |
|
* @author Soner Sayakci <shyim@posteo.de> |
|
*/ |
|
class Stats |
|
{ |
|
/** |
|
* @var array |
|
*/ |
|
private $data; |
|
|
|
/** |
|
* Stats constructor. |
|
* @author Soner Sayakci <shyim@posteo.de> |
|
*/ |
|
public function __construct() |
|
{ |
|
$stats = file_get_contents('http://127.0.0.1:26765/stat'); |
|
$xml = simplexml_load_string($stats, 'SimpleXMLElement', LIBXML_NOCDATA); |
|
$this->data = json_decode(json_encode($xml), true); |
|
} |
|
|
|
/** |
|
* @param Streams $stream |
|
* @author Soner Sayakci <shyim@posteo.de> |
|
* @return array |
|
*/ |
|
public function getStatsForStream(Streams $stream): array |
|
{ |
|
$appKey = $stream->getUser()->getUsername() . '/' . $stream->getName(); |
|
|
|
foreach ($this->data['server']['application'] as $application) { |
|
if ($application['name'] === $appKey && isset($application['live']['stream'])) { |
|
return $application['live']['stream']; |
|
} |
|
} |
|
|
|
return []; |
|
} |
|
}
|
|
|