Skip to content

Commit 90fd0ef

Browse files
committed
ov-components: add recordingStreamBaseUrl directive and integrate with config service for dynamic stream URL construction
1 parent 6137bdb commit 90fd0ef

5 files changed

Lines changed: 96 additions & 7 deletions

File tree

openvidu-components-angular/projects/openvidu-components-angular/src/lib/directives/api/api.directive.module.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
MinimalDirective,
3737
ParticipantNameDirective,
3838
PrejoinDirective,
39+
RecordingStreamBaseUrlDirective,
3940
TokenDirective,
4041
TokenErrorDirective,
4142
VideoEnabledDirective
@@ -56,6 +57,7 @@ import {
5657
PrejoinDisplayParticipantName,
5758
VideoEnabledDirective,
5859
AudioEnabledDirective,
60+
RecordingStreamBaseUrlDirective,
5961
ToolbarCameraButtonDirective,
6062
ToolbarMicrophoneButtonDirective,
6163
ToolbarScreenshareButtonDirective,
@@ -100,6 +102,7 @@ import {
100102
PrejoinDisplayParticipantName,
101103
VideoEnabledDirective,
102104
AudioEnabledDirective,
105+
RecordingStreamBaseUrlDirective,
103106
ToolbarCameraButtonDirective,
104107
ToolbarMicrophoneButtonDirective,
105108
ToolbarScreenshareButtonDirective,

openvidu-components-angular/projects/openvidu-components-angular/src/lib/directives/api/videoconference.directive.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,3 +725,69 @@ export class AudioEnabledDirective implements OnDestroy {
725725
}
726726
}
727727
}
728+
729+
/**
730+
* The **recordingStreamBaseUrl** directive sets the base URL for retrieving recording streams.
731+
* The complete request URL is dynamically constructed by concatenating the supplied URL, the
732+
* internally managed recordingId, and the `/stream` segment.
733+
*
734+
* The final URL format will be:
735+
*
736+
* {recordingStreamBaseUrl}/{recordingId}/stream
737+
*
738+
* Default: `"/{recordingId}/stream"`
739+
*
740+
* It is essential that the resulting route is declared and configured on your backend, as it is
741+
* used for serving and accessing the recording streams.
742+
*
743+
* @example
744+
* <ov-videoconference [recordingStreamBaseUrl]="'https://myserver.com/api/recordings'">
745+
* </ov-videoconference>
746+
*/
747+
@Directive({
748+
selector: 'ov-videoconference[recordingStreamBaseUrl]'
749+
})
750+
export class RecordingStreamBaseUrlDirective implements AfterViewInit, OnDestroy {
751+
/**
752+
* @ignore
753+
*/
754+
@Input() set recordingStreamBaseUrl(url: string) {
755+
this.update(url);
756+
}
757+
758+
/**
759+
* @ignore
760+
*/
761+
constructor(
762+
private elementRef: ElementRef,
763+
private libService: OpenViduComponentsConfigService
764+
) {}
765+
766+
/**
767+
* @ignore
768+
*/
769+
ngAfterViewInit(): void {
770+
this.update(this.recordingStreamBaseUrl);
771+
}
772+
773+
/**
774+
* @ignore
775+
*/
776+
ngOnDestroy(): void {
777+
this.clear();
778+
}
779+
780+
/**
781+
* @ignore
782+
*/
783+
clear() {
784+
this.update('');
785+
}
786+
787+
/**
788+
* @ignore
789+
*/
790+
update(value: string) {
791+
if (value) this.libService.setRecordingStreamBaseUrl(value);
792+
}
793+
}

