Files
upstream-jitsi-meet/react/features/pip/external-api.shared.ts
upstream-mirror 1d2bfcac0c
Some checks failed
Prosody Plugin Tests / test (push) Failing after 10m11s
Close stale issues and PRs / stale (push) Failing after 1s
snapshot of https://github.com/jitsi/jitsi-meet.git @ fd1749dd28f4138aa80234fc7f311b19aaffa0e7 (2026-09-15)
2026-09-15 15:56:32 +05:00

49 lines
1.7 KiB
TypeScript

/**
* Shared utilities for PiP feature used by external_api.js.
*
* IMPORTANT: Keep this file minimal with no heavy dependencies.
* It's bundled into external_api.min.js and we want to keep that bundle slim.
* Only import lightweight modules here.
*/
/**
* Checks if current environment is Electron.
* Inline check to avoid importing BrowserDetection and its ua-parser dependency.
*
* @returns {boolean} - True if running in Electron.
*/
function isElectron(): boolean {
return navigator.userAgent.includes('Electron');
}
/**
* Checks if PiP is enabled based on config and environment.
*
* Honors the config it is given, but when `enableBrowserPiP` is absent it deliberately stays
* permissive: the external API evaluates this against only the embedder-provided config, never
* the deployment's server-side config, so applying the opt-in default here would silently
* disable embedded auto-PiP for deployments that opt in server-side. The authoritative opt-in
* default (an absent flag counts as disabled) is applied by `shouldShowPiP()` inside the client,
* where the merged config is available — an over-approximating embedder only costs a no-op
* show-PiP request that the client refuses.
*
* @param {Object} pipConfig - The pip config object.
* @returns {boolean} - True if PiP is enabled.
*/
export function isPiPEnabled(pipConfig?: { disabled?: boolean; enableBrowserPiP?: boolean; }): boolean {
if (pipConfig?.disabled) {
return false;
}
if (isElectron()) {
return true;
}
if (pipConfig?.enableBrowserPiP === false) {
return false;
}
return 'documentPictureInPicture' in window
|| Boolean(document.pictureInPictureEnabled);
}