fix microphone audio being played back through local video preview

This commit is contained in:
Bruno Windels 2023-01-06 12:05:11 +01:00
parent e26eb30b82
commit fcb4f2a62d
2 changed files with 16 additions and 2 deletions

View File

@ -136,7 +136,7 @@ class OwnMemberViewModel extends ViewModel<Options> implements IStreamViewModel
}
get stream(): Stream | undefined {
return this.call.localMedia?.userMedia;
return this.call.localMedia?.userMediaPreview;
}
private get call(): GroupCall {

View File

@ -20,11 +20,24 @@ import {SDPStreamMetadata} from "./callEventTypes";
import {getStreamVideoTrack, getStreamAudioTrack} from "./common";
export class LocalMedia {
// the userMedia stream without audio, to play in the UI
// without our own audio being played back to us
public readonly userMediaPreview?: Stream;
constructor(
public readonly userMedia?: Stream,
public readonly screenShare?: Stream,
public readonly dataChannelOptions?: RTCDataChannelInit,
) {}
) {
if (userMedia && userMedia.getVideoTracks().length > 0) {
this.userMediaPreview = userMedia.clone();
const audioTrack = getStreamAudioTrack(this.userMediaPreview);
if (audioTrack) {
audioTrack.stop();
this.userMediaPreview.removeTrack(audioTrack);
}
}
}
withUserMedia(stream: Stream) {
return new LocalMedia(stream, this.screenShare, this.dataChannelOptions);
@ -63,6 +76,7 @@ export class LocalMedia {
dispose() {
getStreamAudioTrack(this.userMedia)?.stop();
getStreamVideoTrack(this.userMedia)?.stop();
getStreamVideoTrack(this.userMediaPreview)?.stop();
getStreamVideoTrack(this.screenShare)?.stop();
}
}