bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/wake-lock/container.jsx
Arthurk12 e5aa8cb0e0 refactor(wake-lock): change settings flags
Changes enableWakeLock => wakeLock.enabled to follow the pattern used by
other features and wakeLockEnabled => wakeLock. Also make the necessary
code changes to reference this new settings flags correctly.
2023-06-14 13:38:00 -03:00

57 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.isSupported()) 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(() => {
const wakeLockSettings = Settings.application.wakeLock;
return {
request: Service.request,
release: Service.release,
wakeLockSettings,
areAudioModalsOpen: Session.get('audioModalIsOpen') || Session.get('inEchoTest'),
autoJoin: getFromUserSettings('bbb_auto_join_audio', APP_CONFIG.autoJoin),
};
})(WakeLockContainer);