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(compute-pressure) monitor cpu pressure (#13645)

Mihaela Dumitru4461196ba3ab
diff --git a/globals.d.ts b/globals.d.ts
index 3b5a68941f..eda5cbea1b 100644
--- a/globals.d.ts
+++ b/globals.d.ts
@@ -19,6 +19,8 @@ declare global {
interfaceConfig?: any;
JitsiMeetJS?: any;
JitsiMeetElectron?: any;
+ PressureObserver?: any;
+ PressureRecord?: any;
// selenium tests handler
_sharedVideoPlayer: any;
alwaysOnTop: { api: any };
diff --git a/globals.native.d.ts b/globals.native.d.ts
index 79e8352eec..e465b77fff 100644
--- a/globals.native.d.ts
+++ b/globals.native.d.ts
@@ -17,6 +17,8 @@ interface IWindow {
innerWidth: number;
interfaceConfig: any;
location: ILocation;
+ PressureObserver?: any;
+ PressureRecord?: any;
self: any;
top: any;
diff --git a/modules/API/API.js b/modules/API/API.js
index cd12dc4529..01575dcfda 100644
--- a/modules/API/API.js
+++ b/modules/API/API.js
@@ -2059,6 +2059,19 @@ class API {
});
}
+ /**
+ * Notify the external application (if API is enabled) when the compute pressure changed.
+ *
+ * @param {Array} records - The new pressure records.
+ * @returns {void}
+ */
+ notifyComputePressureChanged(records) {
+ this._sendEvent({
+ name: 'compute-pressure-changed',
+ records
+ });
+ }
+
/**
* Disposes the allocated resources.
*
diff --git a/modules/API/external/external_api.js b/modules/API/external/external_api.js
index ef2c5d69b5..a06bce3f11 100644
--- a/modules/API/external/external_api.js
+++ b/modules/API/external/external_api.js
@@ -106,6 +106,7 @@ const events = {
'browser-support': 'browserSupport',
'camera-error': 'cameraError',
'chat-updated': 'chatUpdated',
+ 'compute-pressure-changed': 'computePressureChanged',
'content-sharing-participants-changed': 'contentSharingParticipantsChanged',
'data-channel-closed': 'dataChannelClosed',
'data-channel-opened': 'dataChannelOpened',
diff --git a/react/features/app/middlewares.any.ts b/react/features/app/middlewares.any.ts
index 0399e3e6c9..a96a65e176 100644
--- a/react/features/app/middlewares.any.ts
+++ b/react/features/app/middlewares.any.ts
@@ -1,6 +1,7 @@
import '../analytics/middleware';
import '../authentication/middleware';
import '../av-moderation/middleware';
+import '../base/app/middleware';
import '../base/conference/middleware';
import '../base/config/middleware';
import '../base/jwt/middleware';
diff --git a/react/features/base/app/middleware.ts b/react/features/base/app/middleware.ts
new file mode 100644
index 0000000000..eb8c26e9e0
--- /dev/null
+++ b/react/features/base/app/middleware.ts
@@ -0,0 +1,54 @@
+import { AnyAction } from 'redux';
+
+import MiddlewareRegistry from '../../base/redux/MiddlewareRegistry';
+
+import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
+import logger from './logger';
+
+
+/**
+ * Experimental feature to monitor CPU pressure.
+ */
+let pressureObserver: typeof window.PressureObserver;
+
+/**
+ * Middleware which intercepts app actions to handle changes to the related state.
+ *
+ * @param {Store} store - The redux store.
+ * @returns {Function}
+ */
+MiddlewareRegistry.register(() => (next: Function) => async (action: AnyAction) => {
+
+ switch (action.type) {
+ case APP_WILL_MOUNT: {
+ if ('PressureObserver' in globalThis) {
+ pressureObserver = new window.PressureObserver(
+ (records: typeof window.PressureRecord) => {
+ logger.info('Compute pressure state changed:', JSON.stringify(records));
+ if (typeof APP !== 'undefined') {
+ APP.API.notifyComputePressureChanged(records);
+ }
+ },
+ { sampleRate: 1 }
+ );
+
+ try {
+ pressureObserver
+ .observe('cpu')
+ .catch((e: any) => logger.error('CPU pressure observer failed to start', e));
+ } catch (e: any) {
+ logger.error('CPU pressure observer failed to start', e);
+ }
+ }
+ break;
+ }
+ case APP_WILL_UNMOUNT: {
+ if (pressureObserver) {
+ pressureObserver.unobserve('cpu');
+ }
+ break;
+ }
+ }
+
+ return next(action);
+});
diff --git a/webpack.config.js b/webpack.config.js
index 297070fae4..07b9715c0f 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -339,7 +339,7 @@ module.exports = (_env, argv) => {
...config.plugins,
...getBundleAnalyzerPlugin(analyzeBundle, 'external_api')
],
- performance: getPerformanceHints(perfHintOptions, 35 * 1024)
+ performance: getPerformanceHints(perfHintOptions, 40 * 1024)
}),
Object.assign({}, config, {
entry: {