mirror of https://github.com/sualko/cloud_bbb
refactor: use adapter for bbb
parent
e1da5ebffc
commit
6005928e78
|
@ -0,0 +1,115 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace OCA\BigBlueButton\BigBlueButton;
|
||||||
|
|
||||||
|
use BigBlueButton\BigBlueButton;
|
||||||
|
use BigBlueButton\Parameters\CreateMeetingParameters;
|
||||||
|
use BigBlueButton\Parameters\JoinMeetingParameters;
|
||||||
|
use OCA\BigBlueButton\Db\Room;
|
||||||
|
use OCP\IConfig;
|
||||||
|
use OCP\IURLGenerator;
|
||||||
|
|
||||||
|
class API
|
||||||
|
{
|
||||||
|
/** @var IConfig */
|
||||||
|
private $config;
|
||||||
|
|
||||||
|
/** @var IURLGenerator */
|
||||||
|
private $urlGenerator;
|
||||||
|
|
||||||
|
/** @var BigBlueButton */
|
||||||
|
private $server;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
IConfig $config,
|
||||||
|
IURLGenerator $urlGenerator
|
||||||
|
) {
|
||||||
|
$this->config = $config;
|
||||||
|
$this->urlGenerator = $urlGenerator;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getServer()
|
||||||
|
{
|
||||||
|
if (!$this->server) {
|
||||||
|
$apiUrl = $this->config->getAppValue('bbb', 'api.url');
|
||||||
|
$secret = $this->config->getAppValue('bbb', 'api.secret');
|
||||||
|
|
||||||
|
$this->server = new BigBlueButton($apiUrl, $secret);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->server;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create join url.
|
||||||
|
*
|
||||||
|
* @return string join url
|
||||||
|
*/
|
||||||
|
public function createJoinUrl(Room $room, int $creationTime, string $displayname, string $uid = null)
|
||||||
|
{
|
||||||
|
$password = $uid === $room->userId ? $room->moderatorPassword : $room->attendeePassword;
|
||||||
|
|
||||||
|
$joinMeetingParams = new JoinMeetingParameters($room->uid, $displayname, $password);
|
||||||
|
|
||||||
|
$joinMeetingParams->setCreationTime($creationTime);
|
||||||
|
$joinMeetingParams->setJoinViaHtml5(true);
|
||||||
|
$joinMeetingParams->setRedirect(true);
|
||||||
|
|
||||||
|
if ($uid) {
|
||||||
|
$joinMeetingParams->setUserId($uid);
|
||||||
|
// $joinMeetingParams->setAvatarURL();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->getServer()->getJoinMeetingURL($joinMeetingParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create meeting room.
|
||||||
|
*
|
||||||
|
* @return int creation time
|
||||||
|
*/
|
||||||
|
public function createMeeting(Room $room, Presentation $presentation = null)
|
||||||
|
{
|
||||||
|
$bbb = $this->getServer();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $bbb->createMeeting($this->buildMeetingParams($room, $presentation));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
throw $e;
|
||||||
|
throw new \Exception('Can not process create request');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$response->success()) {
|
||||||
|
throw new \Exception('Can not create meeting');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response->getCreationTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildMeetingParams(Room $room, Presentation $presentation = null)
|
||||||
|
{
|
||||||
|
$createMeetingParams = new CreateMeetingParameters($room->uid, $room->name);
|
||||||
|
$createMeetingParams->setAttendeePassword($room->attendeePassword);
|
||||||
|
$createMeetingParams->setModeratorPassword($room->moderatorPassword);
|
||||||
|
$createMeetingParams->setRecord($room->record);
|
||||||
|
$createMeetingParams->setAllowStartStopRecording($room->record);
|
||||||
|
$createMeetingParams->setLogoutUrl($this->urlGenerator->getBaseUrl());
|
||||||
|
|
||||||
|
$invitationUrl = $this->urlGenerator->linkToRouteAbsolute('bbb.join.index', ['token' => $room->uid]);
|
||||||
|
$createMeetingParams->setModeratorOnlyMessage('To invite someone to the meeting, send them this link: ' . $invitationUrl);
|
||||||
|
|
||||||
|
if (!empty($room->welcome)) {
|
||||||
|
$createMeetingParams->setWelcomeMessage($room->welcome);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($room->maxParticipants > 0) {
|
||||||
|
$createMeetingParams->setMaxParticipants($room->maxParticipants);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($presentation !== null && $presentation->isValid()) {
|
||||||
|
$createMeetingParams->addPresentation($presentation->getUrl(), null, $presentation->getFilename());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $createMeetingParams;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace OCA\BigBlueButton\BigBlueButton;
|
||||||
|
|
||||||
|
class Presentation
|
||||||
|
{
|
||||||
|
private $url;
|
||||||
|
|
||||||
|
private $filename;
|
||||||
|
|
||||||
|
public function __construct(string $url, string $filename)
|
||||||
|
{
|
||||||
|
$this->url = $url;
|
||||||
|
$this->filename = $filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUrl()
|
||||||
|
{
|
||||||
|
return $this->url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFilename()
|
||||||
|
{
|
||||||
|
return $this->filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isValid()
|
||||||
|
{
|
||||||
|
return !empty($this->url) && !empty($this->filename);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,17 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
namespace OCA\BigBlueButton\Controller;
|
namespace OCA\BigBlueButton\Controller;
|
||||||
|
|
||||||
|
use OCA\BigBlueButton\BigBlueButton\API;
|
||||||
|
use OCA\BigBlueButton\BigBlueButton\Presentation;
|
||||||
use OCP\AppFramework\Http\RedirectResponse;
|
use OCP\AppFramework\Http\RedirectResponse;
|
||||||
use OCP\AppFramework\PublicShareController;
|
use OCP\AppFramework\PublicShareController;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\ISession;
|
use OCP\ISession;
|
||||||
use OCP\IUserSession;
|
use OCP\IUserSession;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OCP\IURLGenerator;
|
use OCP\Files\NotFoundException;
|
||||||
use OCA\BigBlueButton\Service\RoomService;
|
use OCA\BigBlueButton\Service\RoomService;
|
||||||
use BigBlueButton\BigBlueButton;
|
|
||||||
use BigBlueButton\Parameters\CreateMeetingParameters;
|
|
||||||
use BigBlueButton\Parameters\JoinMeetingParameters;
|
|
||||||
use OCP\AppFramework\Http\TemplateResponse;
|
use OCP\AppFramework\Http\TemplateResponse;
|
||||||
|
|
||||||
class JoinController extends PublicShareController
|
class JoinController extends PublicShareController
|
||||||
|
@ -25,8 +24,8 @@ class JoinController extends PublicShareController
|
||||||
/** @var IConfig */
|
/** @var IConfig */
|
||||||
private $config;
|
private $config;
|
||||||
|
|
||||||
/** @var IURLGenerator */
|
/** @var API */
|
||||||
private $urlGenerator;
|
private $api;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
string $appName,
|
string $appName,
|
||||||
|
@ -35,14 +34,14 @@ class JoinController extends PublicShareController
|
||||||
RoomService $service,
|
RoomService $service,
|
||||||
IUserSession $userSession,
|
IUserSession $userSession,
|
||||||
IConfig $config,
|
IConfig $config,
|
||||||
IURLGenerator $urlGenerator
|
API $api
|
||||||
) {
|
) {
|
||||||
parent::__construct($appName, $request, $session);
|
parent::__construct($appName, $request, $session);
|
||||||
|
|
||||||
$this->service = $service;
|
$this->service = $service;
|
||||||
$this->userSession = $userSession;
|
$this->userSession = $userSession;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->urlGenerator = $urlGenerator;
|
$this->api = $api;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getPasswordHash(): string
|
protected function getPasswordHash(): string
|
||||||
|
@ -73,29 +72,45 @@ class JoinController extends PublicShareController
|
||||||
* @PublicPage
|
* @PublicPage
|
||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
*/
|
*/
|
||||||
public function index($displayname, $u, $filename)
|
public function index($displayname, $u = '', $filename = '')
|
||||||
{
|
{
|
||||||
$room = $this->service->findByUid($this->getToken());
|
$room = $this->service->findByUid($this->getToken());
|
||||||
|
|
||||||
if ($room === null) {
|
if ($room === null) {
|
||||||
return 'Room not found';
|
throw new NotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$uid = null;
|
$userId = null;
|
||||||
$url = null;
|
$presentation = null;
|
||||||
|
|
||||||
if ($this->userSession->isLoggedIn()) {
|
if ($this->userSession->isLoggedIn()) {
|
||||||
$user = $this->userSession->getUser();
|
$user = $this->userSession->getUser();
|
||||||
$displayname = $user->getDisplayName();
|
$displayname = $user->getDisplayName();
|
||||||
$uid = $user->getUID();
|
$userId = $user->getUID();
|
||||||
$url = $u;
|
|
||||||
|
if ($userId === $room->userId) {
|
||||||
|
$presentation = new Presentation($u, $filename);
|
||||||
|
}
|
||||||
} elseif (empty($displayname) || strlen($displayname) < 3) {
|
} elseif (empty($displayname) || strlen($displayname) < 3) {
|
||||||
$apiUrl = $this->config->getAppValue($this->appName, 'api.url');
|
|
||||||
$response = new TemplateResponse($this->appName, 'publicdisplayname', [
|
$response = new TemplateResponse($this->appName, 'publicdisplayname', [
|
||||||
'room' => $room->name,
|
'room' => $room->name,
|
||||||
'wrongdisplayname' => !empty($displayname) && strlen($displayname) < 3
|
'wrongdisplayname' => !empty($displayname) && strlen($displayname) < 3
|
||||||
], 'guest');
|
], 'guest');
|
||||||
|
|
||||||
|
$this->addFormActionDomain($response);
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
$creationDate = $this->api->createMeeting($room, $presentation);
|
||||||
|
$joinUrl = $this->api->createJoinUrl($room, $creationDate, $displayname, $userId);
|
||||||
|
|
||||||
|
return new RedirectResponse($joinUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function addFormActionDomain($response)
|
||||||
|
{
|
||||||
|
$apiUrl = $this->config->getAppValue($this->appName, 'api.url');
|
||||||
$parsedApiUrl = parse_url($apiUrl);
|
$parsedApiUrl = parse_url($apiUrl);
|
||||||
|
|
||||||
if ($parsedApiUrl === false) {
|
if ($parsedApiUrl === false) {
|
||||||
|
@ -103,69 +118,5 @@ class JoinController extends PublicShareController
|
||||||
}
|
}
|
||||||
|
|
||||||
$response->getContentSecurityPolicy()->addAllowedFormActionDomain(($parsedApiUrl['scheme'] ?: 'https') . '://' . $parsedApiUrl['host']);
|
$response->getContentSecurityPolicy()->addAllowedFormActionDomain(($parsedApiUrl['scheme'] ?: 'https') . '://' . $parsedApiUrl['host']);
|
||||||
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->processPublicJoin($room, $displayname, $uid, $url, $filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function processPublicJoin($room, $displayname, $uid, $presentation, $filename)
|
|
||||||
{
|
|
||||||
$apiUrl = $this->config->getAppValue($this->appName, 'api.url');
|
|
||||||
$secret = $this->config->getAppValue($this->appName, 'api.secret');
|
|
||||||
|
|
||||||
$bbb = new BigBlueButton($apiUrl, $secret);
|
|
||||||
|
|
||||||
$createMeetingParams = new CreateMeetingParameters($room->uid, $room->name);
|
|
||||||
$createMeetingParams->setAttendeePassword($room->attendeePassword);
|
|
||||||
$createMeetingParams->setModeratorPassword($room->moderatorPassword);
|
|
||||||
$createMeetingParams->setRecord($room->record);
|
|
||||||
$createMeetingParams->setAllowStartStopRecording($room->record);
|
|
||||||
$createMeetingParams->setLogoutUrl($this->urlGenerator->getBaseUrl());
|
|
||||||
|
|
||||||
$invitationUrl = $this->urlGenerator->linkToRouteAbsolute('bbb.join.index', ['token' => $this->getToken()]);
|
|
||||||
$createMeetingParams->setModeratorOnlyMessage('To invite someone to the meeting, send them this link: ' . $invitationUrl);
|
|
||||||
|
|
||||||
if (!empty($room->welcome)) {
|
|
||||||
$createMeetingParams->setWelcomeMessage($room->welcome);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($room->maxParticipants > 0) {
|
|
||||||
$createMeetingParams->setMaxParticipants($room->maxParticipants);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($presentation) {
|
|
||||||
$createMeetingParams->addPresentation($presentation, null, $filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$response = $bbb->createMeeting($createMeetingParams);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
throw $e;
|
|
||||||
throw new \Exception('Can not process create request');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$response->success()) {
|
|
||||||
throw new \Exception('Can not create meeting');
|
|
||||||
}
|
|
||||||
|
|
||||||
$password = $uid === $room->userId ? $room->moderatorPassword : $room->attendeePassword;
|
|
||||||
|
|
||||||
|
|
||||||
$joinMeetingParams = new JoinMeetingParameters($room->uid, $displayname, $password);
|
|
||||||
|
|
||||||
$joinMeetingParams->setCreationTime($response->getCreationTime());
|
|
||||||
$joinMeetingParams->setJoinViaHtml5(true);
|
|
||||||
|
|
||||||
if ($uid) {
|
|
||||||
$joinMeetingParams->setUserId($uid);
|
|
||||||
// $joinMeetingParams->setAvatarURL();
|
|
||||||
}
|
|
||||||
|
|
||||||
$joinMeetingParams->setRedirect(true);
|
|
||||||
$joinUrl = $bbb->getJoinMeetingURL($joinMeetingParams);
|
|
||||||
|
|
||||||
return new RedirectResponse($joinUrl);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue