listen to local volume change only if in bubble conversation
This commit is contained in:
@@ -169,7 +169,9 @@ export class GameScene extends DirtyScene {
|
|||||||
private peerStoreUnsubscribe!: Unsubscriber;
|
private peerStoreUnsubscribe!: Unsubscriber;
|
||||||
private emoteUnsubscribe!: Unsubscriber;
|
private emoteUnsubscribe!: Unsubscriber;
|
||||||
private emoteMenuUnsubscribe!: Unsubscriber;
|
private emoteMenuUnsubscribe!: Unsubscriber;
|
||||||
private volumeStoreUnsubscribes: Map<number, Unsubscriber> = new Map<number, Unsubscriber>();
|
|
||||||
|
private volumeStoreUnsubscribers: Map<number, Unsubscriber> = new Map<number, Unsubscriber>();
|
||||||
|
private localVolumeStoreUnsubscriber: Unsubscriber | undefined;
|
||||||
private followUsersColorStoreUnsubscribe!: Unsubscriber;
|
private followUsersColorStoreUnsubscribe!: Unsubscriber;
|
||||||
|
|
||||||
private biggestAvailableAreaStoreUnsubscribe!: () => void;
|
private biggestAvailableAreaStoreUnsubscribe!: () => void;
|
||||||
@@ -637,20 +639,13 @@ export class GameScene extends DirtyScene {
|
|||||||
this.connect();
|
this.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
localVolumeStore.subscribe((volume) => {
|
|
||||||
if (volume) {
|
|
||||||
this.CurrentPlayer.showIconTalk(volume > 5);
|
|
||||||
this.markDirty(); // should be dirty from animation
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let oldPeerNumber = 0;
|
let oldPeerNumber = 0;
|
||||||
this.peerStoreUnsubscribe = peerStore.subscribe((peers) => {
|
this.peerStoreUnsubscribe = peerStore.subscribe((peers) => {
|
||||||
this.volumeStoreUnsubscribes.forEach(unsubscribe => unsubscribe());
|
this.volumeStoreUnsubscribers.forEach(unsubscribe => unsubscribe());
|
||||||
this.volumeStoreUnsubscribes.clear();
|
this.volumeStoreUnsubscribers.clear();
|
||||||
|
|
||||||
for (const [key, videoStream] of peers) {
|
for (const [key, videoStream] of peers) {
|
||||||
this.volumeStoreUnsubscribes.set(key, videoStream.volumeStore.subscribe((volume) => {
|
this.volumeStoreUnsubscribers.set(key, videoStream.volumeStore.subscribe((volume) => {
|
||||||
if (volume) {
|
if (volume) {
|
||||||
console.log(`${key}: ${volume}`);
|
console.log(`${key}: ${volume}`);
|
||||||
this.MapPlayersByKey.get(key)?.showIconTalk(volume > 5);
|
this.MapPlayersByKey.get(key)?.showIconTalk(volume > 5);
|
||||||
@@ -665,6 +660,18 @@ export class GameScene extends DirtyScene {
|
|||||||
} else if (newPeerNumber < oldPeerNumber) {
|
} else if (newPeerNumber < oldPeerNumber) {
|
||||||
this.playSound("audio-webrtc-out");
|
this.playSound("audio-webrtc-out");
|
||||||
}
|
}
|
||||||
|
if (newPeerNumber > 0) {
|
||||||
|
this.localVolumeStoreUnsubscriber = localVolumeStore.subscribe((volume) => {
|
||||||
|
if (volume) {
|
||||||
|
this.CurrentPlayer.showIconTalk(volume > 5);
|
||||||
|
this.markDirty(); // should be dirty from animation
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if (this.localVolumeStoreUnsubscriber) {
|
||||||
|
this.localVolumeStoreUnsubscriber();
|
||||||
|
}
|
||||||
|
}
|
||||||
oldPeerNumber = newPeerNumber;
|
oldPeerNumber = newPeerNumber;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -546,36 +546,35 @@ export const obtainedMediaConstraintStore = derived<Readable<MediaStreamConstrai
|
|||||||
export const localVolumeStore = readable<number | null>(null, (set) => {
|
export const localVolumeStore = readable<number | null>(null, (set) => {
|
||||||
let timeout: ReturnType<typeof setTimeout>;
|
let timeout: ReturnType<typeof setTimeout>;
|
||||||
const unsubscribe = localStreamStore.subscribe((localStreamStoreValue) => {
|
const unsubscribe = localStreamStore.subscribe((localStreamStoreValue) => {
|
||||||
console.log('LOCAL VOLUME STORE SUBSCRIBE TO LOCAL STREAM STORE');
|
clearInterval(timeout);
|
||||||
if (localStreamStoreValue.type === "error") {
|
if (localStreamStoreValue.type === "error") {
|
||||||
console.log('D1');
|
|
||||||
set(null);
|
set(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const soundMeter = new SoundMeter();
|
const soundMeter = new SoundMeter();
|
||||||
const mediaStream = localStreamStoreValue.stream;
|
const mediaStream = localStreamStoreValue.stream;
|
||||||
if (mediaStream !== null && mediaStream.getAudioTracks().length > 0) {
|
|
||||||
console.log('D3');
|
if (mediaStream === null || mediaStream.getAudioTracks().length <= 0) {
|
||||||
console.log(localStreamStoreValue);
|
set(null);
|
||||||
soundMeter.connectToSource(mediaStream, new AudioContext());
|
return;
|
||||||
let error = false;
|
|
||||||
|
|
||||||
timeout = setInterval(() => {
|
|
||||||
console.log('local time interval');
|
|
||||||
try {
|
|
||||||
set(soundMeter.getVolume());
|
|
||||||
} catch (err) {
|
|
||||||
if (!error) {
|
|
||||||
console.error(err);
|
|
||||||
error = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
soundMeter.connectToSource(mediaStream, new AudioContext());
|
||||||
|
let error = false;
|
||||||
|
|
||||||
|
timeout = setInterval(() => {
|
||||||
|
try {
|
||||||
|
set(soundMeter.getVolume());
|
||||||
|
} catch (err) {
|
||||||
|
if (!error) {
|
||||||
|
console.error(err);
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
});
|
});
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
console.log('UNSUBSCRIBE FROM LOCAL STREAM STORE');
|
|
||||||
unsubscribe();
|
unsubscribe();
|
||||||
clearInterval(timeout);
|
clearInterval(timeout);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ export class VideoPeer extends Peer {
|
|||||||
this.uniqueId = "video_" + this.userId;
|
this.uniqueId = "video_" + this.userId;
|
||||||
|
|
||||||
this.streamStore = readable<MediaStream | null>(null, (set) => {
|
this.streamStore = readable<MediaStream | null>(null, (set) => {
|
||||||
console.log('STREAM STORE INITIALIZE');
|
|
||||||
const onStream = (stream: MediaStream | null) => {
|
const onStream = (stream: MediaStream | null) => {
|
||||||
set(stream);
|
set(stream);
|
||||||
};
|
};
|
||||||
@@ -74,32 +73,30 @@ export class VideoPeer extends Peer {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('CREATE VOLUME STORE');
|
|
||||||
|
|
||||||
this.volumeStore = readable<number | null>(null, (set) => {
|
this.volumeStore = readable<number | null>(null, (set) => {
|
||||||
let timeout: ReturnType<typeof setTimeout>;
|
let timeout: ReturnType<typeof setTimeout>;
|
||||||
console.log('VOLUME STORE INITIALIZE');
|
|
||||||
const unsubscribe = this.streamStore.subscribe((mediaStream) => {
|
const unsubscribe = this.streamStore.subscribe((mediaStream) => {
|
||||||
if (mediaStream !== null && mediaStream.getAudioTracks().length > 0) {
|
if (mediaStream === null || mediaStream.getAudioTracks().length <= 0) {
|
||||||
const soundMeter = new SoundMeter();
|
set(null);
|
||||||
soundMeter.connectToSource(mediaStream, new AudioContext());
|
return;
|
||||||
let error = false;
|
|
||||||
|
|
||||||
timeout = setInterval(() => {
|
|
||||||
try {
|
|
||||||
set(soundMeter.getVolume());
|
|
||||||
} catch (err) {
|
|
||||||
if (!error) {
|
|
||||||
console.error(err);
|
|
||||||
error = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 100);
|
|
||||||
}
|
}
|
||||||
|
const soundMeter = new SoundMeter();
|
||||||
|
soundMeter.connectToSource(mediaStream, new AudioContext());
|
||||||
|
let error = false;
|
||||||
|
|
||||||
|
timeout = setInterval(() => {
|
||||||
|
try {
|
||||||
|
set(soundMeter.getVolume());
|
||||||
|
} catch (err) {
|
||||||
|
if (!error) {
|
||||||
|
console.error(err);
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
});
|
});
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
console.log('UNSUBSCRIBE');
|
|
||||||
unsubscribe();
|
unsubscribe();
|
||||||
clearInterval(timeout);
|
clearInterval(timeout);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user