bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/wake-lock/container.jsx
Arthurk12 c52a35834e feat(wake-lock): enable implicit activation based on the default setting
This commit removes the wake lock activation toast along with the
enable/disable buttons, implementing the wake lock implicit activation
behavior. The wake lock feature is implicitly activated if the
`defaultSettings.application.wakeLock` in the `settings.yml` file is set
true. For mobile devices that do not support the API or fail when
requesting a wake lock, toasts are raised explaining that calls will be
dropped when the screen turns off.

In cases where `defaultSettings.application.wakeLock` is set false, users
can enable the wake lock manually through the settings menu.
2023-08-11 17:42:20 -03:00

56 lines
1.6 KiB
JavaScript

import React, { useEffect, useState, useRef } from 'react';
import PropTypes from 'prop-types';
import { withTracker } from 'meteor/react-meteor-data';
import WakeLock from './component';
import Service from './service';
import Settings from '/imports/ui/services/settings';
import getFromUserSettings from '/imports/ui/services/users-settings';
const APP_CONFIG = Meteor.settings.public.app;
const propTypes = {
areAudioModalsOpen: PropTypes.bool,
autoJoin: PropTypes.bool.isRequired,
};
const defaultProps = {
areAudioModalsOpen: false,
};
function usePrevious(value) {
const ref = useRef();
useEffect(() => {
ref.current = value;
});
return ref.current;
}
const WakeLockContainer = (props) => {
if (!Service.isMobile()) return null;
const { areAudioModalsOpen, autoJoin } = props;
const wereAudioModalsOpen = usePrevious(areAudioModalsOpen);
const [endedAudioSetup, setEndedAudioSetup] = useState(false || !autoJoin);
useEffect(() => {
if (wereAudioModalsOpen && !areAudioModalsOpen && !endedAudioSetup) {
setEndedAudioSetup(true);
}
}, [areAudioModalsOpen]);
return endedAudioSetup ? <WakeLock {...props} /> : null;
};
WakeLockContainer.propTypes = propTypes;
WakeLockContainer.defaultProps = defaultProps;
export default withTracker(() => {
return {
request: Service.request,
release: Service.release,
wakeLockSettings: Settings.application.wakeLock,
areAudioModalsOpen: Session.get('audioModalIsOpen') || Session.get('inEchoTest'),
autoJoin: getFromUserSettings('bbb_auto_join_audio', APP_CONFIG.autoJoin),
};
})(WakeLockContainer);