mirror of https://github.com/OpenVidu/openvidu.git
ov-components: Exported storage service
parent
f7d6e81261
commit
c3b2b4663f
|
@ -1,7 +1,7 @@
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
export enum Storage {
|
export enum StorageKeys {
|
||||||
PARTICIPANT_NAME = 'openviduCallName',
|
PARTICIPANT_NAME = 'openviduCallName',
|
||||||
VIDEO_DEVICE = 'openviduCallVideoDevice',
|
VIDEO_DEVICE = 'openviduCallVideoDevice',
|
||||||
AUDIO_DEVICE = 'openviduCallAudioDevice',
|
AUDIO_DEVICE = 'openviduCallAudioDevice',
|
||||||
|
|
|
@ -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 { Storage } from '../../models/storage.model';
|
import { 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';
|
||||||
|
|
||||||
|
@ -14,31 +14,31 @@ export class StorageService {
|
||||||
public storage = window.localStorage;
|
public storage = window.localStorage;
|
||||||
public log: ILogger;
|
public log: ILogger;
|
||||||
|
|
||||||
constructor(private loggerSrv: LoggerService) {
|
constructor(protected loggerSrv: LoggerService) {
|
||||||
this.log = this.loggerSrv.get('StorageService');
|
this.log = this.loggerSrv.get('StorageService');
|
||||||
}
|
}
|
||||||
|
|
||||||
getParticipantName(): string | null {
|
getParticipantName(): string | null {
|
||||||
return this.get(Storage.PARTICIPANT_NAME);
|
return this.get(StorageKeys.PARTICIPANT_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
setParticipantName(name: string) {
|
setParticipantName(name: string) {
|
||||||
this.set(Storage.PARTICIPANT_NAME, name);
|
this.set(StorageKeys.PARTICIPANT_NAME, name);
|
||||||
}
|
}
|
||||||
getVideoDevice(): CustomDevice | null {
|
getVideoDevice(): CustomDevice | null {
|
||||||
return this.get(Storage.VIDEO_DEVICE);
|
return this.get(StorageKeys.VIDEO_DEVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
setVideoDevice(device: CustomDevice) {
|
setVideoDevice(device: CustomDevice) {
|
||||||
this.set(Storage.VIDEO_DEVICE, device);
|
this.set(StorageKeys.VIDEO_DEVICE, device);
|
||||||
}
|
}
|
||||||
|
|
||||||
getAudioDevice(): CustomDevice | null {
|
getAudioDevice(): CustomDevice | null {
|
||||||
return this.get(Storage.AUDIO_DEVICE);
|
return this.get(StorageKeys.AUDIO_DEVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
setAudioDevice(device: CustomDevice) {
|
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
|
* Returns true only if the participant has the camera deliberately enabled
|
||||||
*/
|
*/
|
||||||
isCameraEnabled(): boolean {
|
isCameraEnabled(): boolean {
|
||||||
const value = this.get(Storage.CAMERA_ENABLED);
|
const value = this.get(StorageKeys.CAMERA_ENABLED);
|
||||||
if (value === null) {
|
if (value === null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ export class StorageService {
|
||||||
}
|
}
|
||||||
|
|
||||||
setCameraEnabled(enabled: boolean) {
|
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
|
* Returns true only if the participant has the microphone deliberately enabled
|
||||||
*/
|
*/
|
||||||
isMicrophoneEnabled(): boolean {
|
isMicrophoneEnabled(): boolean {
|
||||||
const value = this.get(Storage.MICROPHONE_ENABLED);
|
const value = this.get(StorageKeys.MICROPHONE_ENABLED);
|
||||||
if (value === null) {
|
if (value === null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -73,42 +73,43 @@ export class StorageService {
|
||||||
* @param enabled
|
* @param enabled
|
||||||
*/
|
*/
|
||||||
setMicrophoneEnabled(enabled: boolean) {
|
setMicrophoneEnabled(enabled: boolean) {
|
||||||
this.set(Storage.MICROPHONE_ENABLED, enabled);
|
this.set(StorageKeys.MICROPHONE_ENABLED, enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
setLang(lang: string) {
|
setLang(lang: string) {
|
||||||
this.set(Storage.LANG, lang);
|
this.set(StorageKeys.LANG, lang);
|
||||||
}
|
}
|
||||||
|
|
||||||
getLang(): string {
|
getLang(): string {
|
||||||
return this.get(Storage.LANG);
|
return this.get(StorageKeys.LANG);
|
||||||
}
|
}
|
||||||
|
|
||||||
setCaptionLang(lang: string) {
|
setCaptionLang(lang: string) {
|
||||||
this.set(Storage.CAPTION_LANG, lang);
|
this.set(StorageKeys.CAPTION_LANG, lang);
|
||||||
}
|
}
|
||||||
|
|
||||||
getCaptionsLang(): string {
|
getCaptionsLang(): string {
|
||||||
return this.get(Storage.CAPTION_LANG);
|
return this.get(StorageKeys.CAPTION_LANG);
|
||||||
}
|
}
|
||||||
|
|
||||||
setBackground(id: string) {
|
setBackground(id: string) {
|
||||||
this.set(Storage.BACKGROUND, id);
|
this.set(StorageKeys.BACKGROUND, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
getBackground(): string {
|
getBackground(): string {
|
||||||
return this.get(Storage.BACKGROUND);
|
return this.get(StorageKeys.BACKGROUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
removeBackground() {
|
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 });
|
const value = JSON.stringify({ item: item });
|
||||||
this.storage.setItem(key, value);
|
this.storage.setItem(key, value);
|
||||||
}
|
}
|
||||||
private get(key: string): any {
|
|
||||||
|
protected get(key: string): any {
|
||||||
const str = this.storage.getItem(key);
|
const str = this.storage.getItem(key);
|
||||||
if (!!str) {
|
if (!!str) {
|
||||||
return JSON.parse(str).item;
|
return JSON.parse(str).item;
|
||||||
|
@ -116,7 +117,7 @@ export class StorageService {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private remove(key: string) {
|
protected remove(key: string) {
|
||||||
this.storage.removeItem(key);
|
this.storage.removeItem(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ export * from './lib/models/data-topic.model';
|
||||||
export * from './lib/models/room.model';
|
export * from './lib/models/room.model';
|
||||||
export * from './lib/models/toolbar.model';
|
export * from './lib/models/toolbar.model';
|
||||||
export * from './lib/models/logger.model'
|
export * from './lib/models/logger.model'
|
||||||
|
export * from './lib/models/storage.model';
|
||||||
export * from './lib/openvidu-components-angular.module';
|
export * from './lib/openvidu-components-angular.module';
|
||||||
// Pipes
|
// Pipes
|
||||||
export * from './lib/pipes/participant.pipe';
|
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/recording/recording.service';
|
||||||
export * from './lib/services/config/global-config.service';
|
export * from './lib/services/config/global-config.service';
|
||||||
export * from './lib/services/logger/logger.service';
|
export * from './lib/services/logger/logger.service';
|
||||||
|
export * from './lib/services/storage/storage.service';
|
||||||
|
|
||||||
export * from 'livekit-client';
|
export * from 'livekit-client';
|
||||||
|
|
Loading…
Reference in New Issue