Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/V4/OpenViduController.php
Show First 20 Lines • Show All 191 Lines • ▼ Show 20 Lines | public function joinRoom($id) | ||||
// Check if there's still a valid beta entitlement for the room owner | // Check if there's still a valid beta entitlement for the room owner | ||||
$sku = \App\Sku::where('title', 'meet')->first(); | $sku = \App\Sku::where('title', 'meet')->first(); | ||||
if ($sku && !$room->owner->entitlements()->where('sku_id', $sku->id)->first()) { | if ($sku && !$room->owner->entitlements()->where('sku_id', $sku->id)->first()) { | ||||
return $this->errorResponse(404, \trans('meet.room-not-found')); | return $this->errorResponse(404, \trans('meet.room-not-found')); | ||||
} | } | ||||
$user = Auth::guard()->user(); | $user = Auth::guard()->user(); | ||||
$isOwner = $user && $user->id == $room->user_id; | $isOwner = $user && $user->id == $room->user_id; | ||||
$init = !empty(request()->input('init')); | |||||
// 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(422, \trans('meet.session-not-found'), ['code' => 323]); | 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 (!$init) { | ||||
return $this->errorResponse(422, \trans('meet.session-not-found'), ['code' => 324]); | 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')); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | public function joinRoom($id) | ||||
// 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(422, $error, $response + ['code' => 327]); | return $this->errorResponse(422, $error, $response + ['code' => 327]); | ||||
} | } | ||||
} | } | ||||
// Initialize connection tokens | |||||
if ($init) { | |||||
// Choose the connection role | |||||
if ($isOwner) { | |||||
$role = Room::ROLE_MODERATOR; | |||||
} elseif (request()->input('role') === Room::ROLE_PUBLISHER) { | |||||
$role = Room::ROLE_PUBLISHER; | |||||
} else { | |||||
$role = Room::ROLE_SUBSCRIBER; | |||||
} | |||||
// 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($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 | // Create session token for screen sharing connection | ||||
if (!empty(request()->input('screenShare'))) { | if ($role != Room::ROLE_SUBSCRIBER && !empty(request()->input('screenShare'))) { | ||||
$add_token = $room->getSessionToken(Room::ROLE_PUBLISHER); | $add_token = $room->getSessionToken(Room::ROLE_PUBLISHER); | ||||
$response['shareToken'] = $add_token['token']; | $response['shareToken'] = $add_token['token']; | ||||
} | } | ||||
// Tell the UI who's the room owner | $response_code = 200; | ||||
$response['role'] = $role; | |||||
$response['owner'] = $isOwner; | $response['owner'] = $isOwner; | ||||
// Append the room configuration | |||||
$response['config'] = $config; | $response['config'] = $config; | ||||
} else { | |||||
$response_code = 422; | |||||
$response['code'] = 322; | |||||
} | |||||
return response()->json($response); | return response()->json($response, $response_code); | ||||
} | } | ||||
/** | /** | ||||
* Set the domain configuration. | * Set the domain configuration. | ||||
* | * | ||||
* @param string $id Room identifier (name) | * @param string $id Room identifier (name) | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse|void | * @return \Illuminate\Http\JsonResponse|void | ||||
▲ Show 20 Lines • Show All 82 Lines • Show Last 20 Lines |