diff --git a/resources/js/meet-room.js b/resources/js/meet-room.js index 805c06c..d94416b 100644 --- a/resources/js/meet-room.js +++ b/resources/js/meet-room.js @@ -168,6 +168,7 @@ function meetRoom() { this.muteOnJoin = el.dataset.muteOnJoin === '1'; this.videoOffOnJoin = el.dataset.videoOffOnJoin === '1' || this.audioOnly; this.isRecording = el.dataset.recordingActive === '1'; + this.activeRecordingUuid = el.dataset.activeRecordingUuid || null; this.isLocked = el.dataset.locked === '1'; this.watermark = el.dataset.watermark === '1'; this.liveCaptions = el.dataset.liveCaptions === '1'; @@ -371,6 +372,8 @@ function meetRoom() { this.attachExistingTracks(room.localParticipant); room.remoteParticipants.forEach((participant) => this.attachExistingTracks(participant)); this.syncParticipants(); + + await this.maybeStartAutoRecording(); } catch (e) { console.error(e); this.connectionStatus = this.connectionErrorMessage(e); @@ -1359,6 +1362,37 @@ function meetRoom() { } }, + async maybeStartAutoRecording() { + if (!this.isHost || !this.isRecording || recordingMediaRecorder) { + return; + } + + const el = document.getElementById('meet-config'); + const existingUuid = this.activeRecordingUuid || el?.dataset.activeRecordingUuid || ''; + + if (existingUuid) { + this.activeRecordingUuid = existingUuid; + } else { + await this.startServerRecording(); + return; + } + + const started = await this.tryStartClientRecordingWithRetry(); + if (!started) { + console.warn('Auto-record client capture could not start.'); + } + }, + + async tryStartClientRecordingWithRetry() { + if (this.startClientRecording()) { + return true; + } + + await new Promise((resolve) => setTimeout(resolve, 1500)); + + return this.startClientRecording(); + }, + async toggleRecording() { if (!this.isHost) return; @@ -1375,7 +1409,7 @@ function meetRoom() { const data = await res.json(); this.activeRecordingUuid = data.recording_uuid; - if (!this.startClientRecording()) { + if (! await this.tryStartClientRecordingWithRetry()) { this.isRecording = false; this.activeRecordingUuid = null; return; @@ -1453,6 +1487,7 @@ function meetRoom() { }, async stopServerAndUploadRecording() { + const hadClientRecorder = !!recordingMediaRecorder; const res = await fetch(this.config.recordingStopUrl, { method: 'POST', headers: this.headers() }); const blob = await this.stopClientRecording(); this.isRecording = false; @@ -1470,7 +1505,7 @@ function meetRoom() { if (!uploaded) { window.alert(`Recording upload failed. Open Recordings and try again, or re-record the ${this.sessionNoun()}.`); } - } else if (recordingUuid) { + } else if (recordingUuid && hadClientRecorder) { window.alert(`No recording was captured from this ${this.sessionNoun()}. Start recording again while the ${this.sessionNoun()} is live.`); } diff --git a/resources/views/meet/room/show.blade.php b/resources/views/meet/room/show.blade.php index 656d5c1..9a3f69e 100644 --- a/resources/views/meet/room/show.blade.php +++ b/resources/views/meet/room/show.blade.php @@ -90,6 +90,7 @@ data-watermark="{{ $watermark ? '1' : '0' }}" data-locked="{{ $session->is_locked ? '1' : '0' }}" data-recording-active="{{ $activeRecording ? '1' : '0' }}" + data-active-recording-uuid="{{ $activeRecording?->uuid ?? '' }}" data-is-webinar="{{ ($isWebinar ?? false) ? '1' : '0' }}" data-is-conference="{{ ($isConference ?? false) ? '1' : '0' }}" data-session-noun="{{ $sessionNoun }}"