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
|
||||
namespace OCA\BigBlueButton\Controller;
|
||||
|
||||
use OCA\BigBlueButton\BigBlueButton\API;
|
||||
use OCA\BigBlueButton\BigBlueButton\Presentation;
|
||||
use OCP\AppFramework\Http\RedirectResponse;
|
||||
use OCP\AppFramework\PublicShareController;
|
||||
use OCP\IRequest;
|
||||
use OCP\ISession;
|
||||
use OCP\IUserSession;
|
||||
use OCP\IConfig;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\Files\NotFoundException;
|
||||
use OCA\BigBlueButton\Service\RoomService;
|
||||
use BigBlueButton\BigBlueButton;
|
||||
use BigBlueButton\Parameters\CreateMeetingParameters;
|
||||
use BigBlueButton\Parameters\JoinMeetingParameters;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
|
||||
class JoinController extends PublicShareController
|
||||
|
@ -25,8 +24,8 @@ class JoinController extends PublicShareController
|
|||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/** @var IURLGenerator */
|
||||
private $urlGenerator;
|
||||
/** @var API */
|
||||
private $api;
|
||||
|
||||
public function __construct(
|
||||
string $appName,
|
||||
|
@ -35,14 +34,14 @@ class JoinController extends PublicShareController
|
|||
RoomService $service,
|
||||
IUserSession $userSession,
|
||||
IConfig $config,
|
||||
IURLGenerator $urlGenerator
|
||||
API $api
|
||||
) {
|
||||
parent::__construct($appName, $request, $session);
|
||||
|
||||
$this->service = $service;
|
||||
$this->userSession = $userSession;
|
||||
$this->config = $config;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->api = $api;
|
||||
}
|
||||
|
||||
protected function getPasswordHash(): string
|
||||
|
@ -73,29 +72,45 @@ class JoinController extends PublicShareController
|
|||
* @PublicPage
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function index($displayname, $u, $filename)
|
||||
public function index($displayname, $u = '', $filename = '')
|
||||
{
|
||||
$room = $this->service->findByUid($this->getToken());
|
||||
|
||||
if ($room === null) {
|
||||
return 'Room not found';
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
$uid = null;
|
||||
$url = null;
|
||||
$userId = null;
|
||||
$presentation = null;
|
||||
|
||||
if ($this->userSession->isLoggedIn()) {
|
||||
$user = $this->userSession->getUser();
|
||||
$displayname = $user->getDisplayName();
|
||||
$uid = $user->getUID();
|
||||
$url = $u;
|
||||
$userId = $user->getUID();
|
||||
|
||||
if ($userId === $room->userId) {
|
||||
$presentation = new Presentation($u, $filename);
|
||||
}
|
||||
} elseif (empty($displayname) || strlen($displayname) < 3) {
|
||||
$apiUrl = $this->config->getAppValue($this->appName, 'api.url');
|
||||
$response = new TemplateResponse($this->appName, 'publicdisplayname', [
|
||||
'room' => $room->name,
|
||||
'wrongdisplayname' => !empty($displayname) && strlen($displayname) < 3
|
||||
], '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);
|
||||
|
||||
if ($parsedApiUrl === false) {
|
||||
|
@ -103,69 +118,5 @@ class JoinController extends PublicShareController
|
|||
}
|
||||
|
||||
$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