Skip to content

Commit

Permalink
Simplify logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jrose-signal authored and indutny-signal committed Sep 7, 2022
1 parent 56ffd7b commit 618a772
Showing 1 changed file with 53 additions and 6 deletions.
59 changes: 53 additions & 6 deletions ts/services/calling.ts
Expand Up @@ -133,6 +133,40 @@ function isScreenSource(source: PresentedSource): boolean {
return source.id.startsWith('screen');
}

function truncateForLogging(name: string | undefined): string | undefined {
if (!name || name.length <= 4) {
return name;
}
return `${name.slice(0, 2)}...${name.slice(-2)}`;
}

function cleanForLogging(settings?: MediaDeviceSettings): unknown {
if (!settings) {
return settings;
}

return {
availableCameras: settings.availableCameras.map(camera => {
const { deviceId, kind, label, groupId } = camera;
return {
deviceId,
kind,
label: truncateForLogging(label),
groupId,
};
}),
availableMicrophones: settings.availableMicrophones.map(device => {
return truncateForLogging(device.name);
}),
availableSpeakers: settings.availableSpeakers.map(device => {
return truncateForLogging(device.name);
}),
selectedMicrophone: truncateForLogging(settings.selectedMicrophone?.name),
selectedSpeaker: truncateForLogging(settings.selectedSpeaker?.name),
selectedCamera: settings.selectedCamera,
};
}

function translateSourceName(
i18n: LocalizerType,
source: PresentedSource
Expand Down Expand Up @@ -1324,8 +1358,8 @@ export class CallingClass {
) {
log.info(
'MediaDevice: available devices changed (from->to)',
this.lastMediaDeviceSettings,
newSettings
cleanForLogging(this.lastMediaDeviceSettings),
cleanForLogging(newSettings)
);

await this.selectPreferredDevices(newSettings);
Expand Down Expand Up @@ -1398,13 +1432,21 @@ export class CallingClass {
}

setPreferredMicrophone(device: AudioDevice): void {
log.info('MediaDevice: setPreferredMicrophone', device);
log.info(
'MediaDevice: setPreferredMicrophone',
device.index,
truncateForLogging(device.name)
);
window.Events.setPreferredAudioInputDevice(device);
RingRTC.setAudioInput(device.index);
}

setPreferredSpeaker(device: AudioDevice): void {
log.info('MediaDevice: setPreferredSpeaker', device);
log.info(
'MediaDevice: setPreferredSpeaker',
device.index,
truncateForLogging(device.name)
);
window.Events.setPreferredAudioOutputDevice(device);
RingRTC.setAudioOutput(device.index);
}
Expand Down Expand Up @@ -1532,13 +1574,18 @@ export class CallingClass {
if (settings.selectedMicrophone) {
log.info(
'MediaDevice: selecting microphone',
settings.selectedMicrophone
settings.selectedMicrophone.index,
truncateForLogging(settings.selectedMicrophone.name)
);
RingRTC.setAudioInput(settings.selectedMicrophone.index);
}

if (settings.selectedSpeaker) {
log.info('MediaDevice: selecting speaker', settings.selectedSpeaker);
log.info(
'MediaDevice: selecting speaker',
settings.selectedSpeaker.index,
truncateForLogging(settings.selectedSpeaker.name)
);
RingRTC.setAudioOutput(settings.selectedSpeaker.index);
}
}
Expand Down

0 comments on commit 618a772

Please sign in to comment.