Browse Source

Add endpoint to add a user to a call

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/81/head
Joas Schilling 9 years ago
parent
commit
ff39859bc1
No known key found for this signature in database GPG Key ID: E166FD8976B3BAC8
  1. 5
      appinfo/routes.php
  2. 44
      lib/Controller/ApiController.php

5
appinfo/routes.php

@ -48,6 +48,11 @@ return [
'url' => '/api/room',
'verb' => 'GET',
],
[
'name' => 'api#addParticipantToRoom',
'url' => '/api/room/{roomId}',
'verb' => 'POST',
],
[
'name' => 'api#leaveRoom',
'url' => '/api/room/{roomId}',

44
lib/Controller/ApiController.php

@ -277,6 +277,50 @@ class ApiController extends Controller {
return new JSONResponse(['roomId' => $room->getId()], Http::STATUS_CREATED);
}
/**
* @NoAdminRequired
*
* @param int $roomId
* @param string $newParticipant
* @return JSONResponse
*/
public function addParticipantToRoom($roomId, $newParticipant) {
try {
$room = $this->manager->getRoomById($roomId);
} catch (RoomNotFoundException $e) {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
}
$participants = $room->getParticipants();
if (!isset($participants[$this->userId])) {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
}
if (isset($participants[$newParticipant])) {
return new JSONResponse([]);
}
$newUser = $this->userManager->get($newParticipant);
if (!$newUser instanceof IUser) {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
}
if ($room->getType() === Room::ONE_TO_ONE_CALL) {
// In case a user is added to a one2one call, we create a new group call and add the participants manually
$room = $this->manager->createRoom(Room::GROUP_CALL, $this->secureRandom->generate(12));
foreach ($participants as $participant => $lastPing) {
$user = $this->userManager->get($participant);
if ($user instanceof IUser) {
$room->addUser($user);
}
}
return new JSONResponse(['roomId' => $room->getId()], Http::STATUS_CREATED);
}
$room->addUser($newUser);
return new JSONResponse([]);
}
/**
* @NoAdminRequired
*

Loading…
Cancel
Save