Record meetings with LiveKit Egress instead of browser capture.
Deploy Ladill Meet / deploy (push) Successful in 52s

Server-side room composite egress replaces fragile MediaRecorder DOM capture when enabled, with webhook completion and browser fallback when egress is unavailable.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-04 03:18:28 +00:00
co-authored by Cursor
parent c2cb9cf33a
commit 4e4bed0df3
10 changed files with 674 additions and 10 deletions
+133 -8
View File
@@ -5,12 +5,20 @@ namespace App\Services\Meet;
use App\Models\Recording;
use App\Models\Session;
use App\Models\User;
use App\Services\Meet\Media\LiveKitEgressService;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Livekit\EgressInfo;
use Livekit\EgressStatus;
use Livekit\FileInfo;
use RuntimeException;
class RecordingService
{
public function __construct(
protected LiveKitEgressService $egress,
) {}
public function start(Session $session, User $host, string $layout = 'gallery'): Recording
{
$active = $session->recordings()->where('status', 'recording')->first();
@@ -27,6 +35,15 @@ class RecordingService
'started_at' => now(),
]);
$egressMeta = $this->egress->tryStart($session, $recording);
if ($egressMeta !== null) {
$recording->update(['metadata' => $egressMeta]);
$recording = $recording->fresh();
} else {
$recording->update(['metadata' => ['capture_mode' => 'browser']]);
$recording = $recording->fresh();
}
AuditLogger::record(
$session->owner_ref,
'recording.started',
@@ -39,12 +56,26 @@ class RecordingService
return $recording;
}
public function captureMode(Recording $recording): string
{
return (string) ($recording->metadata['capture_mode'] ?? 'browser');
}
public function usesServerEgress(Recording $recording): bool
{
return $this->captureMode($recording) === 'egress';
}
public function stop(Recording $recording, string $actorRef): Recording
{
if ($recording->status !== 'recording') {
return $recording;
}
if ($this->usesServerEgress($recording)) {
$this->egress->tryStop($recording->metadata['egress_id'] ?? null);
}
$recording->update([
'status' => 'processing',
'ended_at' => now(),
@@ -65,6 +96,73 @@ class RecordingService
return $recording->fresh();
}
public function completeFromEgress(Recording $recording, EgressInfo $info): Recording
{
if (! in_array($recording->status, ['recording', 'processing'], true)) {
return $recording;
}
$status = $info->getStatus();
if (in_array($status, [EgressStatus::EGRESS_FAILED, EgressStatus::EGRESS_ABORTED, EgressStatus::EGRESS_LIMIT_REACHED], true)) {
return $this->fail(
$recording,
filled($info->getError()) ? $info->getError() : 'LiveKit recording failed.',
);
}
if ($status !== EgressStatus::EGRESS_COMPLETE) {
return $recording;
}
$file = $this->firstEgressFile($info);
if ($file === null) {
return $this->fail($recording, 'LiveKit recording finished without a file.');
}
$storagePath = (string) ($recording->metadata['egress_filepath'] ?? $file->getFilename());
$size = (int) $file->getSize();
if ($size <= 0) {
return $this->fail($recording, 'LiveKit recording file is empty.');
}
$durationSeconds = $this->durationSecondsFromFile($file, $recording);
$recording->update([
'status' => 'ready',
'storage_path' => $storagePath,
'file_size' => $size,
'ended_at' => $recording->ended_at ?? now(),
'duration_seconds' => $durationSeconds,
'metadata' => array_merge($recording->metadata ?? [], [
'egress_location' => $file->getLocation(),
]),
]);
$recording = $recording->fresh();
$session = $recording->session;
AuditLogger::record(
$recording->owner_ref,
'recording.ready',
$session->room->organization_id,
null,
Recording::class,
$recording->id,
);
app(MeetNotificationService::class)->recordingReady($recording);
app(\App\Services\Integrations\WebhookDispatcher::class)->recordingReady($recording);
app(MeetBillingService::class)->chargeRecordingStorageInitial($recording);
if ($session->room->setting('auto_ai_summary', false) || config('meet.ai.auto_summarize', true)) {
app(TranscriptService::class)->ensureForSession($session, $recording);
}
return $recording->fresh();
}
/** Store a browser-captured recording on Ladill storage (not LiveKit). */
public function storeUpload(Recording $recording, UploadedFile $file): Recording
{
@@ -160,10 +258,11 @@ class RecordingService
$staleAt = $recording->ended_at ?? $recording->updated_at;
if ($staleAt && $staleAt->lt(now()->subMinutes($timeoutMinutes))) {
return $this->fail(
$recording,
'Recording upload did not complete. Keep the host browser open briefly after ending the meeting so the file can upload.',
);
$reason = $this->usesServerEgress($recording)
? 'LiveKit did not finish processing the recording. Check your egress service and storage configuration.'
: 'Recording upload did not complete. Keep the host browser open briefly after ending the meeting so the file can upload.';
return $this->fail($recording, $reason);
}
return $recording;
@@ -185,10 +284,11 @@ class RecordingService
})
->orderBy('id')
->each(function (Recording $recording) use (&$failed) {
$this->fail(
$recording,
'Recording upload did not complete. Keep the host browser open briefly after ending the meeting so the file can upload.',
);
$reason = $this->usesServerEgress($recording)
? 'LiveKit did not finish processing the recording. Check your egress service and storage configuration.'
: 'Recording upload did not complete. Keep the host browser open briefly after ending the meeting so the file can upload.';
$this->fail($recording, $reason);
$failed++;
});
@@ -244,4 +344,29 @@ class RecordingService
$recording->delete();
}
protected function firstEgressFile(EgressInfo $info): ?FileInfo
{
foreach ($info->getFileResults() as $file) {
if ($file instanceof FileInfo) {
return $file;
}
}
return null;
}
protected function durationSecondsFromFile(FileInfo $file, Recording $recording): ?int
{
$duration = (int) $file->getDuration();
if ($duration <= 0) {
return $recording->duration_seconds;
}
if ($duration > 86_400) {
return (int) round($duration / 1_000_000_000);
}
return $duration;
}
}