From d18c5dc9221cca29b255a163292e372a2a23f26e Mon Sep 17 00:00:00 2001 From: Aleksandr Nikitin Date: Wed, 22 Nov 2023 13:41:50 +0300 Subject: [PATCH] add stream selector --- composer.lock | 56 +++++++++++++-------------- src/Controller/AbstractController.php | 1 - src/Controller/InfoController.php | 1 - src/Controller/InstanceController.php | 20 +++++++--- 4 files changed, 42 insertions(+), 36 deletions(-) diff --git a/composer.lock b/composer.lock index 6aa32da..7fbfe4c 100644 --- a/composer.lock +++ b/composer.lock @@ -12,12 +12,12 @@ "source": { "type": "git", "url": "https://github.com/alexmorbo/trassir-php.git", - "reference": "a0ee25465422fe21890f154ebb54a4a3779cd37d" + "reference": "b5230811d854c87ccce8caa10d66081b589ed905" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/alexmorbo/trassir-php/zipball/a0ee25465422fe21890f154ebb54a4a3779cd37d", - "reference": "a0ee25465422fe21890f154ebb54a4a3779cd37d", + "url": "https://api.github.com/repos/alexmorbo/trassir-php/zipball/b5230811d854c87ccce8caa10d66081b589ed905", + "reference": "b5230811d854c87ccce8caa10d66081b589ed905", "shasum": "" }, "require": { @@ -48,7 +48,7 @@ "issues": "https://github.com/alexmorbo/trassir-php/issues", "source": "https://github.com/alexmorbo/trassir-php/tree/master" }, - "time": "2023-11-13T10:54:15+00:00" + "time": "2023-11-22T10:40:31+00:00" }, { "name": "clue/http-proxy-react", @@ -1279,24 +1279,24 @@ }, { "name": "react/promise", - "version": "v3.0.0", + "version": "v3.1.0", "source": { "type": "git", "url": "https://github.com/reactphp/promise.git", - "reference": "c86753c76fd3be465d93b308f18d189f01a22be4" + "reference": "e563d55d1641de1dea9f5e84f3cccc66d2bfe02c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/reactphp/promise/zipball/c86753c76fd3be465d93b308f18d189f01a22be4", - "reference": "c86753c76fd3be465d93b308f18d189f01a22be4", + "url": "https://api.github.com/repos/reactphp/promise/zipball/e563d55d1641de1dea9f5e84f3cccc66d2bfe02c", + "reference": "e563d55d1641de1dea9f5e84f3cccc66d2bfe02c", "shasum": "" }, "require": { "php": ">=7.1.0" }, "require-dev": { - "phpstan/phpstan": "1.10.20 || 1.4.10", - "phpunit/phpunit": "^9.5 || ^7.5" + "phpstan/phpstan": "1.10.39 || 1.4.10", + "phpunit/phpunit": "^9.6 || ^7.5" }, "type": "library", "autoload": { @@ -1340,7 +1340,7 @@ ], "support": { "issues": "https://github.com/reactphp/promise/issues", - "source": "https://github.com/reactphp/promise/tree/v3.0.0" + "source": "https://github.com/reactphp/promise/tree/v3.1.0" }, "funding": [ { @@ -1348,7 +1348,7 @@ "type": "open_collective" } ], - "time": "2023-07-11T16:12:49+00:00" + "time": "2023-11-16T16:21:57+00:00" }, { "name": "react/socket", @@ -1661,7 +1661,7 @@ }, { "name": "symfony/deprecation-contracts", - "version": "v3.3.0", + "version": "v3.4.0", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", @@ -1708,7 +1708,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.3.0" + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.4.0" }, "funding": [ { @@ -1882,7 +1882,7 @@ }, { "name": "symfony/event-dispatcher-contracts", - "version": "v3.3.0", + "version": "v3.4.0", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher-contracts.git", @@ -1938,7 +1938,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v3.3.0" + "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v3.4.0" }, "funding": [ { @@ -2641,16 +2641,16 @@ }, { "name": "symfony/service-contracts", - "version": "v3.3.0", + "version": "v3.4.0", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "40da9cc13ec349d9e4966ce18b5fbcd724ab10a4" + "reference": "b3313c2dbffaf71c8de2934e2ea56ed2291a3838" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/40da9cc13ec349d9e4966ce18b5fbcd724ab10a4", - "reference": "40da9cc13ec349d9e4966ce18b5fbcd724ab10a4", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/b3313c2dbffaf71c8de2934e2ea56ed2291a3838", + "reference": "b3313c2dbffaf71c8de2934e2ea56ed2291a3838", "shasum": "" }, "require": { @@ -2703,7 +2703,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/service-contracts/tree/v3.3.0" + "source": "https://github.com/symfony/service-contracts/tree/v3.4.0" }, "funding": [ { @@ -2719,7 +2719,7 @@ "type": "tidelift" } ], - "time": "2023-05-23T14:45:45+00:00" + "time": "2023-07-30T20:28:31+00:00" }, { "name": "symfony/string", @@ -2904,16 +2904,16 @@ }, { "name": "symfony/translation-contracts", - "version": "v3.3.0", + "version": "v3.4.0", "source": { "type": "git", "url": "https://github.com/symfony/translation-contracts.git", - "reference": "02c24deb352fb0d79db5486c0c79905a85e37e86" + "reference": "dee0c6e5b4c07ce851b462530088e64b255ac9c5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation-contracts/zipball/02c24deb352fb0d79db5486c0c79905a85e37e86", - "reference": "02c24deb352fb0d79db5486c0c79905a85e37e86", + "url": "https://api.github.com/repos/symfony/translation-contracts/zipball/dee0c6e5b4c07ce851b462530088e64b255ac9c5", + "reference": "dee0c6e5b4c07ce851b462530088e64b255ac9c5", "shasum": "" }, "require": { @@ -2962,7 +2962,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/translation-contracts/tree/v3.3.0" + "source": "https://github.com/symfony/translation-contracts/tree/v3.4.0" }, "funding": [ { @@ -2978,7 +2978,7 @@ "type": "tidelift" } ], - "time": "2023-05-30T17:17:10+00:00" + "time": "2023-07-25T15:08:44+00:00" }, { "name": "symfony/var-dumper", diff --git a/src/Controller/AbstractController.php b/src/Controller/AbstractController.php index b717d6a..cb48e29 100644 --- a/src/Controller/AbstractController.php +++ b/src/Controller/AbstractController.php @@ -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; diff --git a/src/Controller/InfoController.php b/src/Controller/InfoController.php index a61a154..03fba49 100644 --- a/src/Controller/InfoController.php +++ b/src/Controller/InfoController.php @@ -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; diff --git a/src/Controller/InstanceController.php b/src/Controller/InstanceController.php index 07e8f3d..c1130e2 100644 --- a/src/Controller/InstanceController.php +++ b/src/Controller/InstanceController.php @@ -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 ) ); } @@ -241,6 +242,7 @@ public function getChannelVideo( string $instanceId, string $channelId, string $streamType, + string $stream, ): PromiseInterface { $instanceId = (int)$instanceId; @@ -248,9 +250,13 @@ public function getChannelVideo( 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) { @@ -258,13 +264,15 @@ function (Instance $instance) use ($channelId, $streamType) { return $instance->getTrassir()->getVideo( $instance->getName(), $channelId, - $streamType + $streamType, + $stream, ); } else { return $instance->getTrassir()->getVideo( $channel['server_guid'], $channelId, - $streamType + $streamType, + $stream, ); } }