cloud_bbb/lib/Controller/HookController.php

92 lines
1.9 KiB
PHP
Raw Permalink Normal View History

<?php
namespace OCA\BigBlueButton\Controller;
2022-01-05 09:59:49 +01:00
use OCA\BigBlueButton\AvatarRepository;
use OCA\BigBlueButton\Db\Room;
2020-09-22 13:32:25 +02:00
use OCA\BigBlueButton\Event\MeetingEndedEvent;
use OCA\BigBlueButton\Event\RecordingReadyEvent;
2020-09-23 12:33:09 +02:00
use OCA\BigBlueButton\Service\RoomService;
use OCP\AppFramework\Controller;
2020-09-23 12:33:09 +02:00
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IRequest;
class HookController extends Controller {
/** @var string */
protected $token;
/** @var Room|null */
protected $room;
/** @var RoomService */
private $service;
2022-01-05 09:59:49 +01:00
/** @var AvatarRepository */
private $avatarRepository;
/** @var IEventDispatcher */
private $eventDispatcher;
public function __construct(
string $appName,
IRequest $request,
RoomService $service,
2022-01-05 09:59:49 +01:00
AvatarRepository $avatarRepository,
IEventDispatcher $eventDispatcher
) {
parent::__construct($appName, $request);
$this->service = $service;
2022-01-05 09:59:49 +01:00
$this->avatarRepository = $avatarRepository;
$this->eventDispatcher = $eventDispatcher;
}
public function setToken(string $token): void {
$this->token = $token;
$this->room = null;
}
public function isValidToken(): bool {
$room = $this->getRoom();
return $room !== null;
}
/**
* @PublicPage
*
* @NoCSRFRequired
*
* @return void
*/
public function meetingEnded($recordingmarks = false): void {
$recordingmarks = \boolval($recordingmarks);
2022-01-05 09:59:49 +01:00
$room = $this->getRoom();
$this->service->updateRunning($room->getId(), false);
2022-01-05 09:59:49 +01:00
$this->avatarRepository->clearRoom($room->uid);
2022-01-05 09:59:49 +01:00
$this->eventDispatcher->dispatch(MeetingEndedEvent::class, new MeetingEndedEvent($room, $recordingmarks));
}
/**
* @PublicPage
*
* @NoCSRFRequired
*
* @return void
*/
public function recordingReady(): void {
$this->eventDispatcher->dispatch(RecordingReadyEvent::class, new RecordingReadyEvent($this->getRoom()));
}
private function getRoom(): ?Room {
if ($this->room === null) {
$this->room = $this->service->findByUid($this->token);
}
return $this->room;
}
}