import { StorageServiceListener, StorageServiceType } from '@unisphere/runtime'; import { UnisphereBaseService } from './unisphere-base-service'; import { UnisphereWorkspaceService } from './unisphere-workspace-service'; const STORAGE_NAMESPACE = 'player'; const STORAGE_SERVICE_KEY = 'unisphere.service.storage'; class UnisphereStorageService extends UnisphereBaseService { public static update = (key: string, value: unknown): void => { const workspace = UnisphereWorkspaceService.get(); const storageService = workspace?.getService(STORAGE_SERVICE_KEY); storageService?.update(STORAGE_NAMESPACE, key, value); }; public static get = (key: string): unknown => { const workspace = UnisphereWorkspaceService.get(); const storageService = workspace?.getService(STORAGE_SERVICE_KEY); return storageService ? storageService.get(STORAGE_NAMESPACE, key) : null; }; public static subscribe = (key: string, callback: StorageServiceListener): void => { const workspace = UnisphereWorkspaceService.get(); const storageService = workspace?.getService(STORAGE_SERVICE_KEY); if (storageService) { const unsubscribe = storageService.subscribe(callback, { namespace: STORAGE_NAMESPACE, property: key, emitLastValue: true }); UnisphereStorageService.addToUnsubscribeMap(unsubscribe); } }; public static destroy(): void { UnisphereStorageService.unsubscribeAll(); } } export { UnisphereStorageService };