Abstract URIs to stations/web containers.

This commit is contained in:
Buster "Silver Eagle" Neece 2022-01-27 19:33:07 -06:00
parent 02d070b6dd
commit 2bdc2616ad
No known key found for this signature in database
GPG Key ID: 9FC8B9E008872109
6 changed files with 42 additions and 17 deletions

View File

@ -479,10 +479,16 @@ return [
),
// Supervisor manager
Supervisor\Supervisor::class => static function (Environment $settings, Psr\Log\LoggerInterface $logger) {
/** @noinspection HttpUrlsUsage */
Supervisor\Supervisor::class => static function (
Environment $environment,
Psr\Log\LoggerInterface $logger
) {
$uri = $environment->getUriToStations()
->withPort(9001)
->withPath('/RPC2');
$client = new fXmlRpc\Client(
'http://' . ($settings->isDocker() ? 'stations' : '127.0.0.1') . ':9001/RPC2',
(string)$uri,
new fXmlRpc\Transport\PsrTransport(
new Http\Factory\Guzzle\RequestFactory,
new GuzzleHttp\Client

View File

@ -8,6 +8,8 @@ use App\Enums\ApplicationEnvironment;
use App\Enums\ReleaseChannel;
use App\Radio\Configuration;
use App\Traits\AvailableStaticallyTrait;
use GuzzleHttp\Psr7\Uri;
use Psr\Http\Message\UriInterface;
use Psr\Log\LogLevel;
class Environment
@ -206,6 +208,24 @@ class Environment
return ($compareVersion >= $version);
}
public function getUriToWeb(): UriInterface
{
if ($this->isDocker()) {
return $this->isDockerRevisionAtLeast(5)
? new Uri('http://web')
: new Uri('http://nginx');
}
return new Uri('http://127.0.0.1');
}
public function getUriToStations(): UriInterface
{
return $this->isDocker()
? new Uri('http://stations')
: new Uri('http://127.0.0.1');
}
public function getLang(): ?string
{
return $this->data[self::LANG];

View File

@ -195,9 +195,12 @@ class Liquidsoap extends AbstractBackend
*/
public function command(Entity\Station $station, string $command_str): array
{
$hostname = ($this->environment->isDocker() ? 'stations' : 'localhost');
$uri = $this->environment->getUriToStations()
->withScheme('tcp')
->withPort($this->getTelnetPort($station));
$fp = stream_socket_client(
'tcp://' . $hostname . ':' . $this->getTelnetPort($station),
(string)$uri,
$errno,
$errstr,
20

View File

@ -129,14 +129,10 @@ class ConfigWriter implements EventSubscriberInterface
$stationTz = self::cleanUpString($station->getTimezone());
$stationApiAuth = self::cleanUpString($station->getAdapterApiKey());
if ($this->environment->isDocker()) {
$apiServiceUrl = ($this->environment->isDockerRevisionAtLeast(5))
? 'web'
: 'nginx';
} else {
$apiServiceUrl = 'localhost';
}
$stationApiUrl = self::cleanUpString('http://' . $apiServiceUrl . '/api/internal/' . $station->getId());
$stationApiUrl = self::cleanUpString(
(string)$this->environment->getUriToWeb()
->withPath('/api/internal/' . $station->getId())
);
$event->appendBlock(
<<<EOF

View File

@ -54,8 +54,8 @@ class Icecast extends AbstractFrontend
$feConfig = $station->getFrontendConfig();
$radioPort = $feConfig->getPort();
/** @noinspection HttpUrlsUsage */
$baseUrl = 'http://' . ($this->environment->isDocker() ? 'stations' : 'localhost') . ':' . $radioPort;
$baseUrl = $this->environment->getUriToStations()
->withPort($radioPort);
$npAdapter = $this->adapterFactory->getIcecastAdapter($baseUrl);

View File

@ -57,8 +57,8 @@ class SHOUTcast extends AbstractFrontend
$feConfig = $station->getFrontendConfig();
$radioPort = $feConfig->getPort();
/** @noinspection HttpUrlsUsage */
$baseUrl = 'http://' . ($this->environment->isDocker() ? 'stations' : 'localhost') . ':' . $radioPort;
$baseUrl = $this->environment->getUriToStations()
->withPort($radioPort);
$npAdapter = $this->adapterFactory->getShoutcast2Adapter($baseUrl);
$npAdapter->setAdminPassword($feConfig->getAdminPassword());