Reduce redundant code on public player.

This commit is contained in:
Buster "Silver Eagle" Neece 2022-06-20 11:33:20 -05:00
parent 43d9624c76
commit 8bf557e823
No known key found for this signature in database
GPG Key ID: F1D2E64A0005E80E
3 changed files with 61 additions and 74 deletions

View File

@ -26,6 +26,10 @@ final class PlayerAction
string $station_id,
?string $embed = null,
): ResponseInterface {
$response = $response
->withHeader('X-Frame-Options', '*')
->withHeader('X-Robots-Tag', 'index, nofollow');
$station = $request->getStation();
if (!$station->getEnablePublicPage()) {
@ -40,24 +44,67 @@ final class PlayerAction
$defaultAlbumArtUri = $this->stationRepo->getDefaultAlbumArtUrl($station);
$defaultAlbumArt = Router::resolveUri($baseUrl, $defaultAlbumArtUri, true);
$autoplay = !empty($request->getQueryParam('autoplay'));
// Build Vue props.
$customization = $request->getCustomization();
$router = $request->getRouter();
$templateName = (!empty($embed))
? 'frontend/public/embed'
: 'frontend/public/index';
$props = [
'initialNowPlaying' => $np,
'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(
$response
->withHeader('X-Frame-Options', '*')
->withHeader('X-Robots-Tag', 'index, nofollow'),
$templateName,
$response,
'frontend/public/index',
[
'isSocial' => ('social' === $embed),
'autoplay' => $autoplay,
'station' => $station,
'props' => $props,
'defaultAlbumArt' => $defaultAlbumArt,
'nowplaying' => $np,
'customFields' => $this->customFieldRepo->fetchArray(),
]
);
}

View File

@ -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>

View File

@ -8,35 +8,12 @@ $this->layout(
'minimal',
[
'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 */
$assets
->addVueRender('Vue_PublicFullPlayer', '#public-radio-player', $props);
$assets->addVueRender('Vue_PublicFullPlayer', '#public-radio-player', $props);
// Register PWA service worker
$swJsRoute = (string)$router->named('public:sw');