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';
|
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';
|
2024-05-18 04:33:52 +08:00
|
|
|
import useSettings from '../../services/settings/hooks/useSettings';
|
|
|
|
import { SETTINGS } from '../../services/settings/enums';
|
2024-06-06 21:50:03 +08:00
|
|
|
import { useStorageKey } from '../../services/storage/hooks';
|
2022-03-31 03:19:43 +08:00
|
|
|
|
|
|
|
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;
|
2024-06-11 22:41:05 +08:00
|
|
|
const APP_CONFIG = window.meetingClientSettings.public.app;
|
2024-06-06 21:50:03 +08:00
|
|
|
const { autoJoin } = props;
|
|
|
|
const inEchoTest = useStorageKey('inEchoTest');
|
|
|
|
const audioModalIsOpen = useStorageKey('audioModalIsOpen');
|
|
|
|
const areAudioModalsOpen = audioModalIsOpen || inEchoTest;
|
2022-03-31 03:19:43 +08:00
|
|
|
const wereAudioModalsOpen = usePrevious(areAudioModalsOpen);
|
|
|
|
const [endedAudioSetup, setEndedAudioSetup] = useState(false || !autoJoin);
|
2024-01-30 21:03:11 +08:00
|
|
|
const setLocalSettings = useUserChangedLocalSettings();
|
2024-05-18 04:33:52 +08:00
|
|
|
const { wakeLock: wakeLockSettings } = useSettings(SETTINGS.APPLICATION);
|
2022-03-31 03:19:43 +08:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (wereAudioModalsOpen && !areAudioModalsOpen && !endedAudioSetup) {
|
|
|
|
setEndedAudioSetup(true);
|
|
|
|
}
|
|
|
|
}, [areAudioModalsOpen]);
|
|
|
|
|
2024-05-18 04:33:52 +08:00
|
|
|
return endedAudioSetup ? (
|
|
|
|
<WakeLock
|
|
|
|
setLocalSettings={setLocalSettings}
|
|
|
|
wakeLockSettings={wakeLockSettings}
|
2024-06-11 22:41:05 +08:00
|
|
|
request={Service.request}
|
|
|
|
release={Service.release}
|
|
|
|
autoJoin={getFromUserSettings('bbb_auto_join_audio', APP_CONFIG.autoJoin)}
|
2024-06-06 21:50:03 +08:00
|
|
|
areAudioModalsOpen={areAudioModalsOpen}
|
2024-05-18 04:33:52 +08:00
|
|
|
{...props}
|
|
|
|
/>
|
|
|
|
) : null;
|
2023-06-14 00:26:43 +08:00
|
|
|
};
|
|
|
|
|
2022-03-31 03:19:43 +08:00
|
|
|
WakeLockContainer.propTypes = propTypes;
|
|
|
|
WakeLockContainer.defaultProps = defaultProps;
|
|
|
|
|
2024-06-11 22:41:05 +08:00
|
|
|
export default WakeLockContainer;
|