Files
ladill-meet/app/Services/Meet/Media/LiveKitProvider.php
T
isaaccladandCursor 965fb992e9
Deploy Ladill Meet / deploy (push) Failing after 7s
Initial Ladill Meet release.
Phases 0–18: core meetings, webinar, breakouts, team chat, live streaming, town hall, billing, and Ladill Mail calendar wiring.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-30 23:35:29 +00:00

78 lines
2.3 KiB
PHP

<?php
namespace App\Services\Meet\Media;
class LiveKitProvider implements MediaProviderInterface
{
public function createRoom(string $roomName, array $options = []): void
{
// LiveKit creates rooms lazily on first join.
}
public function deleteRoom(string $roomName): void
{
//
}
public function generateToken(
string $roomName,
string $identity,
string $displayName,
array $grants = [],
): string {
$apiKey = (string) config('meet.media.livekit.api_key');
$apiSecret = (string) config('meet.media.livekit.api_secret');
$now = time();
$payload = [
'iss' => $apiKey,
'sub' => $identity,
'iat' => $now,
'nbf' => $now,
'exp' => $now + 3600,
'name' => $displayName,
'video' => [
'roomJoin' => true,
'room' => $roomName,
'canPublish' => $grants['can_publish'] ?? true,
'canSubscribe' => $grants['can_subscribe'] ?? true,
'canPublishData' => $grants['can_publish_data'] ?? true,
'roomAdmin' => $grants['room_admin'] ?? false,
],
];
return $this->encodeJwt($payload, $apiSecret);
}
public function isConfigured(): bool
{
return filled(config('meet.media.livekit.url'))
&& filled(config('meet.media.livekit.api_key'))
&& filled(config('meet.media.livekit.api_secret'));
}
public function serverUrl(): string
{
return (string) config('meet.media.livekit.url');
}
/**
* @param array<string, mixed> $payload
*/
protected function encodeJwt(array $payload, string $secret): string
{
$header = $this->base64UrlEncode(json_encode(['alg' => 'HS256', 'typ' => 'JWT'], JSON_THROW_ON_ERROR));
$body = $this->base64UrlEncode(json_encode($payload, JSON_THROW_ON_ERROR));
$signature = $this->base64UrlEncode(
hash_hmac('sha256', "{$header}.{$body}", $secret, true)
);
return "{$header}.{$body}.{$signature}";
}
protected function base64UrlEncode(string $data): string
{
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
}