FIX: we now make sure to completly disable the old stream before attempting to create a new one (#1493)
* FIX: we now make sure to completly disable the old stream before attempting to create a new one * FIX: disable audio optimization on chrome * always reemit the stream on chrome * Try fix on stop current stream Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Try fix on stop current stream Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Push fix microphone Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> Co-authored-by: Gregoire Parant <g.parant@thecodingmachine.com>
This commit is contained in:
parent
f6fcb37d91
commit
7bb0175648
@ -289,7 +289,9 @@ export const mediaStreamConstraintsStore = derived(
|
|||||||
// Disable webcam for energy reasons (the user is not moving and we are talking to no one)
|
// Disable webcam for energy reasons (the user is not moving and we are talking to no one)
|
||||||
if ($cameraEnergySavingStore === true) {
|
if ($cameraEnergySavingStore === true) {
|
||||||
currentVideoConstraint = false;
|
currentVideoConstraint = false;
|
||||||
currentAudioConstraint = false;
|
//this optimization is desactivated because of sound issues on chrome
|
||||||
|
//todo: fix this conflicts and reactivate this optimization
|
||||||
|
//currentAudioConstraint = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let's make the changes only if the new value is different from the old one.
|
// Let's make the changes only if the new value is different from the old one.
|
||||||
@ -376,7 +378,8 @@ function toggleConstraints(track: MediaStreamTrack, constraints: MediaTrackConst
|
|||||||
} else if (constraints === false) {
|
} else if (constraints === false) {
|
||||||
track.stop();
|
track.stop();
|
||||||
}
|
}
|
||||||
if (constraints && constraints !== true) {
|
// @ts-ignore
|
||||||
|
if (typeof constraints !== "boolean" && constraints !== true) {
|
||||||
track.applyConstraints(constraints);
|
track.applyConstraints(constraints);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -391,12 +394,11 @@ export const localStreamStore = derived<Readable<MediaStreamConstraints>, LocalS
|
|||||||
|
|
||||||
async function initStream(constraints: MediaStreamConstraints) {
|
async function initStream(constraints: MediaStreamConstraints) {
|
||||||
try {
|
try {
|
||||||
const newStream = await navigator.mediaDevices.getUserMedia(constraints);
|
|
||||||
if (currentStream) {
|
if (currentStream) {
|
||||||
//we need stop all tracks to make sure the old stream will be garbage collected
|
//we need stop all tracks to make sure the old stream will be garbage collected
|
||||||
currentStream.getTracks().forEach((t) => t.stop());
|
//currentStream.getTracks().forEach((t) => t.stop());
|
||||||
}
|
}
|
||||||
currentStream = newStream;
|
currentStream = await navigator.mediaDevices.getUserMedia(constraints);
|
||||||
set({
|
set({
|
||||||
type: "success",
|
type: "success",
|
||||||
stream: currentStream,
|
stream: currentStream,
|
||||||
@ -480,7 +482,8 @@ export const localStreamStore = derived<Readable<MediaStreamConstraints>, LocalS
|
|||||||
type: "success",
|
type: "success",
|
||||||
stream: null,
|
stream: null,
|
||||||
});
|
});
|
||||||
} else if ((constraints.audio && !oldConstraints.audio) || (!oldConstraints.video && constraints.video)) {
|
} //we reemit the stream if it was muted just to be sure
|
||||||
|
else if (constraints.audio /* && !oldConstraints.audio*/ || (!oldConstraints.video && constraints.video)) {
|
||||||
initStream(constraints);
|
initStream(constraints);
|
||||||
}
|
}
|
||||||
oldConstraints = {
|
oldConstraints = {
|
||||||
|
Loading…
Reference in New Issue
Block a user