catch no audio track error

This commit is contained in:
Hanusiak Piotr 2022-02-03 12:21:30 +01:00
parent 87dde50251
commit e0f5529fa7
3 changed files with 58 additions and 5 deletions

View File

@ -92,6 +92,7 @@ import { MapStore } from "../../Stores/Utils/MapStore";
import { followUsersColorStore } from "../../Stores/FollowStore";
import { GameSceneUserInputHandler } from "../UserInput/GameSceneUserInputHandler";
import { locale } from "../../i18n/i18n-svelte";
import { localVolumeStore } from '../../Stores/MediaStore';
export interface GameSceneInitInterface {
initPosition: PointInterface | null;
reconnecting: boolean;
@ -636,6 +637,13 @@ export class GameScene extends DirtyScene {
this.connect();
}
// localVolumeStore.subscribe((volume) => {
// if (volume) {
// this.CurrentPlayer.showIconTalk(volume > 5);
// this.markDirty(); // should be dirty from animation
// }
// });
let oldPeerNumber = 0;
this.peerStoreUnsubscribe = peerStore.subscribe((peers) => {
this.volumeStoreUnsubscribes.forEach(unsubscribe => unsubscribe());

View File

@ -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)
*/

View File

@ -62,7 +62,6 @@ export class VideoPeer extends Peer {
this.uniqueId = "video_" + this.userId;
this.streamStore = readable<MediaStream | null>(null, (set) => {
console.log('STREAM STORE INITIALIZE');
const onStream = (stream: MediaStream | null) => {
set(stream);
};
@ -74,19 +73,22 @@ export class VideoPeer extends Peer {
};
});
console.log('CREATE VOLUME STORE');
this.volumeStore = readable<number | null>(null, (set) => {
let timeout: ReturnType<typeof setTimeout>;
console.log('VOLUME STORE INITIALIZE');
const unsubscribe = this.streamStore.subscribe((mediaStream) => {
if (mediaStream === null) {
set(null);
return;
}
const soundMeter = new SoundMeter();
soundMeter.connectToSource(mediaStream, new AudioContext());
let error = false;
try {
soundMeter.connectToSource(mediaStream, new AudioContext());
} catch (errMsg) {
console.warn(errMsg);
set(null);
return;
}
timeout = setInterval(() => {
try {