Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/V4/OpenViduController.php
<?php | <?php | ||||
namespace App\Http\Controllers\API\V4; | namespace App\Http\Controllers\API\V4; | ||||
use App\Http\Controllers\Controller; | use App\Http\Controllers\Controller; | ||||
use App\OpenVidu\Connection; | use App\OpenVidu\Connection; | ||||
use App\OpenVidu\Room; | use App\OpenVidu\Room; | ||||
use Illuminate\Http\Request; | use Illuminate\Http\Request; | ||||
use Illuminate\Support\Facades\Auth; | use Illuminate\Support\Facades\Auth; | ||||
use Illuminate\Support\Facades\Validator; | use Illuminate\Support\Facades\Validator; | ||||
class OpenViduController extends Controller | class OpenViduController extends Controller | ||||
{ | { | ||||
/** | /** | ||||
* Accepting the room join request. | * Accept the room join request. | ||||
* | * | ||||
* @param string $id Room identifier (name) | * @param string $id Room identifier (name) | ||||
* @param string $reqid Request identifier | * @param string $reqid Request identifier | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse | * @return \Illuminate\Http\JsonResponse | ||||
*/ | */ | ||||
public function acceptJoinRequest($id, $reqid) | public function acceptJoinRequest($id, $reqid) | ||||
{ | { | ||||
$room = Room::where('name', $id)->first(); | $room = Room::where('name', $id)->first(); | ||||
// This isn't a room, bye bye | // This isn't a room, bye bye | ||||
if (!$room) { | if (!$room) { | ||||
return $this->errorResponse(404, \trans('meet.room-not-found')); | return $this->errorResponse(404, \trans('meet.room-not-found')); | ||||
} | } | ||||
$user = Auth::guard()->user(); | // Only the moderator can do it | ||||
if (!$this->isModerator($room)) { | |||||
// Only the room owner can do it | |||||
if (!$user || $user->id != $room->user_id) { | |||||
return $this->errorResponse(403); | return $this->errorResponse(403); | ||||
} | } | ||||
if (!$room->requestAccept($reqid)) { | if (!$room->requestAccept($reqid)) { | ||||
return $this->errorResponse(500, \trans('meet.session-request-accept-error')); | return $this->errorResponse(500, \trans('meet.session-request-accept-error')); | ||||
} | } | ||||
return response()->json(['status' => 'success']); | return response()->json(['status' => 'success']); | ||||
} | } | ||||
/** | /** | ||||
* Denying the room join request. | * Deny the room join request. | ||||
* | * | ||||
* @param string $id Room identifier (name) | * @param string $id Room identifier (name) | ||||
* @param string $reqid Request identifier | * @param string $reqid Request identifier | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse | * @return \Illuminate\Http\JsonResponse | ||||
*/ | */ | ||||
public function denyJoinRequest($id, $reqid) | public function denyJoinRequest($id, $reqid) | ||||
{ | { | ||||
$room = Room::where('name', $id)->first(); | $room = Room::where('name', $id)->first(); | ||||
// This isn't a room, bye bye | // This isn't a room, bye bye | ||||
if (!$room) { | if (!$room) { | ||||
return $this->errorResponse(404, \trans('meet.room-not-found')); | return $this->errorResponse(404, \trans('meet.room-not-found')); | ||||
} | } | ||||
$user = Auth::guard()->user(); | // Only the moderator can do it | ||||
if (!$this->isModerator($room)) { | |||||
// Only the room owner can do it | |||||
if (!$user || $user->id != $room->user_id) { | |||||
return $this->errorResponse(403); | return $this->errorResponse(403); | ||||
} | } | ||||
if (!$room->requestDeny($reqid)) { | if (!$room->requestDeny($reqid)) { | ||||
return $this->errorResponse(500, \trans('meet.session-request-deny-error')); | return $this->errorResponse(500, \trans('meet.session-request-deny-error')); | ||||
} | } | ||||
return response()->json(['status' => 'success']); | return response()->json(['status' => 'success']); | ||||
Show All 28 Lines | public function closeRoom($id) | ||||
return response()->json([ | return response()->json([ | ||||
'status' => 'success', | 'status' => 'success', | ||||
'message' => __('meet.session-close-success'), | 'message' => __('meet.session-close-success'), | ||||
]); | ]); | ||||
} | } | ||||
/** | /** | ||||
* Accepting the room join request. | * Dismiss the participant/connection from the session. | ||||
* | * | ||||
* @param string $id Room identifier (name) | * @param string $id Room identifier (name) | ||||
* @param string $conn Connection identifier | * @param string $conn Connection identifier | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse | * @return \Illuminate\Http\JsonResponse | ||||
*/ | */ | ||||
public function dismissConnection($id, $conn) | public function dismissConnection($id, $conn) | ||||
{ | { | ||||
$connection = Connection::where('id', $conn)->first(); | $connection = Connection::where('id', $conn)->first(); | ||||
// There's no such connection, bye bye | // There's no such connection, bye bye | ||||
if (!$connection || $connection->room->name != $id) { | if (!$connection || $connection->room->name != $id) { | ||||
return $this->errorResponse(404, \trans('meet.connection-not-found')); | return $this->errorResponse(404, \trans('meet.connection-not-found')); | ||||
} | } | ||||
$user = Auth::guard()->user(); | // Only the moderator can do it | ||||
if (!$this->isModerator($connection->room)) { | |||||
// Only the room owner can do it (for now) | |||||
if (!$user || $user->id != $connection->room->user_id) { | |||||
return $this->errorResponse(403); | return $this->errorResponse(403); | ||||
} | } | ||||
if (!$connection->dismiss()) { | if (!$connection->dismiss()) { | ||||
return $this->errorResponse(500, \trans('meet.connection-dismiss-error')); | return $this->errorResponse(500, \trans('meet.connection-dismiss-error')); | ||||
} | } | ||||
return response()->json(['status' => 'success']); | return response()->json(['status' => 'success']); | ||||
▲ Show 20 Lines • Show All 230 Lines • ▼ Show 20 Lines | public function setRoomConfig($id) | ||||
return response()->json([ | return response()->json([ | ||||
'status' => 'success', | 'status' => 'success', | ||||
'message' => \trans('meet.room-setconfig-success'), | 'message' => \trans('meet.room-setconfig-success'), | ||||
]); | ]); | ||||
} | } | ||||
/** | /** | ||||
* Update the participant/connection parameters (e.g. role). | |||||
* | |||||
* @param string $id Room identifier (name) | |||||
* @param string $conn Connection identifier | |||||
* | |||||
* @return \Illuminate\Http\JsonResponse | |||||
*/ | |||||
public function updateConnection($id, $conn) | |||||
{ | |||||
$connection = Connection::where('id', $conn)->first(); | |||||
// There's no such connection, bye bye | |||||
if (!$connection || $connection->room->name != $id) { | |||||
return $this->errorResponse(404, \trans('meet.connection-not-found')); | |||||
} | |||||
// Only the moderator can do it | |||||
if (!$this->isModerator($connection->room)) { | |||||
return $this->errorResponse(403); | |||||
} | |||||
foreach (request()->input() as $key => $value) { | |||||
switch ($key) { | |||||
case 'role': | |||||
$connection->{$key} = $value; | |||||
break; | |||||
} | |||||
} | |||||
// The connection observer will send a signal to everyone when needed | |||||
$connection->save(); | |||||
return response()->json(['status' => 'success']); | |||||
} | |||||
/** | |||||
* Webhook as triggered from OpenVidu server | * Webhook as triggered from OpenVidu server | ||||
* | * | ||||
* @param \Illuminate\Http\Request $request The API request. | * @param \Illuminate\Http\Request $request The API request. | ||||
* | * | ||||
* @return \Illuminate\Http\Response The response | * @return \Illuminate\Http\Response The response | ||||
*/ | */ | ||||
public function webhook(Request $request) | public function webhook(Request $request) | ||||
{ | { | ||||
Show All 17 Lines | public function webhook(Request $request) | ||||
// So, it is better to remove them all in a single INSERT. | // So, it is better to remove them all in a single INSERT. | ||||
Connection::where('session_id', $sessionId)->delete(); | Connection::where('session_id', $sessionId)->delete(); | ||||
break; | break; | ||||
} | } | ||||
return response('Success', 200); | return response('Success', 200); | ||||
} | } | ||||
/** | |||||
* Check if current user is a moderator for the specified room. | |||||
* | |||||
* @param \App\OpenVidu\Room $room The room | |||||
* | |||||
* @return bool True if the current user is the room moderator | |||||
*/ | |||||
protected function isModerator(Room $room): bool | |||||
{ | |||||
$user = Auth::guard()->user(); | |||||
// The room owner is a moderator | |||||
if ($user && $user->id == $room->user_id) { | |||||
return true; | |||||
} | |||||
// TODO: Moderators authentication | |||||
return false; | |||||
} | |||||
} | } |