Changeset View
Changeset View
Standalone View
Standalone View
src/app/OpenVidu/Room.php
Show First 20 Lines • Show All 224 Lines • ▼ Show 20 Lines | public function getSessionToken($role = self::ROLE_SUBSCRIBER): ?array | ||||
] | ] | ||||
]; | ]; | ||||
$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); | ||||
$authToken = base64_encode($json['id'] . ':' . \random_bytes(16)); | |||||
// Extract the 'token' part of the token, it will be used to authenticate the connection. | // Extract the 'token' part of the token, it will be used to authenticate the connection. | ||||
// It will be needed in next iterations e.g. to authenticate moderators that aren't | // It will be needed in next iterations e.g. to authenticate moderators that aren't | ||||
// Kolab4 users (or are just not logged in to Kolab4). | // Kolab4 users (or are just not logged in to Kolab4). | ||||
// FIXME: we could as well generate our own token for auth purposes | // FIXME: we could as well generate our own token for auth purposes | ||||
parse_str(parse_url($json['token'], PHP_URL_QUERY), $url); | parse_str(parse_url($json['token'], PHP_URL_QUERY), $url); | ||||
// Create the connection reference in our database | // Create the connection reference in our database | ||||
$conn = new Connection(); | $conn = new Connection(); | ||||
$conn->id = $json['id']; | $conn->id = $json['id']; | ||||
$conn->session_id = $this->session_id; | $conn->session_id = $this->session_id; | ||||
$conn->room_id = $this->id; | $conn->room_id = $this->id; | ||||
$conn->role = $role; | $conn->role = $role; | ||||
$conn->metadata = ['token' => $url['token']]; | $conn->metadata = ['token' => $url['token'], 'authToken' => $authToken]; | ||||
$conn->save(); | $conn->save(); | ||||
return [ | return [ | ||||
'session' => $this->session_id, | 'session' => $this->session_id, | ||||
'token' => $json['token'], | 'token' => $json['token'], | ||||
'authToken' => $authToken, | |||||
'connectionId' => $json['id'], | 'connectionId' => $json['id'], | ||||
'role' => $role, | 'role' => $role, | ||||
]; | ]; | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 151 Lines • Show Last 20 Lines |