Skip to content

Commit

Permalink
ov-components: Exported storage service
Browse files Browse the repository at this point in the history
  • Loading branch information
CSantosM committed Sep 24, 2024
1 parent f7d6e81 commit c3b2b46
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @internal
*/
export enum Storage {
export enum StorageKeys {
PARTICIPANT_NAME = 'openviduCallName',
VIDEO_DEVICE = 'openviduCallVideoDevice',
AUDIO_DEVICE = 'openviduCallAudioDevice',
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -14,55 +14,55 @@ 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);
}

/**
* @internal
* 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;
}
return value === true;
}

setCameraEnabled(enabled: boolean) {
this.set(Storage.CAMERA_ENABLED, enabled);
this.set(StorageKeys.CAMERA_ENABLED, enabled);
}

/**
* @internal
* 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;
}
Expand All @@ -73,50 +73,51 @@ 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;
}
return null;
}

private remove(key: string) {
protected remove(key: string) {
this.storage.removeItem(key);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';

0 comments on commit c3b2b46

Please sign in to comment.