mirror of
https://gitcode.com/GitHub_Trending/ji/jitsi-meet.git
synced 2026-05-22 19:17:47 +00:00
Use the curstom _switchCamera API provided by react-native-webrtc to toggle the camera instead of destroying the current track and creating a new one. _switchCamera is implemented at a low level, so the track perceives no changes, thus being a lot faster and less involved since the capturer doesn't need to be destroyed and re-created. In addition, don't mirror the video for the back camera. Ref: https://github.com/oney/react-native-webrtc/pull/235
105 lines
2.5 KiB
JavaScript
105 lines
2.5 KiB
JavaScript
/* @flow */
|
|
|
|
import type { Dispatch } from 'redux';
|
|
|
|
import {
|
|
SET_AUDIO_MUTED,
|
|
SET_CAMERA_FACING_MODE,
|
|
SET_VIDEO_MUTED,
|
|
TOGGLE_CAMERA_FACING_MODE
|
|
} from './actionTypes';
|
|
import { CAMERA_FACING_MODE } from './constants';
|
|
|
|
/**
|
|
* Action to set the muted state of the local audio.
|
|
*
|
|
* @param {boolean} muted - True if the local audio is to be muted or false if
|
|
* the local audio is to be unmuted.
|
|
* @returns {{
|
|
* type: SET_AUDIO_MUTED,
|
|
* muted: boolean
|
|
* }}
|
|
*/
|
|
export function setAudioMuted(muted: boolean) {
|
|
return {
|
|
type: SET_AUDIO_MUTED,
|
|
muted
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Action to set the facing mode of the local camera.
|
|
*
|
|
* @param {CAMERA_FACING_MODE} cameraFacingMode - The camera facing mode to set.
|
|
* @returns {{
|
|
* type: SET_CAMERA_FACING_MODE,
|
|
* cameraFacingMode: CAMERA_FACING_MODE
|
|
* }}
|
|
*/
|
|
export function setCameraFacingMode(cameraFacingMode: CAMERA_FACING_MODE) {
|
|
return {
|
|
type: SET_CAMERA_FACING_MODE,
|
|
cameraFacingMode
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Action to set the muted state of the local video.
|
|
*
|
|
* @param {boolean} muted - True if the local video is to be muted or false if
|
|
* the local video is to be unmuted.
|
|
* @returns {{
|
|
* type: SET_VIDEO_MUTED,
|
|
* muted: boolean
|
|
* }}
|
|
*/
|
|
export function setVideoMuted(muted: boolean) {
|
|
return {
|
|
type: SET_VIDEO_MUTED,
|
|
muted
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Toggles the mute state of the local audio track(s).
|
|
*
|
|
* @returns {Function}
|
|
*/
|
|
export function toggleAudioMuted() {
|
|
return (dispatch: Dispatch<*>, getState: Function) => {
|
|
const muted = getState()['features/base/media'].audio.muted;
|
|
|
|
return dispatch(setAudioMuted(!muted));
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Toggles the camera facing mode. Most commonly, for example, mobile devices
|
|
* such as phones have a front/user-facing and a back/environment-facing
|
|
* cameras. In contrast to setCameraFacingMode, allows the toggling to be
|
|
* optimally and/or natively implemented without the overhead of separate reads
|
|
* and writes of the current/effective camera facing mode.
|
|
*
|
|
* @returns {{
|
|
* type: TOGGLE_CAMERA_FACING_MODE
|
|
* }}
|
|
*/
|
|
export function toggleCameraFacingMode() {
|
|
return {
|
|
type: TOGGLE_CAMERA_FACING_MODE
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Toggles the mute state of the local video track(s).
|
|
*
|
|
* @returns {Function}
|
|
*/
|
|
export function toggleVideoMuted() {
|
|
return (dispatch: Dispatch<*>, getState: Function) => {
|
|
const muted = getState()['features/base/media'].video.muted;
|
|
|
|
return dispatch(setVideoMuted(!muted));
|
|
};
|
|
}
|