<?php
namespace App\Controller;
use App\Security\ApiUser;
use App\Service\Client\LivecamService;
use App\Service\Client\User\AmateurListingService;
use App\Service\Client\User\MemberPropertyService;
use App\Service\Client\User\MemberService;
use App\Service\LivecamOnlineService;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/livecams")
*/
class LivecamController extends AbstractController
{
public function __construct(
protected LivecamService $livecamService,
protected MemberService $memberService,
protected AmateurListingService $amateurService,
protected MemberPropertyService $propertyService
)
{
}
/**
* @Route("/{page}", requirements={"page": "\d+"}, defaults={"page": 1})
* @Template()
* @param int $page
* @param LivecamOnlineService $livecamOnlineService
* @return array
*/
public function index(int $page, LivecamOnlineService $livecamOnlineService): array
{
$livecamAmateurs = $this->amateurService->getLivecamAmateurs($page, 15, $livecamOnlineService);
$onlineAmateurs = $this->amateurService->getOnlineAmateurs(1, 15);
return [
'amateurs' => $livecamAmateurs,
'online_amateurs' => $onlineAmateurs,
'page' => $page
];
}
/**
* @Route("/app/watch/{username}")
* @Template()
* @param string $username
* @return array|RedirectResponse
* @throws \Psr\Cache\InvalidArgumentException
* @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface
* @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
* @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
*/
public function watch(string $username)
{
$this->denyAccessUnlessGranted('ROLE_MEMBER');
try {
$amateur = $this->memberService->getMemberDetailByUsername($username);
} catch (NotFoundHttpException $e) {
if (empty($amateur) || !$amateur['is_amateur'] || !$amateur['is_active']) {
throw $this->createNotFoundException('Amateur nicht gefunden.');
}
}
/**
* @var $user ApiUser
*/
$user = $this->getUser();
return [
'isDev' => $this->getParameter('kernel.environment') === "dev",
'amateur' => $amateur,
'appConfig' => [
'amateurName' => $amateur['username'],
'memberName' => $user = $this->getUser()->getUserIdentifier(),
'socketUrl' => $this->livecamService->getSocketUrl(),
]
];
}
/**
* @Route("/app/send")
* @Template()
* @return array
*/
public function send(): array
{
$this->denyAccessUnlessGranted('ROLE_AMATEUR');
return [
'isDev' => $this->getParameter('kernel.environment') === "dev",
'appConfig' => [
'amateurName' => $user = $this->getUser()->getUserIdentifier(),
'socketUrl' => $this->livecamService->getSocketUrl(),
]
];
}
}