Reduce redundant code on public player.
This commit is contained in:
parent
43d9624c76
commit
8bf557e823
|
@ -26,6 +26,10 @@ final class PlayerAction
|
||||||
string $station_id,
|
string $station_id,
|
||||||
?string $embed = null,
|
?string $embed = null,
|
||||||
): ResponseInterface {
|
): ResponseInterface {
|
||||||
|
$response = $response
|
||||||
|
->withHeader('X-Frame-Options', '*')
|
||||||
|
->withHeader('X-Robots-Tag', 'index, nofollow');
|
||||||
|
|
||||||
$station = $request->getStation();
|
$station = $request->getStation();
|
||||||
|
|
||||||
if (!$station->getEnablePublicPage()) {
|
if (!$station->getEnablePublicPage()) {
|
||||||
|
@ -40,24 +44,67 @@ final class PlayerAction
|
||||||
$defaultAlbumArtUri = $this->stationRepo->getDefaultAlbumArtUrl($station);
|
$defaultAlbumArtUri = $this->stationRepo->getDefaultAlbumArtUrl($station);
|
||||||
$defaultAlbumArt = Router::resolveUri($baseUrl, $defaultAlbumArtUri, true);
|
$defaultAlbumArt = Router::resolveUri($baseUrl, $defaultAlbumArtUri, true);
|
||||||
|
|
||||||
$autoplay = !empty($request->getQueryParam('autoplay'));
|
// Build Vue props.
|
||||||
|
$customization = $request->getCustomization();
|
||||||
|
$router = $request->getRouter();
|
||||||
|
|
||||||
$templateName = (!empty($embed))
|
$props = [
|
||||||
? 'frontend/public/embed'
|
'initialNowPlaying' => $np,
|
||||||
: 'frontend/public/index';
|
'showAlbumArt' => !$customization->hideAlbumArt(),
|
||||||
|
'autoplay' => !empty($request->getQueryParam('autoplay')),
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($customization->useWebSocketsForNowPlaying()) {
|
||||||
|
$props['useNchan'] = true;
|
||||||
|
$props['nowPlayingUri'] = '/api/live/nowplaying/' . urlencode($station->getShortName());
|
||||||
|
} else {
|
||||||
|
$props['useNchan'] = false;
|
||||||
|
$props['nowPlayingUri'] = (string)$router->named(
|
||||||
|
'api:nowplaying:index',
|
||||||
|
['station_id' => $station->getId()]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render embedded player.
|
||||||
|
if (!empty($embed)) {
|
||||||
|
$pageClasses = [];
|
||||||
|
$pageClasses[] = 'page-station-public-player-embed station-' . $station->getShortName();
|
||||||
|
$pageClasses[] = ('social' === $embed) ? 'embed-social' : 'embed';
|
||||||
|
|
||||||
|
return $request->getView()->renderVuePage(
|
||||||
|
response: $response,
|
||||||
|
component: 'Vue_PublicPlayer',
|
||||||
|
id: 'station-nowplaying',
|
||||||
|
layout: 'minimal',
|
||||||
|
title: $station->getName(),
|
||||||
|
layoutParams: [
|
||||||
|
'page_class' => implode(' ', $pageClasses),
|
||||||
|
'hide_footer' => true,
|
||||||
|
],
|
||||||
|
props: $props,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render full page player.
|
||||||
|
$props['stationName'] = $station->getName();
|
||||||
|
$props['enableRequests'] = $station->getEnableRequests();
|
||||||
|
$props['downloadPlaylistUri'] = (string)$router->named(
|
||||||
|
'public:playlist',
|
||||||
|
['station_id' => $station->getShortName(), 'format' => 'pls']
|
||||||
|
);
|
||||||
|
$props['requestListUri'] = (string)$router->named(
|
||||||
|
'api:requests:list',
|
||||||
|
['station_id' => $station->getId()]
|
||||||
|
);
|
||||||
|
$props['customFields'] = $this->customFieldRepo->fetchArray();
|
||||||
|
|
||||||
return $request->getView()->renderToResponse(
|
return $request->getView()->renderToResponse(
|
||||||
$response
|
$response,
|
||||||
->withHeader('X-Frame-Options', '*')
|
'frontend/public/index',
|
||||||
->withHeader('X-Robots-Tag', 'index, nofollow'),
|
|
||||||
$templateName,
|
|
||||||
[
|
[
|
||||||
'isSocial' => ('social' === $embed),
|
|
||||||
'autoplay' => $autoplay,
|
|
||||||
'station' => $station,
|
'station' => $station,
|
||||||
|
'props' => $props,
|
||||||
'defaultAlbumArt' => $defaultAlbumArt,
|
'defaultAlbumArt' => $defaultAlbumArt,
|
||||||
'nowplaying' => $np,
|
|
||||||
'customFields' => $this->customFieldRepo->fetchArray(),
|
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
<?php
|
|
||||||
/** @var App\Entity\Station $station */
|
|
||||||
|
|
||||||
$pageClasses = [];
|
|
||||||
$pageClasses[] = 'page-station-public-player-embed station-' . $station->getShortName();
|
|
||||||
$pageClasses[] = ($isSocial) ? 'embed-social' : 'embed';
|
|
||||||
|
|
||||||
$this->layout(
|
|
||||||
'minimal',
|
|
||||||
[
|
|
||||||
'page_class' => implode(' ', $pageClasses),
|
|
||||||
'title' => $this->e($station->getName()),
|
|
||||||
'hide_footer' => true,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$props = [
|
|
||||||
'initialNowPlaying' => $nowplaying,
|
|
||||||
'showAlbumArt' => !$customization->hideAlbumArt(),
|
|
||||||
'autoplay' => $autoplay,
|
|
||||||
];
|
|
||||||
|
|
||||||
if ($customization->useWebSocketsForNowPlaying()) {
|
|
||||||
$props['useNchan'] = true;
|
|
||||||
$props['nowPlayingUri'] = '/api/live/nowplaying/' . urlencode($station->getShortName());
|
|
||||||
} else {
|
|
||||||
$props['useNchan'] = false;
|
|
||||||
$props['nowPlayingUri'] = (string)$router->named('api:nowplaying:index', ['station_id' => $station->getId()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var \App\Assets $assets */
|
|
||||||
$assets->addVueRender('Vue_PublicPlayer', '#station-nowplaying', $props);
|
|
||||||
?>
|
|
||||||
|
|
||||||
<div class="stations nowplaying">
|
|
||||||
<div id="station-nowplaying"></div>
|
|
||||||
</div>
|
|
|
@ -8,35 +8,12 @@ $this->layout(
|
||||||
'minimal',
|
'minimal',
|
||||||
[
|
[
|
||||||
'page_class' => 'page-station-public-player station-' . $station->getShortName(),
|
'page_class' => 'page-station-public-player station-' . $station->getShortName(),
|
||||||
'title' => $this->e($station->getName()),
|
'title' => $this->e($station->getName()),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
$props = [
|
|
||||||
'stationName' => $station->getName(),
|
|
||||||
'enableRequests' => $station->getEnableRequests(),
|
|
||||||
'autoplay' => $autoplay,
|
|
||||||
'downloadPlaylistUri' => (string)$router->named(
|
|
||||||
'public:playlist',
|
|
||||||
['station_id' => $station->getShortName(), 'format' => 'pls']
|
|
||||||
),
|
|
||||||
'requestListUri' => (string)$router->named('api:requests:list', ['station_id' => $station->getId()]),
|
|
||||||
'customFields' => $customFields,
|
|
||||||
'initialNowPlaying' => $nowplaying,
|
|
||||||
'showAlbumArt' => !$customization->hideAlbumArt(),
|
|
||||||
];
|
|
||||||
|
|
||||||
if ($customization->useWebSocketsForNowPlaying()) {
|
|
||||||
$props['useNchan'] = true;
|
|
||||||
$props['nowPlayingUri'] = '/api/live/nowplaying/' . urlencode($station->getShortName());
|
|
||||||
} else {
|
|
||||||
$props['useNchan'] = false;
|
|
||||||
$props['nowPlayingUri'] = (string)$router->named('api:nowplaying:index', ['station_id' => $station->getId()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var \App\Assets $assets */
|
/** @var \App\Assets $assets */
|
||||||
$assets
|
$assets->addVueRender('Vue_PublicFullPlayer', '#public-radio-player', $props);
|
||||||
->addVueRender('Vue_PublicFullPlayer', '#public-radio-player', $props);
|
|
||||||
|
|
||||||
// Register PWA service worker
|
// Register PWA service worker
|
||||||
$swJsRoute = (string)$router->named('public:sw');
|
$swJsRoute = (string)$router->named('public:sw');
|
||||||
|
|
Loading…
Reference in New Issue