2020-05-15 12:13:47 +02:00
|
|
|
<?php
|
2020-10-15 00:19:31 +02:00
|
|
|
|
2021-07-19 07:53:45 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-05-15 12:13:47 +02:00
|
|
|
namespace App\Controller\Frontend\PublicPages;
|
|
|
|
|
2021-10-08 06:13:21 +02:00
|
|
|
use App\Assets;
|
2020-05-15 12:13:47 +02:00
|
|
|
use App\Exception\StationNotFoundException;
|
|
|
|
use App\Exception\StationUnsupportedException;
|
|
|
|
use App\Http\Response;
|
|
|
|
use App\Http\ServerRequest;
|
2022-06-22 03:48:32 +02:00
|
|
|
use App\Radio\Adapters;
|
2020-05-15 12:13:47 +02:00
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
|
2022-05-22 02:27:28 +02:00
|
|
|
final class WebDjAction
|
2020-05-15 12:13:47 +02:00
|
|
|
{
|
2022-05-22 02:27:28 +02:00
|
|
|
public function __construct(
|
2022-06-22 03:48:32 +02:00
|
|
|
private readonly Assets $assets,
|
|
|
|
private readonly Adapters $adapters,
|
2022-05-22 02:27:28 +02:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2020-05-15 12:13:47 +02:00
|
|
|
public function __invoke(
|
|
|
|
ServerRequest $request,
|
|
|
|
Response $response,
|
2022-05-24 07:50:43 +02:00
|
|
|
string $station_id
|
2020-05-15 12:13:47 +02:00
|
|
|
): ResponseInterface {
|
|
|
|
$station = $request->getStation();
|
|
|
|
|
|
|
|
if (!$station->getEnablePublicPage()) {
|
2020-10-15 00:19:31 +02:00
|
|
|
throw new StationNotFoundException();
|
2020-05-15 12:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$station->getEnableStreamers()) {
|
2020-10-15 00:19:31 +02:00
|
|
|
throw new StationUnsupportedException();
|
2020-05-15 12:13:47 +02:00
|
|
|
}
|
|
|
|
|
2022-06-22 03:48:32 +02:00
|
|
|
$backend = $this->adapters->getBackendAdapter($station);
|
|
|
|
if (null === $backend) {
|
2020-10-15 00:19:31 +02:00
|
|
|
throw new StationUnsupportedException();
|
2020-05-15 12:13:47 +02:00
|
|
|
}
|
|
|
|
|
2021-10-08 06:13:21 +02:00
|
|
|
$router = $request->getRouter();
|
|
|
|
|
2020-05-15 12:13:47 +02:00
|
|
|
$wss_url = (string)$backend->getWebStreamingUrl($station, $request->getRouter()->getBaseUrl());
|
|
|
|
$wss_url = str_replace('wss://', '', $wss_url);
|
|
|
|
|
2021-10-08 06:13:21 +02:00
|
|
|
$libUrls = [];
|
2022-05-22 02:27:28 +02:00
|
|
|
$lib = $this->assets->getLibrary('Vue_PublicWebDJ');
|
2021-10-08 06:36:50 +02:00
|
|
|
if (null !== $lib) {
|
|
|
|
foreach (array_slice($lib['files']['js'], 0, -1) as $script) {
|
2022-05-22 02:27:28 +02:00
|
|
|
$libUrls[] = (string)($router->getBaseUrl()->withPath($this->assets->getUrl($script['src'])));
|
2021-10-08 06:36:50 +02:00
|
|
|
}
|
2021-10-08 06:13:21 +02:00
|
|
|
}
|
|
|
|
|
2021-10-08 10:49:41 +02:00
|
|
|
return $request->getView()->renderVuePage(
|
2022-05-17 09:51:00 +02:00
|
|
|
response: $response->withHeader('X-Frame-Options', '*'),
|
2021-10-08 10:49:41 +02:00
|
|
|
component: 'Vue_PublicWebDJ',
|
|
|
|
id: 'web_dj',
|
|
|
|
layout: 'minimal',
|
|
|
|
title: __('Web DJ') . ' - ' . $station->getName(),
|
|
|
|
layoutParams: [
|
|
|
|
'page_class' => 'dj station-' . $station->getShortName(),
|
|
|
|
'hide_footer' => true,
|
|
|
|
],
|
|
|
|
props: [
|
|
|
|
'stationName' => $station->getName(),
|
|
|
|
'libUrls' => $libUrls,
|
|
|
|
'baseUri' => $wss_url,
|
|
|
|
],
|
2021-10-08 06:13:21 +02:00
|
|
|
);
|
2020-05-15 12:13:47 +02:00
|
|
|
}
|
2020-10-15 00:19:31 +02:00
|
|
|
}
|