diff --git a/react/features/rtcstats/functions.js b/react/features/rtcstats/functions.js new file mode 100644 index 000000000..d980da375 --- /dev/null +++ b/react/features/rtcstats/functions.js @@ -0,0 +1,21 @@ +// @flow + +import { toState } from '../base/redux'; + +/** + * Checks whether rtcstats is enabled or not. + * + * @param {Function|Object} stateful - The redux store or {@code getState} function. + * @returns {boolean} + */ +export function isRtcstatsEnabled(stateful: Function | Object) { + // TODO: Remove when rtcstats is fully cimpatible with mobile. + if (navigator.product === 'ReactNative') { + return false; + } + + const state = toState(stateful); + const config = state['features/base/config']; + + return config?.analytics?.rtcstatsEnabled ?? false; +} diff --git a/react/features/rtcstats/middleware.js b/react/features/rtcstats/middleware.js index 73c5f40ab..0d816ba72 100644 --- a/react/features/rtcstats/middleware.js +++ b/react/features/rtcstats/middleware.js @@ -9,6 +9,7 @@ import { getLocalParticipant } from '../base/participants'; import { MiddlewareRegistry } from '../base/redux'; import RTCStats from './RTCStats'; +import { isRtcstatsEnabled } from './functions'; import logger from './logger'; /** @@ -25,7 +26,7 @@ MiddlewareRegistry.register(store => next => action => { switch (action.type) { case LIB_WILL_INIT: { - if (analytics.rtcstatsEnabled) { + if (isRtcstatsEnabled(state)) { // RTCStats "proxies" WebRTC functions such as GUM and RTCPeerConnection by rewriting the global // window functions. Because lib-jitsi-meet uses references to those functions that are taken on // init, we need to add these proxies before it initializes, otherwise lib-jitsi-meet will use the @@ -47,7 +48,7 @@ MiddlewareRegistry.register(store => next => action => { break; } case CONFERENCE_JOINED: { - if (analytics.rtcstatsEnabled && RTCStats.isInitialized()) { + if (isRtcstatsEnabled(state) && RTCStats.isInitialized()) { // Once the conference started connect to the rtcstats server and send data. try { RTCStats.connect();