Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(pip): add debug logging for better PiP flow observability

Hristo Terezov1f1dbb2517dd
diff --git a/modules/API/API.js b/modules/API/API.js
index 7c87172a96..19dfb2276d 100755
--- a/modules/API/API.js
+++ b/modules/API/API.js
@@ -2325,6 +2325,7 @@ class API {
* @returns {void}
*/
notifyPictureInPictureRequested() {
+ logger.debug('Sending _pip-requested event to External API');
this._sendEvent({
name: '_pip-requested'
});
@@ -2336,6 +2337,7 @@ class API {
* @returns {void}
*/
notifyPictureInPictureEntered() {
+ logger.debug('Sending pip-entered event to External API');
this._sendEvent({
name: 'pip-entered'
});
@@ -2347,6 +2349,7 @@ class API {
* @returns {void}
*/
notifyPictureInPictureLeft() {
+ logger.debug('Sending pip-left event to External API');
this._sendEvent({
name: 'pip-left'
});
diff --git a/react/features/pip/actions.ts b/react/features/pip/actions.ts
index 183dbbae02..e43802bffc 100644
--- a/react/features/pip/actions.ts
+++ b/react/features/pip/actions.ts
@@ -68,6 +68,8 @@ export function toggleVideoFromPiP() {
*/
export function exitPiP() {
return (dispatch: IStore['dispatch']) => {
+ logger.debug('exitPiP called');
+
if (document.pictureInPictureElement) {
document.exitPictureInPicture()
.then(() => {
@@ -95,6 +97,8 @@ export function handleWindowBlur(videoElement: HTMLVideoElement) {
const state = getState();
const isPiPActive = state['features/pip']?.isPiPActive;
+ logger.debug(`Window blur detected, isPiPActive=${isPiPActive}`);
+
if (!isPiPActive) {
enterPiP(videoElement);
}
@@ -112,6 +116,8 @@ export function handleWindowFocus() {
const state = getState();
const isPiPActive = state['features/pip']?.isPiPActive;
+ logger.debug(`Window focus detected, isPiPActive=${isPiPActive}`);
+
if (isPiPActive) {
dispatch(exitPiP());
}
@@ -160,17 +166,24 @@ export function showPiP() {
return (_dispatch: IStore['dispatch'], getState: IStore['getState']) => {
const state = getState();
const isPiPActive = state['features/pip']?.isPiPActive;
+ const _shouldShowPip = shouldShowPiP(state);
+
+ logger.debug(`showPiP called, shouldShow=${_shouldShowPip}, isPiPActive=${isPiPActive}`);
- if (!shouldShowPiP(state)) {
+ if (!_shouldShowPip) {
return;
}
if (!isPiPActive) {
const videoElement = document.getElementById('pipVideo') as HTMLVideoElement;
- if (videoElement) {
- enterPiP(videoElement);
+ if (!videoElement) {
+ logger.warn('showPiP: pipVideo element not found');
+
+ return;
}
+
+ enterPiP(videoElement);
}
};
}
@@ -186,6 +199,8 @@ export function hidePiP() {
const state = getState();
const isPiPActive = state['features/pip']?.isPiPActive;
+ logger.debug(`hidePiP called, isPiPActive=${isPiPActive}`);
+
if (isPiPActive) {
dispatch(exitPiP());
}
diff --git a/react/features/pip/functions.ts b/react/features/pip/functions.ts
index b5d69855e7..119e777e7c 100644
--- a/react/features/pip/functions.ts
+++ b/react/features/pip/functions.ts
@@ -311,8 +311,12 @@ export function requestPictureInPicture() {
// Wait for metadata to load before requesting PiP.
video.addEventListener('loadedmetadata', () => {
+ logger.debug(`Calling video.requestPictureInPicture(), readyState=${video.readyState}`);
+
// @ts-ignore - requestPictureInPicture is not yet in all TypeScript definitions.
- video.requestPictureInPicture().catch((err: Error) => {
+ video.requestPictureInPicture().then(() => {
+ logger.debug('video.requestPictureInPicture() succeeded');
+ }).catch((err: Error) => {
logger.error(`Error while requesting PiP after metadata loaded: ${err.message}`);
}).finally(() => {
// Currently Electron will only pass the requests and execute requestPictureInPicture but
@@ -326,8 +330,12 @@ export function requestPictureInPicture() {
return;
}
+ logger.debug(`Calling video.requestPictureInPicture(), readyState=${video.readyState}`);
+
// @ts-ignore - requestPictureInPicture is not yet in all TypeScript definitions.
- video.requestPictureInPicture().catch((err: Error) => {
+ video.requestPictureInPicture().then(() => {
+ logger.debug('video.requestPictureInPicture() succeeded');
+ }).catch((err: Error) => {
logger.error(`Error while requesting PiP: ${err.message}`);
}).finally(() => {
// Currently Electron will only pass the requests and execute requestPictureInPicture but
diff --git a/react/features/pip/subscriber.ts b/react/features/pip/subscriber.ts
index 2cbe509e83..68c16486dd 100644
--- a/react/features/pip/subscriber.ts
+++ b/react/features/pip/subscriber.ts
@@ -5,6 +5,7 @@ import { isLocalTrackMuted } from '../base/tracks/functions.any';
import { getElectronGlobalNS } from '../base/util/helpers';
import { requestPictureInPicture, shouldShowPiP, updateMediaSessionState } from './functions';
+import logger from './logger';
/**
* Listens to audio and video mute state changes when PiP is active
@@ -51,9 +52,11 @@ StateListenerRegistry.register(
if (_shouldShowPiP) {
// Expose requestPictureInPicture for Electron main process.
if (!electronNS.requestPictureInPicture) {
+ logger.debug('Exposing requestPictureInPicture to Electron namespace');
electronNS.requestPictureInPicture = requestPictureInPicture;
}
} else if (typeof electronNS.requestPictureInPicture === 'function') {
+ logger.debug('Removing requestPictureInPicture from Electron namespace (PiP disabled)');
delete electronNS.requestPictureInPicture;
}
}