wip: optimizations
This commit is contained in:
+20
-20
@@ -5,6 +5,7 @@ import {
|
||||
} from '@angular/core';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { STORAGE_KEY_USER_VOLUMES } from '../../../../core/constants';
|
||||
import { jsonStorage } from '../../../../infrastructure/persistence/json-storage.service';
|
||||
import { ScreenShareFacade } from '../../../../domains/screen-share';
|
||||
import { User } from '../../../../shared-kernel';
|
||||
import { selectAllUsers, selectCurrentUser } from '../../../../store/users/users.selectors';
|
||||
@@ -38,6 +39,7 @@ interface PeerAudioPipeline {
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class VoicePlaybackService {
|
||||
private readonly store = inject(Store);
|
||||
private readonly jsonStorage = jsonStorage;
|
||||
private readonly voiceConnection = inject(VoiceConnectionFacade);
|
||||
private readonly screenShare = inject(ScreenShareFacade);
|
||||
private readonly allUsers = this.store.selectSignal(selectAllUsers);
|
||||
@@ -401,33 +403,31 @@ export class VoicePlaybackService {
|
||||
}
|
||||
});
|
||||
|
||||
localStorage.setItem(STORAGE_KEY_USER_VOLUMES, JSON.stringify(data));
|
||||
this.jsonStorage.write(STORAGE_KEY_USER_VOLUMES, data);
|
||||
} catch {
|
||||
// localStorage not available
|
||||
// storage not available
|
||||
}
|
||||
}
|
||||
|
||||
private loadPersistedVolumes(): void {
|
||||
try {
|
||||
const raw = localStorage.getItem(STORAGE_KEY_USER_VOLUMES);
|
||||
const data = this.jsonStorage.read<Record<string, { volume: number; muted: boolean }> | null>(
|
||||
STORAGE_KEY_USER_VOLUMES,
|
||||
null
|
||||
);
|
||||
|
||||
if (!raw)
|
||||
return;
|
||||
|
||||
const data = JSON.parse(raw) as Record<string, { volume: number; muted: boolean }>;
|
||||
|
||||
Object.entries(data).forEach(([id, entry]) => {
|
||||
if (typeof entry.volume === 'number') {
|
||||
this.userVolumes.set(id, entry.volume);
|
||||
}
|
||||
|
||||
if (entry.muted) {
|
||||
this.userMuted.set(id, true);
|
||||
}
|
||||
});
|
||||
} catch {
|
||||
// corrupted data - ignore
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object.entries(data).forEach(([id, entry]) => {
|
||||
if (typeof entry.volume === 'number') {
|
||||
this.userVolumes.set(id, entry.volume);
|
||||
}
|
||||
|
||||
if (entry.muted) {
|
||||
this.userMuted.set(id, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private hasAudio(stream: MediaStream): boolean {
|
||||
|
||||
Reference in New Issue
Block a user