Changeset View
Changeset View
Standalone View
Standalone View
src/app/OpenVidu/Room.php
Show First 20 Lines • Show All 164 Lines • ▼ Show 20 Lines | public function deleteSession(): bool | ||||
return false; | return false; | ||||
} | } | ||||
/** | /** | ||||
* Create a OpenVidu session (connection) token | * Create a OpenVidu session (connection) token | ||||
* | * | ||||
* @return array|null Token data on success, NULL otherwise | * @return array|null Token data on success, NULL otherwise | ||||
* @throws \Exception if session does not exist | |||||
*/ | */ | ||||
public function getSessionToken($role = self::ROLE_PUBLISHER): ?array | public function getSessionToken($role = self::ROLE_PUBLISHER): ?array | ||||
{ | { | ||||
$response = $this->client()->request( | if (!$this->session_id) { | ||||
'POST', | throw new \Exception("The room session does not exist"); | ||||
'tokens', | } | ||||
[ | |||||
$url = 'sessions/' . $this->session_id . '/connection'; | |||||
$post = [ | |||||
'json' => [ | 'json' => [ | ||||
'session' => $this->session_id, | |||||
'role' => $role | 'role' => $role | ||||
] | ] | ||||
] | ]; | ||||
); | |||||
$response = $this->client()->request('POST', $url, $post); | |||||
if ($response->getStatusCode() == 200) { | if ($response->getStatusCode() == 200) { | ||||
$json = json_decode($response->getBody(), true); | $json = json_decode($response->getBody(), true); | ||||
return $json; | return [ | ||||
'session' => $this->session_id, | |||||
'token' => $json['token'], | |||||
'role' => $json['role'], | |||||
'connectionId' => $json['id'], | |||||
]; | |||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
/** | /** | ||||
* Check if the room has an active session | * Check if the room has an active session | ||||
* | * | ||||
▲ Show 20 Lines • Show All 163 Lines • Show Last 20 Lines |