UNPKG

@100mslive/react-native-room-kit

Version:

100ms Room Kit provides simple & easy to use UI components to build Live Streaming & Video Conferencing experiences in your apps.

39 lines 2.46 kB
import { WaveIcon } from '../Icons'; import React from 'react'; import { PressableIcon } from './PressableIcon'; import { styles } from './styles'; import { useSelector } from 'react-redux'; import { useHMSLayoutConfig } from '../hooks-util'; export const HMSManageNoiseCancellation = () => { const noiseCancellationPlugin = useSelector(state => state.hmsStates.noiseCancellationPlugin); const [isNoiseCancellationEnabled, setIsNoiseCancellationEnabled] = React.useState(false); const enabledByDefault = useHMSLayoutConfig(layoutConfig => { var _layoutConfig$screens; return (layoutConfig === null || layoutConfig === void 0 || (_layoutConfig$screens = layoutConfig.screens) === null || _layoutConfig$screens === void 0 || (_layoutConfig$screens = _layoutConfig$screens.preview) === null || _layoutConfig$screens === void 0 || (_layoutConfig$screens = _layoutConfig$screens.default) === null || _layoutConfig$screens === void 0 || (_layoutConfig$screens = _layoutConfig$screens.elements) === null || _layoutConfig$screens === void 0 || (_layoutConfig$screens = _layoutConfig$screens.noise_cancellation) === null || _layoutConfig$screens === void 0 ? void 0 : _layoutConfig$screens.enabled_by_default) || false; }); React.useEffect(() => { if (enabledByDefault) { noiseCancellationPlugin === null || noiseCancellationPlugin === void 0 || noiseCancellationPlugin.enable(); setIsNoiseCancellationEnabled(true); } }, []); const handleButtonPress = async () => { const isAvailable = await (noiseCancellationPlugin === null || noiseCancellationPlugin === void 0 ? void 0 : noiseCancellationPlugin.isNoiseCancellationAvailable()); if (!noiseCancellationPlugin && isAvailable) { console.error('Noise Cancellation Plugin not found'); return; } if (isNoiseCancellationEnabled) { await (noiseCancellationPlugin === null || noiseCancellationPlugin === void 0 ? void 0 : noiseCancellationPlugin.disable()); } else { await (noiseCancellationPlugin === null || noiseCancellationPlugin === void 0 ? void 0 : noiseCancellationPlugin.enable()); } setIsNoiseCancellationEnabled(!isNoiseCancellationEnabled); }; return /*#__PURE__*/React.createElement(PressableIcon, { style: styles.noiseButton, onPress: handleButtonPress, active: isNoiseCancellationEnabled }, /*#__PURE__*/React.createElement(WaveIcon, null)); }; //# sourceMappingURL=HMSManageNoiseCancellation.js.map