Preload media devices to avoid later delay
Co-authored-by: ayumi yu <ayumi@signal.org>
This commit is contained in:
parent
6d216a3eca
commit
59a4f237fd
5 changed files with 43 additions and 0 deletions
|
@ -2653,6 +2653,15 @@ async function ensureFilePermissions(onlyFiles?: Array<string>) {
|
|||
getLogger().info(`Finish ensuring permissions in ${Date.now() - start}ms`);
|
||||
}
|
||||
|
||||
ipc.handle('get-media-access-status', async (_event, value) => {
|
||||
// This function is not supported on Linux
|
||||
if (!systemPreferences.getMediaAccessStatus) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return systemPreferences.getMediaAccessStatus(value);
|
||||
});
|
||||
|
||||
ipc.handle('get-auto-launch', async () => {
|
||||
return app.getLoginItemSettings(await getDefaultLoginItemSettings())
|
||||
.openAtLogin;
|
||||
|
|
|
@ -383,6 +383,10 @@ export class CallingClass {
|
|||
});
|
||||
|
||||
void this.cleanExpiredGroupCallRingsAndLoop();
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
drop(this.enumerateMediaDevices());
|
||||
}
|
||||
}
|
||||
|
||||
private attemptToGiveOurServiceIdToRingRtc(): void {
|
||||
|
@ -2433,6 +2437,23 @@ export class CallingClass {
|
|||
void this.cleanExpiredGroupCallRingsAndLoop();
|
||||
}, CLEAN_EXPIRED_GROUP_CALL_RINGS_INTERVAL);
|
||||
}
|
||||
|
||||
// MacOS: Preload devices to work around delay when first entering call lobby
|
||||
// https://bugs.chromium.org/p/chromium/issues/detail?id=1287628
|
||||
private async enumerateMediaDevices(): Promise<void> {
|
||||
try {
|
||||
const microphoneStatus = await window.IPC.getMediaAccessStatus(
|
||||
'microphone'
|
||||
);
|
||||
if (microphoneStatus !== 'granted') {
|
||||
return;
|
||||
}
|
||||
|
||||
drop(window.navigator.mediaDevices.enumerateDevices());
|
||||
} catch (error) {
|
||||
log.error('enumerateMediaDevices failed:', Errors.toLogFormat(error));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const calling = new CallingClass();
|
||||
|
|
|
@ -108,6 +108,9 @@ export type IPCEventsCallbacksType = {
|
|||
deleteAllMyStories: () => Promise<void>;
|
||||
editCustomColor: (colorId: string, customColor: CustomColorType) => void;
|
||||
getConversationsWithCustomColor: (x: string) => Array<ConversationType>;
|
||||
getMediaAccessStatus: (
|
||||
mediaType: 'screen' | 'microphone' | 'camera'
|
||||
) => Promise<string | unknown>;
|
||||
installStickerPack: (packId: string, key: string) => Promise<void>;
|
||||
isFormattingFlagEnabled: () => boolean;
|
||||
isPhoneNumberSharingEnabled: () => boolean;
|
||||
|
@ -609,6 +612,11 @@ export function createIPCEvents(
|
|||
showWhatsNewModal();
|
||||
},
|
||||
|
||||
getMediaAccessStatus: async (
|
||||
mediaType: 'screen' | 'microphone' | 'camera'
|
||||
) => {
|
||||
return window.IPC.getMediaAccessStatus(mediaType);
|
||||
},
|
||||
getMediaPermissions: window.IPC.getMediaPermissions,
|
||||
getMediaCameraPermissions: window.IPC.getMediaCameraPermissions,
|
||||
|
||||
|
|
3
ts/window.d.ts
vendored
3
ts/window.d.ts
vendored
|
@ -66,6 +66,9 @@ export type IPCType = {
|
|||
};
|
||||
drawAttention: () => void;
|
||||
getAutoLaunch: () => Promise<boolean>;
|
||||
getMediaAccessStatus: (
|
||||
mediaType: 'screen' | 'microphone' | 'camera'
|
||||
) => Promise<string | undefined>;
|
||||
getMediaCameraPermissions: () => Promise<boolean>;
|
||||
getMediaPermissions: () => Promise<boolean>;
|
||||
logAppLoadedEvent?: (options: { processedCount?: number }) => void;
|
||||
|
|
|
@ -86,6 +86,8 @@ const IPC: IPCType = {
|
|||
ipc.send('draw-attention');
|
||||
},
|
||||
getAutoLaunch: () => ipc.invoke('get-auto-launch'),
|
||||
getMediaAccessStatus: mediaType =>
|
||||
ipc.invoke('get-media-access-status', mediaType),
|
||||
getMediaPermissions: () => ipc.invoke('settings:get:mediaPermissions'),
|
||||
getMediaCameraPermissions: () =>
|
||||
ipc.invoke('settings:get:mediaCameraPermissions'),
|
||||
|
|
Loading…
Reference in a new issue