Changeset View
Changeset View
Standalone View
Standalone View
src/app/OpenVidu/Room.php
Show First 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | public function deleteSession(): bool | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
/** | /** | ||||
* Create a OpenVidu session (connection) token | * Create a OpenVidu session (connection) token | ||||
* | * | ||||
* @param string $role User role | |||||
* @param array $data User data to attach to the connection. | |||||
* It will be available client-side for everybody. | |||||
* | |||||
* @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 | * @throws \Exception if session does not exist | ||||
*/ | */ | ||||
public function getSessionToken($role = self::ROLE_PUBLISHER): ?array | public function getSessionToken($role = self::ROLE_PUBLISHER, $data = []): ?array | ||||
{ | { | ||||
if (!$this->session_id) { | if (!$this->session_id) { | ||||
throw new \Exception("The room session does not exist"); | throw new \Exception("The room session does not exist"); | ||||
} | } | ||||
// FIXME: Looks like passing the role in 'data' param is the only way | |||||
// to make it visible for everyone in a room. So, for example we can | |||||
// handle/style subscribers/publishers/moderators differently on the | |||||
// client-side. Is this a security issue? | |||||
if (!empty($data)) { | |||||
$data += ['role' => $role]; | |||||
} else { | |||||
$data = ['role' => $role]; | |||||
} | |||||
$url = 'sessions/' . $this->session_id . '/connection'; | $url = 'sessions/' . $this->session_id . '/connection'; | ||||
$post = [ | $post = [ | ||||
'json' => [ | 'json' => [ | ||||
'role' => $role | 'role' => $role, | ||||
'data' => json_encode($data) | |||||
] | ] | ||||
]; | ]; | ||||
$response = $this->client()->request('POST', $url, $post); | $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); | ||||
▲ Show 20 Lines • Show All 177 Lines • Show Last 20 Lines |