mediasfu-reactnative
Version:
MediaSFU Prebuilt React Native SDK
80 lines • 3.1 kB
JavaScript
/**
* Switches the user's video device with alternate logic, taking into account recording state and camera access permissions.
*
* @param {SwitchVideoAltOptions} options - The parameters object containing necessary variables.
* @returns {Promise<void>}
*
* @example
* ```typescript
* switchVideoAlt({
* parameters: {
* recordStarted: true,
* recordResumed: false,
* recordStopped: false,
* recordPaused: false,
* recordingMediaOptions: 'video',
* videoAlreadyOn: true,
* currentFacingMode: 'user',
* prevFacingMode: 'environment',
* allowed: true,
* audioOnlyRoom: false,
* updateCurrentFacingMode: (mode) => setCurrentFacingMode(mode),
* updatePrevFacingMode: (mode) => setPrevFacingMode(mode),
* updateIsMediaSettingsModalVisible: (isVisible) => setMediaSettingsModal(isVisible),
* showAlert: (alertOptions) => showAlert(alertOptions),
* switchUserVideoAlt: switchUserVideoAltFunction,
* }
* });
* ```
*/
export const switchVideoAlt = async ({ parameters }) => {
let { recordStarted, recordResumed, recordStopped, recordPaused, recordingMediaOptions, videoAlreadyOn, currentFacingMode, prevFacingMode, allowed, audioOnlyRoom, updateCurrentFacingMode, updateIsMediaSettingsModalVisible, updatePrevFacingMode, showAlert,
// media functions
switchUserVideoAlt, } = parameters;
if (audioOnlyRoom) {
showAlert === null || showAlert === void 0 ? void 0 : showAlert({
message: 'You cannot turn on your camera in an audio-only event.',
type: 'danger',
duration: 3000,
});
return;
}
let checkoff = false;
if ((recordStarted || recordResumed) && !recordStopped && !recordPaused && recordingMediaOptions === 'video') {
checkoff = true;
}
if (!allowed) {
showAlert === null || showAlert === void 0 ? void 0 : showAlert({
message: 'Allow access to your camera by starting it for the first time.',
type: 'danger',
duration: 3000,
});
return;
}
if (checkoff) {
if (videoAlreadyOn) {
showAlert === null || showAlert === void 0 ? void 0 : showAlert({
message: 'Please turn off your video before switching.',
type: 'danger',
duration: 3000,
});
return;
}
}
else if (!videoAlreadyOn) {
showAlert === null || showAlert === void 0 ? void 0 : showAlert({
message: 'Please turn on your video before switching.',
type: 'danger',
duration: 3000,
});
return;
}
// Camera switching logic
prevFacingMode = currentFacingMode;
updatePrevFacingMode(prevFacingMode);
currentFacingMode = currentFacingMode === 'environment' ? 'user' : 'environment';
updateCurrentFacingMode(currentFacingMode);
updateIsMediaSettingsModalVisible(false);
await switchUserVideoAlt({ videoPreference: currentFacingMode, checkoff, parameters });
};
//# sourceMappingURL=switchVideoAlt.js.map