2022-03-31 03:19:43 +08:00
|
|
|
import React, { useEffect, useState, useRef } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2023-06-14 00:26:43 +08:00
|
|
|
import { withTracker } from 'meteor/react-meteor-data';
|
|
|
|
import WakeLock from './component';
|
|
|
|
import Service from './service';
|
|
|
|
import Settings from '/imports/ui/services/settings';
|
2022-03-31 03:19:43 +08:00
|
|
|
import getFromUserSettings from '/imports/ui/services/users-settings';
|
2024-01-30 21:03:11 +08:00
|
|
|
import useUserChangedLocalSettings from '../../services/settings/hooks/useUserChangedLocalSettings';
|
2022-03-31 03:19:43 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2023-06-14 00:26:43 +08:00
|
|
|
|
|
|
|
const WakeLockContainer = (props) => {
|
2023-08-12 03:57:11 +08:00
|
|
|
if (!Service.isMobile()) return null;
|
2022-03-31 03:19:43 +08:00
|
|
|
|
|
|
|
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();
|
2022-03-31 03:19:43 +08:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (wereAudioModalsOpen && !areAudioModalsOpen && !endedAudioSetup) {
|
|
|
|
setEndedAudioSetup(true);
|
|
|
|
}
|
|
|
|
}, [areAudioModalsOpen]);
|
|
|
|
|
2024-01-30 21:03:11 +08:00
|
|
|
return endedAudioSetup ? <WakeLock setLocalSettings={setLocalSettings} {...props} /> : null;
|
2023-06-14 00:26:43 +08:00
|
|
|
};
|
|
|
|
|
2022-03-31 03:19:43 +08:00
|
|
|
WakeLockContainer.propTypes = propTypes;
|
|
|
|
WakeLockContainer.defaultProps = defaultProps;
|
|
|
|
|
2023-06-14 00:26:43 +08:00
|
|
|
export default withTracker(() => {
|
|
|
|
return {
|
|
|
|
request: Service.request,
|
|
|
|
release: Service.release,
|
2023-08-12 03:57:11 +08:00
|
|
|
wakeLockSettings: Settings.application.wakeLock,
|
2022-03-31 03:19:43 +08:00
|
|
|
areAudioModalsOpen: Session.get('audioModalIsOpen') || Session.get('inEchoTest'),
|
|
|
|
autoJoin: getFromUserSettings('bbb_auto_join_audio', APP_CONFIG.autoJoin),
|
2023-06-14 00:26:43 +08:00
|
|
|
};
|
|
|
|
})(WakeLockContainer);
|