Преглед изворни кода

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

j8
Mihai-Andrei Uscat пре 4 година
родитељ
комит
1ad40de487
No account linked to committer's email address

+ 8
- 0
modules/API/API.js Прегледај датотеку

@@ -23,6 +23,7 @@ import {
23 23
     pinParticipant,
24 24
     kickParticipant
25 25
 } from '../../react/features/base/participants';
26
+import { isToggleCameraEnabled, toggleCamera } from '../../react/features/base/tracks';
26 27
 import { setPrivateMessageRecipient } from '../../react/features/chat/actions';
27 28
 import { openChat } from '../../react/features/chat/actions.web';
28 29
 import {
@@ -169,6 +170,13 @@ function initCommands() {
169 170
             sendAnalytics(createApiEvent('film.strip.toggled'));
170 171
             APP.UI.toggleFilmstrip();
171 172
         },
173
+        'toggle-camera': () => {
174
+            if (!isToggleCameraEnabled(APP.store.getState())) {
175
+                return;
176
+            }
177
+
178
+            APP.store.dispatch(toggleCamera());
179
+        },
172 180
         'toggle-chat': () => {
173 181
             sendAnalytics(createApiEvent('chat.toggled'));
174 182
             APP.UI.toggleChat();

+ 1
- 0
modules/API/external/external_api.js Прегледај датотеку

@@ -51,6 +51,7 @@ const commands = {
51 51
     subject: 'subject',
52 52
     submitFeedback: 'submit-feedback',
53 53
     toggleAudio: 'toggle-audio',
54
+    toggleCamera: 'toggle-camera',
54 55
     toggleChat: 'toggle-chat',
55 56
     toggleFilmStrip: 'toggle-film-strip',
56 57
     toggleRaiseHand: 'toggle-raise-hand',

+ 15
- 0
react/features/base/tracks/functions.js Прегледај датотеку

@@ -1,7 +1,9 @@
1 1
 /* global APP */
2 2
 
3
+import { isMobileBrowser } from '../environment/utils';
3 4
 import JitsiMeetJS, { JitsiTrackErrors, browser } from '../lib-jitsi-meet';
4 5
 import { MEDIA_TYPE, VIDEO_TYPE, setAudioMuted } from '../media';
6
+import { toState } from '../redux';
5 7
 import {
6 8
     getUserSelectedCameraDeviceId,
7 9
     getUserSelectedMicDeviceId
@@ -475,3 +477,16 @@ export function setTrackMuted(track, muted) {
475 477
         }
476 478
     });
477 479
 }
480
+
481
+/**
482
+ * Determines whether toggle camera should be enabled or not.
483
+ *
484
+ * @param {Function|Object} stateful - The redux store or {@code getState} function.
485
+ * @returns {boolean} - Whether toggle camera should be enabled.
486
+ */
487
+export function isToggleCameraEnabled(stateful) {
488
+    const state = toState(stateful);
489
+    const { videoInput } = state['features/base/devices'].availableDevices;
490
+
491
+    return isMobileBrowser() && videoInput.length > 1;
492
+}

+ 2
- 4
react/features/toolbox/components/web/ToggleCameraButton.js Прегледај датотеку

@@ -1,11 +1,10 @@
1 1
 // @flow
2 2
 
3
-import { isMobileBrowser } from '../../../base/environment/utils';
4 3
 import { translate } from '../../../base/i18n';
5 4
 import { IconCameraRefresh } from '../../../base/icons';
6 5
 import { connect } from '../../../base/redux';
7 6
 import { AbstractButton, type AbstractButtonProps } from '../../../base/toolbox/components';
8
-import { isLocalCameraTrackMuted, toggleCamera } from '../../../base/tracks';
7
+import { isLocalCameraTrackMuted, isToggleCameraEnabled, toggleCamera } from '../../../base/tracks';
9 8
 
10 9
 /**
11 10
  * The type of the React {@code Component} props of {@link ToggleCameraButton}.
@@ -65,12 +64,11 @@ class ToggleCameraButton extends AbstractButton<Props, any> {
65 64
 function mapStateToProps(state): Object {
66 65
     const { enabled: audioOnly } = state['features/base/audio-only'];
67 66
     const tracks = state['features/base/tracks'];
68
-    const { videoInput } = state['features/base/devices'].availableDevices;
69 67
 
70 68
     return {
71 69
         _audioOnly: Boolean(audioOnly),
72 70
         _videoMuted: isLocalCameraTrackMuted(tracks),
73
-        visible: isMobileBrowser() && videoInput.length > 1
71
+        visible: isToggleCameraEnabled(state)
74 72
     };
75 73
 }
76 74
 

Loading…
Откажи
Сачувај