Skip to content

Commit

Permalink
add stream selector
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmorbo committed Nov 22, 2023
1 parent a321b6f commit d18c5dc
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 36 deletions.
56 changes: 28 additions & 28 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace AlexMorbo\React\Trassir\Controller;

use AlexMorbo\React\Trassir\Router\Router;
use HttpSoft\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
use React\Promise\PromiseInterface;
Expand Down
1 change: 0 additions & 1 deletion src/Controller/InfoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use AlexMorbo\React\Trassir\Router\Router;
use Fig\Http\Message\StatusCodeInterface;
use Psr\Http\Message\ResponseInterface;
use React\Http\Message\Response;
use React\Promise\PromiseInterface;
use Symfony\Component\Yaml\Yaml;
Expand Down
20 changes: 14 additions & 6 deletions src/Controller/InstanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ public function addRoutes(Router $router): void
)
);
$router->get(
"/api/instance/{instanceId}/channel/{channelId}/video/{streamType}",
fn(ServerRequestInterface $request, $instanceId, $channelId, $streamType) => $this->getChannelVideo(
"/api/instance/{instanceId}/channel/{channelId}/video/{streamType}/{stream}",
fn(ServerRequestInterface $request, $instanceId, $channelId, $streamType, $stream) => $this->getChannelVideo(
$request,
$instanceId,
$channelId,
$streamType
$streamType,
$stream
)
);
}
Expand Down Expand Up @@ -241,30 +242,37 @@ public function getChannelVideo(
string $instanceId,
string $channelId,
string $streamType,
string $stream,
): PromiseInterface {
$instanceId = (int)$instanceId;

if (!in_array($streamType, ['hls', 'rtsp'])) {
throw new BadRequestHttpException('Invalid stream type');
}

if (!in_array($stream, ['main', 'sub'])) {
throw new BadRequestHttpException('Invalid stream type');
}

return $this->trassirHelper->getInstance($instanceId)
->then(
function (Instance $instance) use ($channelId, $streamType) {
function (Instance $instance) use ($channelId, $streamType, $stream) {
foreach ($instance->getTrassir()->getChannels() as $type => $channels) {
foreach ($channels as $channel) {
if ($channel['guid'] === $channelId) {
if ($type === 'channels') {
return $instance->getTrassir()->getVideo(
$instance->getName(),
$channelId,
$streamType
$streamType,
$stream,
);
} else {
return $instance->getTrassir()->getVideo(
$channel['server_guid'],
$channelId,
$streamType
$streamType,
$stream,
);
}
}
Expand Down

0 comments on commit d18c5dc

Please sign in to comment.