bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/wake-lock/container.jsx

58 lines
1.8 KiB
React
Raw Normal View History

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';
2024-01-30 21:03:11 +08:00
import useUserChangedLocalSettings from '../../services/settings/hooks/useUserChangedLocalSettings';
const APP_CONFIG = window.meetingClientSettings.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);
2024-01-30 21:03:11 +08:00
const setLocalSettings = useUserChangedLocalSettings();
useEffect(() => {
if (wereAudioModalsOpen && !areAudioModalsOpen && !endedAudioSetup) {
setEndedAudioSetup(true);
}
}, [areAudioModalsOpen]);
2024-01-30 21:03:11 +08:00
return endedAudioSetup ? <WakeLock setLocalSettings={setLocalSettings} {...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);