catch no audio track error
This commit is contained in:
@@ -10,6 +10,8 @@ import { myCameraVisibilityStore } from "./MyCameraStoreVisibility";
|
||||
import { peerStore } from "./PeerStore";
|
||||
import { privacyShutdownStore } from "./PrivacyShutdownStore";
|
||||
import { MediaStreamConstraintsError } from "./Errors/MediaStreamConstraintsError";
|
||||
import { SoundMeter } from '../Phaser/Components/SoundMeter';
|
||||
import { AudioContext } from 'standardized-audio-context';
|
||||
|
||||
/**
|
||||
* A store that contains the camera state requested by the user (on or off).
|
||||
@@ -395,6 +397,47 @@ async function toggleConstraints(track: MediaStreamTrack, constraints: MediaTrac
|
||||
}
|
||||
}
|
||||
|
||||
export const localVolumeStore = readable<number | null>(null, (set) => {
|
||||
let timeout: ReturnType<typeof setTimeout>;
|
||||
const unsubscribe = localStreamStore.subscribe((localStreamStoreValue) => {
|
||||
console.log('LOCAL VOLUME STORE SUBSCRIBE TO LOCAL STREAM STORE');
|
||||
if (localStreamStoreValue.type === "error") {
|
||||
console.log('D1');
|
||||
set(null);
|
||||
return;
|
||||
}
|
||||
const soundMeter = new SoundMeter();
|
||||
const mediaStream = localStreamStoreValue.stream;
|
||||
if (mediaStream === null) {
|
||||
console.log('D2');
|
||||
set(null);
|
||||
return;
|
||||
}
|
||||
console.log('D3');
|
||||
console.log(localStreamStoreValue);
|
||||
soundMeter.connectToSource(mediaStream, new AudioContext());
|
||||
let error = false;
|
||||
|
||||
timeout = setInterval(() => {
|
||||
console.log('local time interval');
|
||||
try {
|
||||
set(soundMeter.getVolume());
|
||||
} catch (err) {
|
||||
if (!error) {
|
||||
console.error(err);
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
|
||||
return () => {
|
||||
console.log('UNSUBSCRIBE FROM LOCAL STREAM STORE');
|
||||
unsubscribe();
|
||||
clearInterval(timeout);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* A store containing the MediaStream object (or null if nothing requested, or Error if an error occurred)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user