mirror of
https://github.com/vector-im/element-call.git
synced 2026-03-25 06:40:26 +00:00
Extended logging for mute states
This commit is contained in:
@@ -477,9 +477,7 @@ export function createCallViewModel$(
|
||||
mediaDevices,
|
||||
muteStates,
|
||||
trackProcessorState$,
|
||||
logger.getChild(
|
||||
"[Publisher" + connection.transport.livekit_service_url + "]",
|
||||
),
|
||||
logger.getChild(`[${connection.transport.livekit_service_url}]`),
|
||||
);
|
||||
},
|
||||
connectionManager: connectionManager,
|
||||
|
||||
@@ -45,14 +45,16 @@ import {
|
||||
* The Publisher is also responsible for creating the media tracks.
|
||||
*/
|
||||
export class Publisher {
|
||||
private readonly logger: Logger;
|
||||
|
||||
/**
|
||||
* Creates a new Publisher.
|
||||
* @param scope - The observable scope to use for managing the publisher.
|
||||
* @param connection - The connection to use for publishing.
|
||||
* @param devices - The media devices to use for audio and video input.
|
||||
* @param muteStates - The mute states for audio and video.
|
||||
* @param e2eeLivekitOptions - The E2EE options to use for the LiveKit room. Use to share the same key provider across connections!.
|
||||
* @param trackerProcessorState$ - The processor state for the video track processor (e.g. background blur).
|
||||
* @param logger - the parent logger
|
||||
*/
|
||||
public constructor(
|
||||
private scope: ObservableScope,
|
||||
@@ -60,8 +62,9 @@ export class Publisher {
|
||||
devices: MediaDevices,
|
||||
private readonly muteStates: MuteStates,
|
||||
trackerProcessorState$: Behavior<ProcessorState>,
|
||||
private logger: Logger,
|
||||
logger: Logger,
|
||||
) {
|
||||
this.logger = logger.getChild(`[Publisher]`);
|
||||
this.logger.info("Create LiveKit room");
|
||||
const { controlledAudioDevices } = getUrlParams();
|
||||
|
||||
@@ -149,6 +152,7 @@ export class Publisher {
|
||||
|
||||
private _publishing$ = new BehaviorSubject<boolean>(false);
|
||||
public publishing$ = this.scope.behavior(this._publishing$);
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns
|
||||
@@ -233,6 +237,7 @@ export class Publisher {
|
||||
* Stops all tracks that are currently running
|
||||
*/
|
||||
public stopTracks(): void {
|
||||
this.logger.debug("stopTracks called");
|
||||
this.tracks$.value.forEach((t) => t.stop());
|
||||
this._tracks$.next([]);
|
||||
}
|
||||
@@ -337,6 +342,7 @@ export class Publisher {
|
||||
private observeMuteStates(scope: ObservableScope): void {
|
||||
const lkRoom = this.connection.livekitRoom;
|
||||
this.muteStates.audio.setHandler(async (desired) => {
|
||||
this.logger.debug(`Syncing LiveKit audio mute state to ${desired}`);
|
||||
try {
|
||||
await lkRoom.localParticipant.setMicrophoneEnabled(desired);
|
||||
} catch (e) {
|
||||
@@ -345,6 +351,7 @@ export class Publisher {
|
||||
return lkRoom.localParticipant.isMicrophoneEnabled;
|
||||
});
|
||||
this.muteStates.video.setHandler(async (desired) => {
|
||||
this.logger.debug(`Syncing LiveKit video mute state to ${desired}`);
|
||||
try {
|
||||
await lkRoom.localParticipant.setCameraEnabled(desired);
|
||||
} catch (e) {
|
||||
|
||||
@@ -49,6 +49,7 @@ describe("MuteState", () => {
|
||||
} as unknown as MediaDevice<DeviceLabel, SelectedDevice>;
|
||||
|
||||
const muteState = new MuteState(
|
||||
"test-mutestate",
|
||||
testScope,
|
||||
deviceStub,
|
||||
constant(true),
|
||||
|
||||
@@ -52,12 +52,14 @@ export class MuteState<Label, Selected> {
|
||||
private readonly handler$ = new BehaviorSubject(defaultHandler);
|
||||
|
||||
public setHandler(handler: Handler): void {
|
||||
logger.debug(`MuteState[${this.description}]: setting handler`);
|
||||
if (this.handler$.value !== defaultHandler)
|
||||
throw new Error("Multiple mute state handlers are not supported");
|
||||
this.handler$.next(handler);
|
||||
}
|
||||
|
||||
public unsetHandler(): void {
|
||||
logger.debug(`MuteState[${this.description}]: removing handler`);
|
||||
this.handler$.next(defaultHandler);
|
||||
}
|
||||
|
||||
@@ -77,16 +79,19 @@ export class MuteState<Label, Selected> {
|
||||
this.enabledByDefault$,
|
||||
(canControlDevices, enabledByDefault) => {
|
||||
logger.info(
|
||||
`MuteState: canControlDevices: ${canControlDevices}, enabled by default: ${enabledByDefault}`,
|
||||
`MuteState[${this.description}]: canControlDevices: ${canControlDevices}, enabled by default: ${enabledByDefault}`,
|
||||
);
|
||||
if (!canControlDevices) {
|
||||
logger.info(
|
||||
`MuteState: devices connected: ${canControlDevices}, disabling`,
|
||||
`MuteState[${this.description}]: devices connected: ${canControlDevices}, disabling`,
|
||||
);
|
||||
// We need to sync the mute state with the handler
|
||||
// to ensure nothing is beeing published.
|
||||
this.handler$.value(false).catch((err) => {
|
||||
logger.error("MuteState-disable: handler error", err);
|
||||
logger.error(
|
||||
"MuteState[${this.description}] disable: handler error",
|
||||
err,
|
||||
);
|
||||
});
|
||||
return { enabled$: of(false), set: null, toggle: null };
|
||||
}
|
||||
@@ -102,12 +107,18 @@ export class MuteState<Label, Selected> {
|
||||
let syncing = false;
|
||||
|
||||
const sync = async (): Promise<void> => {
|
||||
if (enabled === latestDesired) syncing = false;
|
||||
else {
|
||||
if (enabled === latestDesired) {
|
||||
syncing = false;
|
||||
} else {
|
||||
const previouslyEnabled = enabled;
|
||||
enabled = await firstValueFrom(
|
||||
this.handler$.pipe(
|
||||
switchMap(async (handler) => handler(latestDesired)),
|
||||
switchMap(async (handler) => {
|
||||
logger.debug(
|
||||
`MuteState[${this.description}]: syncing to ${latestDesired}`,
|
||||
);
|
||||
return handler(latestDesired);
|
||||
}),
|
||||
),
|
||||
);
|
||||
if (enabled === previouslyEnabled) {
|
||||
@@ -117,7 +128,10 @@ export class MuteState<Label, Selected> {
|
||||
syncing = true;
|
||||
sync().catch((err) => {
|
||||
// TODO: better error handling
|
||||
logger.error("MuteState: handler error", err);
|
||||
logger.error(
|
||||
"MuteState[${this.description}]: handler error",
|
||||
err,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -129,7 +143,10 @@ export class MuteState<Label, Selected> {
|
||||
syncing = true;
|
||||
sync().catch((err) => {
|
||||
// TODO: better error handling
|
||||
logger.error("MuteState: handler error", err);
|
||||
logger.error(
|
||||
"MuteState[${this.description}]: handler error",
|
||||
err,
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -158,6 +175,8 @@ export class MuteState<Label, Selected> {
|
||||
);
|
||||
|
||||
public constructor(
|
||||
// A description for logging purposes
|
||||
private readonly description: string,
|
||||
private readonly scope: ObservableScope,
|
||||
private readonly device: MediaDevice<Label, Selected>,
|
||||
private readonly joined$: Observable<boolean>,
|
||||
@@ -189,6 +208,7 @@ export class MuteStates {
|
||||
);
|
||||
|
||||
public readonly audio = new MuteState(
|
||||
"audio-mutestate",
|
||||
this.scope,
|
||||
this.mediaDevices.audioInput,
|
||||
this.joined$,
|
||||
@@ -196,6 +216,7 @@ export class MuteStates {
|
||||
constant(false),
|
||||
);
|
||||
public readonly video = new MuteState(
|
||||
"video-mutestate",
|
||||
this.scope,
|
||||
this.mediaDevices.videoInput,
|
||||
this.joined$,
|
||||
|
||||
Reference in New Issue
Block a user