mirror of
https://github.com/vector-im/element-call.git
synced 2026-08-02 19:49:23 +00:00
fix: Initial unmute is reverted
This commit is contained in:
@@ -63,6 +63,7 @@ function createMockLocalTrack(source: Track.Source): LocalTrack {
|
|||||||
|
|
||||||
function createMockMuteState(enabled$: BehaviorSubject<boolean>): {
|
function createMockMuteState(enabled$: BehaviorSubject<boolean>): {
|
||||||
enabled$: BehaviorSubject<boolean>;
|
enabled$: BehaviorSubject<boolean>;
|
||||||
|
syncing$: BehaviorSubject<boolean>;
|
||||||
setHandler: (h: (enabled: boolean) => void) => void;
|
setHandler: (h: (enabled: boolean) => void) => void;
|
||||||
unsetHandler: () => void;
|
unsetHandler: () => void;
|
||||||
} {
|
} {
|
||||||
@@ -70,6 +71,7 @@ function createMockMuteState(enabled$: BehaviorSubject<boolean>): {
|
|||||||
|
|
||||||
const ms = {
|
const ms = {
|
||||||
enabled$,
|
enabled$,
|
||||||
|
syncing$: new BehaviorSubject(false),
|
||||||
setHandler: vi.fn().mockImplementation((h: (enabled: boolean) => void) => {
|
setHandler: vi.fn().mockImplementation((h: (enabled: boolean) => void) => {
|
||||||
currentHandler = h;
|
currentHandler = h;
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -112,27 +112,49 @@ export class Publisher {
|
|||||||
this.logger.info("Local track published", localTrackPublication);
|
this.logger.info("Local track published", localTrackPublication);
|
||||||
const lkRoom = this.connection.livekitRoom;
|
const lkRoom = this.connection.livekitRoom;
|
||||||
if (!this.shouldPublish) {
|
if (!this.shouldPublish) {
|
||||||
|
this.logger.debug("Not publishing, pausing upstream");
|
||||||
this.pauseUpstreams(lkRoom, [localTrackPublication.source]).catch((e) => {
|
this.pauseUpstreams(lkRoom, [localTrackPublication.source]).catch((e) => {
|
||||||
this.logger.error(`Failed to pause upstreams`, e);
|
this.logger.error(`Failed to pause upstreams`, e);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// also check the mute state and apply it
|
|
||||||
if (localTrackPublication.source === Track.Source.Microphone) {
|
if (localTrackPublication.source === Track.Source.Microphone) {
|
||||||
const enabled = this.muteStates.audio.enabled$.value;
|
const muteState = this.muteStates.audio;
|
||||||
lkRoom.localParticipant.setMicrophoneEnabled(enabled).catch((e) => {
|
// skip this if a sync is in progress: enabled$ still reflects the old
|
||||||
this.logger.error(
|
// state while the handler is mid-flight, so the handler itself will apply
|
||||||
`Failed to enable microphone track, enabled:${enabled}`,
|
// the correct mute state once it completes.
|
||||||
e,
|
if (!muteState.syncing$.value) {
|
||||||
);
|
const enabled = muteState.enabled$.value;
|
||||||
});
|
if (!enabled) {
|
||||||
|
this.logger.info(
|
||||||
|
"Local audio track just published but muted meanwhile, setting enabled to false",
|
||||||
|
);
|
||||||
|
lkRoom.localParticipant.setMicrophoneEnabled(false).catch((e) => {
|
||||||
|
this.logger.error(
|
||||||
|
`Failed to enable microphone track, enabled:${enabled}`,
|
||||||
|
e,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (localTrackPublication.source === Track.Source.Camera) {
|
} else if (localTrackPublication.source === Track.Source.Camera) {
|
||||||
const enabled = this.muteStates.video.enabled$.value;
|
const muteState = this.muteStates.video;
|
||||||
lkRoom.localParticipant.setCameraEnabled(enabled).catch((e) => {
|
// skip this if a sync is in progress: enabled$ still reflects the old
|
||||||
this.logger.error(
|
// state while the handler is mid-flight, so the handler itself will apply
|
||||||
`Failed to enable camera track, enabled:${enabled}`,
|
// the correct mute state once it completes.
|
||||||
e,
|
if (!muteState.syncing$.value) {
|
||||||
);
|
const enabled = muteState.enabled$.value;
|
||||||
});
|
if (!enabled) {
|
||||||
|
this.logger.info(
|
||||||
|
"Local video track just published but muted meanwhile, setting enabled to false",
|
||||||
|
);
|
||||||
|
lkRoom.localParticipant.setCameraEnabled(false).catch((e) => {
|
||||||
|
this.logger.error(
|
||||||
|
`Failed to enable camera track, enabled:${enabled}`,
|
||||||
|
e,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user