Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/V4/OpenViduController.php
Show First 20 Lines • Show All 196 Lines • ▼ Show 20 Lines | public function joinRoom($id) | ||||
$user = Auth::guard()->user(); | $user = Auth::guard()->user(); | ||||
$isOwner = $user && $user->id == $room->user_id; | $isOwner = $user && $user->id == $room->user_id; | ||||
// There's no existing session | // There's no existing session | ||||
if (!$room->hasSession()) { | if (!$room->hasSession()) { | ||||
// Participants can't join the room until the session is created by the owner | // Participants can't join the room until the session is created by the owner | ||||
if (!$isOwner) { | if (!$isOwner) { | ||||
return $this->errorResponse(423, \trans('meet.session-not-found')); | return $this->errorResponse(422, \trans('meet.session-not-found'), ['code' => 323]); | ||||
} | } | ||||
// The room owner can create the session on request | // The room owner can create the session on request | ||||
if (empty(request()->input('init'))) { | if (empty(request()->input('init'))) { | ||||
return $this->errorResponse(424, \trans('meet.session-not-found')); | return $this->errorResponse(422, \trans('meet.session-not-found'), ['code' => 324]); | ||||
} | } | ||||
$session = $room->createSession(); | $session = $room->createSession(); | ||||
if (empty($session)) { | if (empty($session)) { | ||||
return $this->errorResponse(500, \trans('meet.session-create-error')); | return $this->errorResponse(500, \trans('meet.session-create-error')); | ||||
} | } | ||||
} | } | ||||
$password = (string) $room->getSetting('password'); | $password = (string) $room->getSetting('password'); | ||||
$config = [ | $config = [ | ||||
'locked' => $room->getSetting('locked') === 'true', | 'locked' => $room->getSetting('locked') === 'true', | ||||
'password' => $isOwner ? $password : '', | 'password' => $isOwner ? $password : '', | ||||
'requires_password' => !$isOwner && strlen($password), | 'requires_password' => !$isOwner && strlen($password), | ||||
]; | ]; | ||||
$response = ['config' => $config]; | |||||
// Validate room password | // Validate room password | ||||
if (!$isOwner && strlen($password)) { | if (!$isOwner && strlen($password)) { | ||||
$request_password = request()->input('password'); | $request_password = request()->input('password'); | ||||
if ($request_password !== $password) { | if ($request_password !== $password) { | ||||
return $this->errorResponse(425, \trans('meet.session-password-error'), ['config' => $config]); | return $this->errorResponse(422, \trans('meet.session-password-error'), $response + ['code' => 325]); | ||||
} | } | ||||
} | } | ||||
// Handle locked room | // Handle locked room | ||||
if (!$isOwner && $config['locked']) { | if (!$isOwner && $config['locked']) { | ||||
$nickname = request()->input('nickname'); | $nickname = request()->input('nickname'); | ||||
$picture = request()->input('picture'); | $picture = request()->input('picture'); | ||||
$requestId = request()->input('requestId'); | $requestId = request()->input('requestId'); | ||||
$request = $requestId ? $room->requestGet($requestId) : null; | $request = $requestId ? $room->requestGet($requestId) : null; | ||||
$error = \trans('meet.session-room-locked-error'); | $error = \trans('meet.session-room-locked-error'); | ||||
// Request already has been processed (not accepted yet, but it could be denied) | // Request already has been processed (not accepted yet, but it could be denied) | ||||
if (empty($request['status']) || $request['status'] != Room::REQUEST_ACCEPTED) { | if (empty($request['status']) || $request['status'] != Room::REQUEST_ACCEPTED) { | ||||
if (!$request) { | if (!$request) { | ||||
if (empty($nickname) || empty($requestId) || !preg_match('/^[a-z0-9]{8,32}$/i', $requestId)) { | if (empty($nickname) || empty($requestId) || !preg_match('/^[a-z0-9]{8,32}$/i', $requestId)) { | ||||
return $this->errorResponse(426, $error, ['config' => $config]); | return $this->errorResponse(422, $error, $response + ['code' => 326]); | ||||
} | } | ||||
if (empty($picture)) { | if (empty($picture)) { | ||||
$svg = file_get_contents(resource_path('images/user.svg')); | $svg = file_get_contents(resource_path('images/user.svg')); | ||||
$picture = 'data:image/svg+xml;base64,' . base64_encode($svg); | $picture = 'data:image/svg+xml;base64,' . base64_encode($svg); | ||||
} elseif (!preg_match('|^data:image/png;base64,[a-zA-Z0-9=+/]+$|', $picture)) { | } elseif (!preg_match('|^data:image/png;base64,[a-zA-Z0-9=+/]+$|', $picture)) { | ||||
return $this->errorResponse(426, $error, ['config' => $config]); | return $this->errorResponse(422, $error, $response + ['code' => 326]); | ||||
} | } | ||||
// TODO: Resize when big/make safe the user picture? | // TODO: Resize when big/make safe the user picture? | ||||
$request = ['nickname' => $nickname, 'requestId' => $requestId, 'picture' => $picture]; | $request = ['nickname' => $nickname, 'requestId' => $requestId, 'picture' => $picture]; | ||||
if (!$room->requestSave($requestId, $request)) { | if (!$room->requestSave($requestId, $request)) { | ||||
// FIXME: should we use error code 500? | // FIXME: should we use error code 500? | ||||
return $this->errorResponse(426, $error, ['config' => $config]); | return $this->errorResponse(422, $error, $response + ['code' => 326]); | ||||
} | } | ||||
// Send the request (signal) to the owner | // Send the request (signal) to the owner | ||||
$result = $room->signal('joinRequest', $request, Room::ROLE_MODERATOR); | $result = $room->signal('joinRequest', $request, Room::ROLE_MODERATOR); | ||||
} | } | ||||
return $this->errorResponse(427, $error, ['config' => $config]); | return $this->errorResponse(422, $error, $response + ['code' => 327]); | ||||
} | } | ||||
} | } | ||||
// Create session token for the current user/connection | // Create session token for the current user/connection | ||||
$response = $room->getSessionToken($isOwner ? Room::ROLE_MODERATOR : Room::ROLE_PUBLISHER); | $response = $room->getSessionToken($isOwner ? Room::ROLE_MODERATOR : Room::ROLE_PUBLISHER); | ||||
if (empty($response)) { | if (empty($response)) { | ||||
return $this->errorResponse(500, \trans('meet.session-join-error')); | return $this->errorResponse(500, \trans('meet.session-join-error')); | ||||
▲ Show 20 Lines • Show All 107 Lines • Show Last 20 Lines |