Fix auto-record egress failing before LiveKit room exists.
Deploy Ladill Meet / deploy (push) Successful in 51s
Deploy Ladill Meet / deploy (push) Successful in 51s
Create rooms via the LiveKit API, retry egress when the room is missing, and resume server egress after the host connects when auto-record fell back to browser capture. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -26,14 +26,7 @@ class LiveKitEgressService
|
||||
|
||||
public function apiHost(): string
|
||||
{
|
||||
$override = (string) config('meet.media.livekit.api_url', '');
|
||||
if ($override !== '') {
|
||||
return rtrim($override, '/');
|
||||
}
|
||||
|
||||
$url = (string) config('meet.media.livekit.url', '');
|
||||
|
||||
return (string) preg_replace('#^wss:#', 'https:', (string) preg_replace('#^ws:#', 'http:', $url));
|
||||
return app(LiveKitProvider::class)->apiHost();
|
||||
}
|
||||
|
||||
public function startRoomRecording(Session $session, Recording $recording, bool $audioOnly = false): EgressInfo
|
||||
@@ -54,6 +47,33 @@ class LiveKitEgressService
|
||||
);
|
||||
}
|
||||
|
||||
protected function startRoomRecordingWithRetry(Session $session, Recording $recording, bool $audioOnly): EgressInfo
|
||||
{
|
||||
$attempts = max(1, (int) config('meet.recordings.egress.start_attempts', 5));
|
||||
$lastError = null;
|
||||
|
||||
for ($attempt = 1; $attempt <= $attempts; $attempt++) {
|
||||
try {
|
||||
return $this->startRoomRecording($session, $recording, $audioOnly);
|
||||
} catch (\Throwable $e) {
|
||||
$lastError = $e;
|
||||
if (! $this->isMissingRoomError($e) || $attempt === $attempts) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
app(LiveKitProvider::class)->createRoom($session->media_room_name);
|
||||
usleep(500_000);
|
||||
}
|
||||
}
|
||||
|
||||
throw $lastError ?? new RuntimeException('LiveKit egress could not start.');
|
||||
}
|
||||
|
||||
protected function isMissingRoomError(\Throwable $e): bool
|
||||
{
|
||||
return str_contains(strtolower($e->getMessage()), 'room does not exist');
|
||||
}
|
||||
|
||||
public function stopEgress(string $egressId): EgressInfo
|
||||
{
|
||||
return $this->client()->stopEgress($egressId);
|
||||
@@ -146,7 +166,7 @@ class LiveKitEgressService
|
||||
|
||||
try {
|
||||
$audioOnly = $session->room->isAudioOnly();
|
||||
$info = $this->startRoomRecording($session, $recording, $audioOnly);
|
||||
$info = $this->startRoomRecordingWithRetry($session, $recording, $audioOnly);
|
||||
$egressId = $info->getEgressId();
|
||||
|
||||
if ($egressId === '') {
|
||||
|
||||
@@ -4,18 +4,58 @@ namespace App\Services\Meet\Media;
|
||||
|
||||
use Agence104\LiveKit\AccessToken;
|
||||
use Agence104\LiveKit\AccessTokenOptions;
|
||||
use Agence104\LiveKit\RoomCreateOptions;
|
||||
use Agence104\LiveKit\RoomServiceClient;
|
||||
use Agence104\LiveKit\VideoGrant;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class LiveKitProvider implements MediaProviderInterface
|
||||
{
|
||||
public function createRoom(string $roomName, array $options = []): void
|
||||
{
|
||||
// LiveKit creates rooms lazily on first join.
|
||||
if (! $this->isConfigured()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$client = new RoomServiceClient(
|
||||
$this->apiHost(),
|
||||
(string) config('meet.media.livekit.api_key'),
|
||||
(string) config('meet.media.livekit.api_secret'),
|
||||
);
|
||||
|
||||
$client->createRoom(new RoomCreateOptions([
|
||||
'name' => $roomName,
|
||||
'empty_timeout' => (int) ($options['empty_timeout'] ?? 300),
|
||||
]));
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('LiveKit createRoom failed.', [
|
||||
'room' => $roomName,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteRoom(string $roomName): void
|
||||
{
|
||||
//
|
||||
if (! $this->isConfigured() || $roomName === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$client = new RoomServiceClient(
|
||||
$this->apiHost(),
|
||||
(string) config('meet.media.livekit.api_key'),
|
||||
(string) config('meet.media.livekit.api_secret'),
|
||||
);
|
||||
|
||||
$client->deleteRoom($roomName);
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('LiveKit deleteRoom failed.', [
|
||||
'room' => $roomName,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function generateToken(
|
||||
@@ -60,4 +100,16 @@ class LiveKitProvider implements MediaProviderInterface
|
||||
{
|
||||
return (string) config('meet.media.livekit.url');
|
||||
}
|
||||
|
||||
public function apiHost(): string
|
||||
{
|
||||
$override = (string) config('meet.media.livekit.api_url', '');
|
||||
if ($override !== '') {
|
||||
return rtrim($override, '/');
|
||||
}
|
||||
|
||||
$url = (string) config('meet.media.livekit.url', '');
|
||||
|
||||
return (string) preg_replace('#^wss:#', 'https:', (string) preg_replace('#^ws:#', 'http:', $url));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ class RecordingService
|
||||
{
|
||||
$active = $session->recordings()->where('status', 'recording')->first();
|
||||
if ($active) {
|
||||
return $active;
|
||||
return $this->ensureServerEgress($session, $active);
|
||||
}
|
||||
|
||||
$recording = Recording::create([
|
||||
@@ -66,6 +66,24 @@ class RecordingService
|
||||
return $this->captureMode($recording) === 'egress';
|
||||
}
|
||||
|
||||
public function ensureServerEgress(Session $session, Recording $recording): Recording
|
||||
{
|
||||
if ($this->usesServerEgress($recording) || ! $this->egress->isAvailable()) {
|
||||
return $recording;
|
||||
}
|
||||
|
||||
$egressMeta = $this->egress->tryStart($session, $recording);
|
||||
if ($egressMeta === null) {
|
||||
return $recording;
|
||||
}
|
||||
|
||||
$recording->update([
|
||||
'metadata' => array_merge($recording->metadata ?? [], $egressMeta),
|
||||
]);
|
||||
|
||||
return $recording->fresh();
|
||||
}
|
||||
|
||||
public function stop(Recording $recording, string $actorRef): Recording
|
||||
{
|
||||
if ($recording->status !== 'recording') {
|
||||
|
||||
Reference in New Issue
Block a user