Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/V4/OpenViduController.php
Show First 20 Lines • Show All 99 Lines • ▼ Show 20 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'), | ||||
]); | ]); | ||||
} | } | ||||
/** | /** | ||||
* Create a connection for screen sharing. | |||||
* | |||||
* @param string $id Room identifier (name) | |||||
* | |||||
* @return \Illuminate\Http\JsonResponse | |||||
*/ | |||||
public function createConnection($id) | |||||
{ | |||||
$room = Room::where('name', $id)->first(); | |||||
// This isn't a room, bye bye | |||||
if (!$room) { | |||||
return $this->errorResponse(404, \trans('meet.room-not-found')); | |||||
} | |||||
$connection = $this->getConnectionFromRequest(); | |||||
if ( | |||||
!$connection | |||||
|| $connection->session_id != $room->session_id | |||||
|| ($connection->role & Room::ROLE_PUBLISHER) == 0 | |||||
) { | |||||
return $this->errorResponse(403); | |||||
} | |||||
$response = $room->getSessionToken(Room::ROLE_SCREEN); | |||||
return response()->json(['status' => 'success', 'token' => $response['token']]); | |||||
} | |||||
/** | |||||
* Dismiss the participant/connection from the session. | * 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) | ||||
Show All 13 Lines | public function dismissConnection($id, $conn) | ||||
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']); | ||||
} | } | ||||
/** | /** | ||||
* Listing of rooms that belong to the current user. | * Listing of rooms that belong to the authenticated user. | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse | * @return \Illuminate\Http\JsonResponse | ||||
*/ | */ | ||||
public function index() | public function index() | ||||
{ | { | ||||
$user = Auth::guard()->user(); | $user = Auth::guard()->user(); | ||||
$rooms = Room::where('user_id', $user->id)->orderBy('name')->get(); | $rooms = Room::where('user_id', $user->id)->orderBy('name')->get(); | ||||
▲ Show 20 Lines • Show All 140 Lines • ▼ Show 20 Lines | public function joinRoom($id) | ||||
// Create session token for the current user/connection | // Create session token for the current user/connection | ||||
$response = $room->getSessionToken($role); | $response = $room->getSessionToken($role); | ||||
if (empty($response)) { | if (empty($response)) { | ||||
return $this->errorResponse(500, \trans('meet.session-join-error')); | return $this->errorResponse(500, \trans('meet.session-join-error')); | ||||
} | } | ||||
// Create session token for screen sharing connection | |||||
if (($role & Room::ROLE_PUBLISHER) && !empty(request()->input('screenShare'))) { | |||||
$add_token = $room->getSessionToken(Room::ROLE_SCREEN); | |||||
$response['shareToken'] = $add_token['token']; | |||||
} | |||||
// Get up-to-date connections metadata | // Get up-to-date connections metadata | ||||
$response['connections'] = $room->getSessionConnections(); | $response['connections'] = $room->getSessionConnections(); | ||||
$response_code = 200; | $response_code = 200; | ||||
$response['role'] = $role; | $response['role'] = $role; | ||||
$response['config'] = $config; | $response['config'] = $config; | ||||
} else { | } else { | ||||
$response_code = 422; | $response_code = 422; | ||||
▲ Show 20 Lines • Show All 157 Lines • ▼ Show 20 Lines | protected function isModerator(Room $room): bool | ||||
$user = Auth::guard()->user(); | $user = Auth::guard()->user(); | ||||
// The room owner is a moderator | // The room owner is a moderator | ||||
if ($user && $user->id == $room->user_id) { | if ($user && $user->id == $room->user_id) { | ||||
return true; | return true; | ||||
} | } | ||||
// Moderator's authentication via the extra request header | // Moderator's authentication via the extra request header | ||||
if ( | |||||
($connection = $this->getConnectionFromRequest()) | |||||
&& $connection->session_id === $room->session_id | |||||
&& $connection->role & Room::ROLE_MODERATOR | |||||
) { | |||||
return true; | |||||
} | |||||
return false; | |||||
} | |||||
/** | |||||
* Get the connection object for the token in current request headers. | |||||
* It will also validate the token. | |||||
* | |||||
* @return \App\OpenVidu\Connection|null Connection (if exists and the token is valid) | |||||
*/ | |||||
protected function getConnectionFromRequest() | |||||
{ | |||||
// Authenticate the user via the extra request header | |||||
if ($token = request()->header(self::AUTH_HEADER)) { | if ($token = request()->header(self::AUTH_HEADER)) { | ||||
list($connId, ) = explode(':', base64_decode($token), 2); | list($connId, ) = explode(':', base64_decode($token), 2); | ||||
if ( | if ( | ||||
($connection = Connection::find($connId)) | ($connection = Connection::find($connId)) | ||||
&& $connection->session_id === $room->session_id | |||||
&& $connection->metadata['authToken'] === $token | && $connection->metadata['authToken'] === $token | ||||
&& $connection->role & Room::ROLE_MODERATOR | |||||
) { | ) { | ||||
return true; | return $connection; | ||||
} | } | ||||
} | } | ||||
return false; | return null; | ||||
} | } | ||||
} | } |