openvidu-components-angular/projects/openvidu-components-angular/src/lib/services/config/directive-config.service.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ export class OpenViduComponentsConfigService {
3333
private audioEnabled = <BehaviorSubject<boolean>>new BehaviorSubject(true);
3434
audioEnabled$: Observable<boolean>;
3535

36+
private recordingStreamBaseUrl = <BehaviorSubject<string>>new BehaviorSubject('');
37+
recordingStreamBaseUrl$: Observable<string>;
38+
3639
//Toolbar settings
3740
private cameraButton = <BehaviorSubject<boolean>>new BehaviorSubject(true);
3841
cameraButton$: Observable<boolean>;
@@ -121,6 +124,7 @@ export class OpenViduComponentsConfigService {
121124
this.prejoinDisplayParticipantName$ = this.prejoinDisplayParticipantName.asObservable();
122125
this.videoEnabled$ = this.videoEnabled.asObservable();
123126
this.audioEnabled$ = this.audioEnabled.asObservable();
127+
this.recordingStreamBaseUrl$ = this.recordingStreamBaseUrl.asObservable();
124128
//Toolbar observables
125129
this.cameraButton$ = this.cameraButton.asObservable();
126130
this.microphoneButton$ = this.microphoneButton.asObservable();
@@ -214,6 +218,17 @@ export class OpenViduComponentsConfigService {
214218
return this.audioEnabled.getValue();
215219
}
216220

221+
setRecordingStreamBaseUrl(recordingStreamBaseUrl: string) {
222+
this.recordingStreamBaseUrl.next(recordingStreamBaseUrl);
223+
}
224+
225+
getRecordingStreamBaseUrl(): string {
226+
let baseUrl = this.recordingStreamBaseUrl.getValue();
227+
// Add trailing slash if not present
228+
baseUrl += baseUrl.endsWith('/') ? '' : '/';
229+
return baseUrl;
230+
}
231+
217232
//Toolbar settings
218233

219234
setCameraButton(cameraButton: boolean) {

openvidu-components-angular/projects/openvidu-components-angular/src/lib/services/recording/recording.service.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { Injectable } from '@angular/core';
22
import { BehaviorSubject, Observable } from 'rxjs';
33
import { RecordingInfo, RecordingStatus, RecordingStatusInfo } from '../../models/recording.model';
44
import { ActionService } from '../action/action.service';
5-
import { GlobalConfigService } from '../config/global-config.service';
5+
import { LoggerService } from '../logger/logger.service';
6+
import { ILogger } from '../../models/logger.model';
7+
import { OpenViduComponentsConfigService } from '../config/directive-config.service';
68

79
@Injectable({
810
providedIn: 'root'
@@ -13,19 +15,19 @@ export class RecordingService {
1315
*/
1416
recordingStatusObs: Observable<RecordingStatusInfo>;
1517
private recordingTimeInterval: NodeJS.Timeout;
16-
private API_RECORDINGS_PREFIX = 'call/api/recordings/';
1718
private recordingStatus = <BehaviorSubject<RecordingStatusInfo>>new BehaviorSubject({
1819
status: RecordingStatus.STOPPED,
1920
recordingList: [] as RecordingInfo[],
2021
recordingElapsedTime: new Date(0, 0, 0, 0, 0, 0, 0)
2122
});
23+
private log: ILogger;
2224

2325
/**
2426
* @internal
2527
*/
26-
constructor(private actionService: ActionService, private globalService: GlobalConfigService) {
28+
constructor(private actionService: ActionService, private libService: OpenViduComponentsConfigService, private loggerService: LoggerService) {
29+
this.log = this.loggerService.get('RecordingService');
2730
this.recordingStatusObs = this.recordingStatus.asObservable();
28-
this.API_RECORDINGS_PREFIX = this.globalService.getBaseHref() + this.API_RECORDINGS_PREFIX;
2931
}
3032

3133
/**
@@ -146,9 +148,10 @@ export class RecordingService {
146148
*/
147149
playRecording(recording: RecordingInfo) {
148150
// Only COMPOSED recording is supported. The extension will allways be 'mp4'.
149-
console.log('Playing recording', recording);
151+
this.log.d('Playing recording', recording);
150152
const queryParamForAvoidCache = `?t=${new Date().getTime()}`;
151-
const streamRecordingUrl = `${this.API_RECORDINGS_PREFIX}${recording.id}/stream${queryParamForAvoidCache}`;
153+
const baseUrl = this.libService.getRecordingStreamBaseUrl();
154+
const streamRecordingUrl = `${baseUrl}${recording.id}/stream${queryParamForAvoidCache}`;
152155
this.actionService.openRecordingPlayerDialog(streamRecordingUrl);
153156
}
154157

@@ -161,7 +164,8 @@ export class RecordingService {
161164
// Only COMPOSED recording is supported. The extension will allways be 'mp4'.
162165
const queryParamForAvoidCache = `?t=${new Date().getTime()}`;
163166
const link = document.createElement('a');
164-
link.href = `${this.API_RECORDINGS_PREFIX}${recording.id}/stream${queryParamForAvoidCache}`;
167+
const baseUrl = this.libService.getRecordingStreamBaseUrl();
168+
link.href = `${baseUrl}${recording.id}/stream${queryParamForAvoidCache}`;
165169
link.download = recording.filename || 'openvidu-recording.mp4';
166170
link.dispatchEvent(
167171
new MouseEvent('click', {

openvidu-components-angular/src/app/openvidu-call/call.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
[participantName]="'Participant'"
1212
[videoEnabled]="true"
1313
[audioEnabled]="true"
14+
[recordingStreamBaseUrl]="'call/api/recordings'"
1415
[toolbarCameraButton]="true"
1516
[toolbarMicrophoneButton]="true"
1617
[toolbarScreenshareButton]="true"

0 commit comments

Comments
 (0)