зеркало из https://github.com/nextcloud/spreed.git
Generate a attendee pin for the moderator when enabling SIP and return it
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Родитель
21194ecb64
Коммит
e0c4fd1b12
|
@ -367,7 +367,7 @@ return [
|
|||
'url' => '/api/{apiVersion}/room/{token}/pin/{pin}',
|
||||
'verb' => 'GET',
|
||||
'requirements' => [
|
||||
'apiVersion' => 'v(2|3)', // FIXME v3 only?
|
||||
'apiVersion' => 'v3',
|
||||
'token' => '^[a-z0-9]{4,30}$',
|
||||
'pin' => '^\d{7,32}$',
|
||||
],
|
||||
|
@ -381,6 +381,26 @@ return [
|
|||
'token' => '^[a-z0-9]{4,30}$',
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'Room#setLobby',
|
||||
'url' => '/api/{apiVersion}/room/{token}/{webinar}/lobby',
|
||||
'verb' => 'PUT',
|
||||
'requirements' => [
|
||||
'apiVersion' => 'v(1|2|3)',
|
||||
'webinar' => 'webinary?',
|
||||
'token' => '^[a-z0-9]{4,30}$',
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'Room#setSIPEnabled',
|
||||
'url' => '/api/{apiVersion}/room/{token}/{webinar}/sip',
|
||||
'verb' => 'PUT',
|
||||
'requirements' => [
|
||||
'apiVersion' => 'v3',
|
||||
'webinar' => 'webinary?',
|
||||
'token' => '^[a-z0-9]{4,30}$',
|
||||
],
|
||||
],
|
||||
|
||||
/**
|
||||
* Bridge settings
|
||||
|
@ -499,30 +519,6 @@ return [
|
|||
],
|
||||
],
|
||||
|
||||
/**
|
||||
* Webinar
|
||||
*/
|
||||
[
|
||||
'name' => 'Webinar#setLobby',
|
||||
'url' => '/api/{apiVersion}/room/{token}/{webinar}/lobby',
|
||||
'verb' => 'PUT',
|
||||
'requirements' => [
|
||||
'apiVersion' => 'v(1|2)',
|
||||
'webinar' => 'webinary?',
|
||||
'token' => '^[a-z0-9]{4,30}$',
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'Webinar#setSIPEnabled',
|
||||
'url' => '/api/{apiVersion}/room/{token}/{webinar}/sip',
|
||||
'verb' => 'PUT',
|
||||
'requirements' => [
|
||||
'apiVersion' => 'v(1|2)',// FIXME v2 only?
|
||||
'webinar' => 'webinary?',
|
||||
'token' => '^[a-z0-9]{4,30}$',
|
||||
],
|
||||
],
|
||||
|
||||
/**
|
||||
* Settings
|
||||
*/
|
||||
|
|
|
@ -1644,4 +1644,73 @@ class RoomController extends AEnvironmentAwareController {
|
|||
|
||||
return new DataResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @RequireModeratorParticipant
|
||||
*
|
||||
* @param int $state
|
||||
* @param int|null $timer
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function setLobby(int $state, ?int $timer = null): DataResponse {
|
||||
$timerDateTime = null;
|
||||
if ($timer !== null && $timer > 0) {
|
||||
try {
|
||||
$timerDateTime = $this->timeFactory->getDateTime('@' . $timer);
|
||||
$timerDateTime->setTimezone(new \DateTimeZone('UTC'));
|
||||
} catch (\Exception $e) {
|
||||
return new DataResponse([], Http::STATUS_BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->room->setLobby($state, $timerDateTime)) {
|
||||
return new DataResponse([], Http::STATUS_BAD_REQUEST);
|
||||
}
|
||||
|
||||
if ($state === Webinary::LOBBY_NON_MODERATORS) {
|
||||
$participants = $this->participantService->getParticipantsInCall($this->room);
|
||||
foreach ($participants as $participant) {
|
||||
if ($participant->hasModeratorPermissions()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->participantService->changeInCall($this->room, $participant, Participant::FLAG_DISCONNECTED);
|
||||
}
|
||||
}
|
||||
|
||||
return new DataResponse($this->formatRoomV2andV3($this->room, $this->participant));
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @RequireModeratorParticipant
|
||||
*
|
||||
* @param int $state
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function setSIPEnabled(int $state): DataResponse {
|
||||
$user = $this->userManager->get($this->userId);
|
||||
if (!$user instanceof IUser) {
|
||||
return new DataResponse([], Http::STATUS_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
if (!$this->talkConfig->canUserEnableSIP($user)) {
|
||||
return new DataResponse([], Http::STATUS_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
if (!$this->talkConfig->isSIPConfigured()) {
|
||||
return new DataResponse([], Http::STATUS_PRECONDITION_FAILED);
|
||||
}
|
||||
|
||||
if (!$this->room->setSIPEnabled($state)) {
|
||||
return new DataResponse([], Http::STATUS_BAD_REQUEST);
|
||||
}
|
||||
|
||||
if ($state === Webinary::SIP_ENABLED) {
|
||||
$this->participantService->generatePinForParticipant($this->room, $this->participant);
|
||||
}
|
||||
|
||||
return new DataResponse($this->formatRoomV2andV3($this->room, $this->participant));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,131 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* @copyright Copyright (c) 2019 Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @author Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Talk\Controller;
|
||||
|
||||
use OCA\Talk\Config;
|
||||
use OCA\Talk\Participant;
|
||||
use OCA\Talk\Service\ParticipantService;
|
||||
use OCA\Talk\Webinary;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\IRequest;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
|
||||
class WebinarController extends AEnvironmentAwareController {
|
||||
|
||||
/** @var ITimeFactory */
|
||||
protected $timeFactory;
|
||||
/** @var ParticipantService */
|
||||
protected $participantService;
|
||||
/** @var Config */
|
||||
protected $talkConfig;
|
||||
/** @var IUserManager */
|
||||
protected $userManager;
|
||||
/** @var string|null */
|
||||
protected $userId;
|
||||
|
||||
public function __construct(string $appName,
|
||||
IRequest $request,
|
||||
ITimeFactory $timeFactory,
|
||||
ParticipantService $participantService,
|
||||
Config $talkConfig,
|
||||
IUserManager $userManager,
|
||||
?string $userId) {
|
||||
parent::__construct($appName, $request);
|
||||
$this->timeFactory = $timeFactory;
|
||||
$this->participantService = $participantService;
|
||||
$this->talkConfig = $talkConfig;
|
||||
$this->userManager = $userManager;
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @RequireModeratorParticipant
|
||||
*
|
||||
* @param int $state
|
||||
* @param int|null $timer
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function setLobby(int $state, ?int $timer = null): DataResponse {
|
||||
$timerDateTime = null;
|
||||
if ($timer !== null && $timer > 0) {
|
||||
try {
|
||||
$timerDateTime = $this->timeFactory->getDateTime('@' . $timer);
|
||||
$timerDateTime->setTimezone(new \DateTimeZone('UTC'));
|
||||
} catch (\Exception $e) {
|
||||
return new DataResponse([], Http::STATUS_BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->room->setLobby($state, $timerDateTime)) {
|
||||
return new DataResponse([], Http::STATUS_BAD_REQUEST);
|
||||
}
|
||||
|
||||
if ($state === Webinary::LOBBY_NON_MODERATORS) {
|
||||
$participants = $this->participantService->getParticipantsInCall($this->room);
|
||||
foreach ($participants as $participant) {
|
||||
if ($participant->hasModeratorPermissions()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->participantService->changeInCall($this->room, $participant, Participant::FLAG_DISCONNECTED);
|
||||
}
|
||||
}
|
||||
|
||||
return new DataResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @RequireModeratorParticipant
|
||||
*
|
||||
* @param int $state
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function setSIPEnabled(int $state): DataResponse {
|
||||
$user = $this->userManager->get($this->userId);
|
||||
if (!$user instanceof IUser) {
|
||||
return new DataResponse([], Http::STATUS_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
if (!$this->talkConfig->canUserEnableSIP($user)) {
|
||||
return new DataResponse([], Http::STATUS_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
if (!$this->talkConfig->isSIPConfigured()) {
|
||||
return new DataResponse([], Http::STATUS_PRECONDITION_FAILED);
|
||||
}
|
||||
|
||||
if (!$this->room->setSIPEnabled($state)) {
|
||||
return new DataResponse([], Http::STATUS_BAD_REQUEST);
|
||||
}
|
||||
|
||||
return new DataResponse();
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче