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';
|
|
|
|
|
|
|
|
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) => {
|
|
|
|
if (!Service.isSupported()) return null;
|
2022-03-31 03:19:43 +08:00
|
|
|
|
|
|
|
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;
|
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(() => {
|
2023-06-14 23:58:18 +08:00
|
|
|
const wakeLockSettings = Settings.application.wakeLock;
|
2023-06-14 00:26:43 +08:00
|
|
|
return {
|
|
|
|
request: Service.request,
|
|
|
|
release: Service.release,
|
|
|
|
wakeLockSettings,
|
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);
|