mirror of https://github.com/OpenVidu/openvidu.git
ov-components: Refactored storage service
parent
c3b2b4663f
commit
72c5aa97ad
|
@ -2,12 +2,14 @@
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
export enum StorageKeys {
|
export enum StorageKeys {
|
||||||
PARTICIPANT_NAME = 'openviduCallName',
|
PARTICIPANT_NAME = 'participantName',
|
||||||
VIDEO_DEVICE = 'openviduCallVideoDevice',
|
VIDEO_DEVICE = 'videoDevice',
|
||||||
AUDIO_DEVICE = 'openviduCallAudioDevice',
|
AUDIO_DEVICE = 'audioDevice',
|
||||||
MICROPHONE_ENABLED = 'openviduCallMicrophoneEnabled',
|
MICROPHONE_ENABLED = 'microphoneEnabled',
|
||||||
CAMERA_ENABLED = 'openviduCallCameraEnabled',
|
CAMERA_ENABLED = 'cameraEnabled',
|
||||||
LANG = 'openviduCallLang',
|
LANG = 'lang',
|
||||||
CAPTION_LANG = 'openviduCallCaptionLang',
|
CAPTION_LANG = 'captionLang',
|
||||||
BACKGROUND = "openviduCallBackground"
|
BACKGROUND = "virtualBg"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const STORAGE_PREFIX = 'ovComponents-';
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { ILogger } from '../../models/logger.model';
|
import { ILogger } from '../../models/logger.model';
|
||||||
import { StorageKeys } from '../../models/storage.model';
|
import { STORAGE_PREFIX, StorageKeys } from '../../models/storage.model';
|
||||||
import { LoggerService } from '../logger/logger.service';
|
import { LoggerService } from '../logger/logger.service';
|
||||||
import { CustomDevice } from '../../models/device.model';
|
import { CustomDevice } from '../../models/device.model';
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import { CustomDevice } from '../../models/device.model';
|
||||||
export class StorageService {
|
export class StorageService {
|
||||||
public storage = window.localStorage;
|
public storage = window.localStorage;
|
||||||
public log: ILogger;
|
public log: ILogger;
|
||||||
|
protected PREFIX_KEY = STORAGE_PREFIX;
|
||||||
|
|
||||||
constructor(protected loggerSrv: LoggerService) {
|
constructor(protected loggerSrv: LoggerService) {
|
||||||
this.log = this.loggerSrv.get('StorageService');
|
this.log = this.loggerSrv.get('StorageService');
|
||||||
|
@ -106,11 +107,11 @@ export class StorageService {
|
||||||
|
|
||||||
protected set(key: string, item: any) {
|
protected set(key: string, item: any) {
|
||||||
const value = JSON.stringify({ item: item });
|
const value = JSON.stringify({ item: item });
|
||||||
this.storage.setItem(key, value);
|
this.storage.setItem(this.PREFIX_KEY + key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected get(key: string): any {
|
protected get(key: string): any {
|
||||||
const str = this.storage.getItem(key);
|
const str = this.storage.getItem(this.PREFIX_KEY + key);
|
||||||
if (!!str) {
|
if (!!str) {
|
||||||
return JSON.parse(str).item;
|
return JSON.parse(str).item;
|
||||||
}
|
}
|
||||||
|
@ -118,7 +119,7 @@ export class StorageService {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected remove(key: string) {
|
protected remove(key: string) {
|
||||||
this.storage.removeItem(key);
|
this.storage.removeItem(this.PREFIX_KEY + key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public clear() {
|
public clear() {
|
||||||
|
|
Loading…
Reference in New Issue