Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(external_api): Add command for toggling camera on mobile web

Mihai-Andrei Uscat1ad40de487c8
diff --git a/modules/API/API.js b/modules/API/API.js
index 9e9d17e506..8fad09830b 100644
--- a/modules/API/API.js
+++ b/modules/API/API.js
@@ -23,6 +23,7 @@ import {
pinParticipant,
kickParticipant
} from '../../react/features/base/participants';
+import { isToggleCameraEnabled, toggleCamera } from '../../react/features/base/tracks';
import { setPrivateMessageRecipient } from '../../react/features/chat/actions';
import { openChat } from '../../react/features/chat/actions.web';
import {
@@ -169,6 +170,13 @@ function initCommands() {
sendAnalytics(createApiEvent('film.strip.toggled'));
APP.UI.toggleFilmstrip();
},
+ 'toggle-camera': () => {
+ if (!isToggleCameraEnabled(APP.store.getState())) {
+ return;
+ }
+
+ APP.store.dispatch(toggleCamera());
+ },
'toggle-chat': () => {
sendAnalytics(createApiEvent('chat.toggled'));
APP.UI.toggleChat();
diff --git a/modules/API/external/external_api.js b/modules/API/external/external_api.js
index 9189d6f31b..37852b20ee 100644
--- a/modules/API/external/external_api.js
+++ b/modules/API/external/external_api.js
@@ -51,6 +51,7 @@ const commands = {
subject: 'subject',
submitFeedback: 'submit-feedback',
toggleAudio: 'toggle-audio',
+ toggleCamera: 'toggle-camera',
toggleChat: 'toggle-chat',
toggleFilmStrip: 'toggle-film-strip',
toggleRaiseHand: 'toggle-raise-hand',
diff --git a/react/features/base/tracks/functions.js b/react/features/base/tracks/functions.js
index 31c45d061c..d96e3a23ea 100644
--- a/react/features/base/tracks/functions.js
+++ b/react/features/base/tracks/functions.js
@@ -1,7 +1,9 @@
/* global APP */
+import { isMobileBrowser } from '../environment/utils';
import JitsiMeetJS, { JitsiTrackErrors, browser } from '../lib-jitsi-meet';
import { MEDIA_TYPE, VIDEO_TYPE, setAudioMuted } from '../media';
+import { toState } from '../redux';
import {
getUserSelectedCameraDeviceId,
getUserSelectedMicDeviceId
@@ -475,3 +477,16 @@ export function setTrackMuted(track, muted) {
}
});
}
+
+/**
+ * Determines whether toggle camera should be enabled or not.
+ *
+ * @param {Function|Object} stateful - The redux store or {@code getState} function.
+ * @returns {boolean} - Whether toggle camera should be enabled.
+ */
+export function isToggleCameraEnabled(stateful) {
+ const state = toState(stateful);
+ const { videoInput } = state['features/base/devices'].availableDevices;
+
+ return isMobileBrowser() && videoInput.length > 1;
+}
diff --git a/react/features/toolbox/components/web/ToggleCameraButton.js b/react/features/toolbox/components/web/ToggleCameraButton.js
index 43c2b69bd7..60c2a07924 100644
--- a/react/features/toolbox/components/web/ToggleCameraButton.js
+++ b/react/features/toolbox/components/web/ToggleCameraButton.js
@@ -1,11 +1,10 @@
// @flow
-import { isMobileBrowser } from '../../../base/environment/utils';
import { translate } from '../../../base/i18n';
import { IconCameraRefresh } from '../../../base/icons';
import { connect } from '../../../base/redux';
import { AbstractButton, type AbstractButtonProps } from '../../../base/toolbox/components';
-import { isLocalCameraTrackMuted, toggleCamera } from '../../../base/tracks';
+import { isLocalCameraTrackMuted, isToggleCameraEnabled, toggleCamera } from '../../../base/tracks';
/**
* The type of the React {@code Component} props of {@link ToggleCameraButton}.
@@ -65,12 +64,11 @@ class ToggleCameraButton extends AbstractButton<Props, any> {
function mapStateToProps(state): Object {
const { enabled: audioOnly } = state['features/base/audio-only'];
const tracks = state['features/base/tracks'];
- const { videoInput } = state['features/base/devices'].availableDevices;
return {
_audioOnly: Boolean(audioOnly),
_videoMuted: isLocalCameraTrackMuted(tracks),
- visible: isMobileBrowser() && videoInput.length > 1
+ visible: isToggleCameraEnabled(state)
};
}