From c3b2b4663f14161fe1a4b5065bcfb1a0d51c4da2 Mon Sep 17 00:00:00 2001 From: Carlos Santos <4a.santos@gmail.com> Date: Tue, 24 Sep 2024 11:10:39 +0200 Subject: [PATCH] ov-components: Exported storage service --- .../src/lib/models/storage.model.ts | 2 +- .../lib/services/storage/storage.service.ts | 45 ++++++++++--------- .../src/public-api.ts | 2 + 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/openvidu-components-angular/projects/openvidu-components-angular/src/lib/models/storage.model.ts b/openvidu-components-angular/projects/openvidu-components-angular/src/lib/models/storage.model.ts index 0de38a5234..a899538f64 100644 --- a/openvidu-components-angular/projects/openvidu-components-angular/src/lib/models/storage.model.ts +++ b/openvidu-components-angular/projects/openvidu-components-angular/src/lib/models/storage.model.ts @@ -1,7 +1,7 @@ /** * @internal */ -export enum Storage { +export enum StorageKeys { PARTICIPANT_NAME = 'openviduCallName', VIDEO_DEVICE = 'openviduCallVideoDevice', AUDIO_DEVICE = 'openviduCallAudioDevice', diff --git a/openvidu-components-angular/projects/openvidu-components-angular/src/lib/services/storage/storage.service.ts b/openvidu-components-angular/projects/openvidu-components-angular/src/lib/services/storage/storage.service.ts index 78a230cebd..5922fe2a4d 100644 --- a/openvidu-components-angular/projects/openvidu-components-angular/src/lib/services/storage/storage.service.ts +++ b/openvidu-components-angular/projects/openvidu-components-angular/src/lib/services/storage/storage.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; import { ILogger } from '../../models/logger.model'; -import { Storage } from '../../models/storage.model'; +import { StorageKeys } from '../../models/storage.model'; import { LoggerService } from '../logger/logger.service'; import { CustomDevice } from '../../models/device.model'; @@ -14,31 +14,31 @@ export class StorageService { public storage = window.localStorage; public log: ILogger; - constructor(private loggerSrv: LoggerService) { + constructor(protected loggerSrv: LoggerService) { this.log = this.loggerSrv.get('StorageService'); } getParticipantName(): string | null { - return this.get(Storage.PARTICIPANT_NAME); + return this.get(StorageKeys.PARTICIPANT_NAME); } setParticipantName(name: string) { - this.set(Storage.PARTICIPANT_NAME, name); + this.set(StorageKeys.PARTICIPANT_NAME, name); } getVideoDevice(): CustomDevice | null { - return this.get(Storage.VIDEO_DEVICE); + return this.get(StorageKeys.VIDEO_DEVICE); } setVideoDevice(device: CustomDevice) { - this.set(Storage.VIDEO_DEVICE, device); + this.set(StorageKeys.VIDEO_DEVICE, device); } getAudioDevice(): CustomDevice | null { - return this.get(Storage.AUDIO_DEVICE); + return this.get(StorageKeys.AUDIO_DEVICE); } setAudioDevice(device: CustomDevice) { - this.set(Storage.AUDIO_DEVICE, device); + this.set(StorageKeys.AUDIO_DEVICE, device); } /** @@ -46,7 +46,7 @@ export class StorageService { * Returns true only if the participant has the camera deliberately enabled */ isCameraEnabled(): boolean { - const value = this.get(Storage.CAMERA_ENABLED); + const value = this.get(StorageKeys.CAMERA_ENABLED); if (value === null) { return true; } @@ -54,7 +54,7 @@ export class StorageService { } setCameraEnabled(enabled: boolean) { - this.set(Storage.CAMERA_ENABLED, enabled); + this.set(StorageKeys.CAMERA_ENABLED, enabled); } /** @@ -62,7 +62,7 @@ export class StorageService { * Returns true only if the participant has the microphone deliberately enabled */ isMicrophoneEnabled(): boolean { - const value = this.get(Storage.MICROPHONE_ENABLED); + const value = this.get(StorageKeys.MICROPHONE_ENABLED); if (value === null) { return true; } @@ -73,42 +73,43 @@ export class StorageService { * @param enabled */ setMicrophoneEnabled(enabled: boolean) { - this.set(Storage.MICROPHONE_ENABLED, enabled); + this.set(StorageKeys.MICROPHONE_ENABLED, enabled); } setLang(lang: string) { - this.set(Storage.LANG, lang); + this.set(StorageKeys.LANG, lang); } getLang(): string { - return this.get(Storage.LANG); + return this.get(StorageKeys.LANG); } setCaptionLang(lang: string) { - this.set(Storage.CAPTION_LANG, lang); + this.set(StorageKeys.CAPTION_LANG, lang); } getCaptionsLang(): string { - return this.get(Storage.CAPTION_LANG); + return this.get(StorageKeys.CAPTION_LANG); } setBackground(id: string) { - this.set(Storage.BACKGROUND, id); + this.set(StorageKeys.BACKGROUND, id); } getBackground(): string { - return this.get(Storage.BACKGROUND); + return this.get(StorageKeys.BACKGROUND); } removeBackground() { - this.remove(Storage.BACKGROUND); + this.remove(StorageKeys.BACKGROUND); } - private set(key: string, item: any) { + protected set(key: string, item: any) { const value = JSON.stringify({ item: item }); this.storage.setItem(key, value); } - private get(key: string): any { + + protected get(key: string): any { const str = this.storage.getItem(key); if (!!str) { return JSON.parse(str).item; @@ -116,7 +117,7 @@ export class StorageService { return null; } - private remove(key: string) { + protected remove(key: string) { this.storage.removeItem(key); } diff --git a/openvidu-components-angular/projects/openvidu-components-angular/src/public-api.ts b/openvidu-components-angular/projects/openvidu-components-angular/src/public-api.ts index c1fce355e4..3911838c54 100644 --- a/openvidu-components-angular/projects/openvidu-components-angular/src/public-api.ts +++ b/openvidu-components-angular/projects/openvidu-components-angular/src/public-api.ts @@ -37,6 +37,7 @@ export * from './lib/models/data-topic.model'; export * from './lib/models/room.model'; export * from './lib/models/toolbar.model'; export * from './lib/models/logger.model' +export * from './lib/models/storage.model'; export * from './lib/openvidu-components-angular.module'; // Pipes export * from './lib/pipes/participant.pipe'; @@ -52,5 +53,6 @@ export * from './lib/services/participant/participant.service'; export * from './lib/services/recording/recording.service'; export * from './lib/services/config/global-config.service'; export * from './lib/services/logger/logger.service'; +export * from './lib/services/storage/storage.service'; export * from 'livekit-client';