Browse Source

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

j8
Mihai-Andrei Uscat 4 years ago
parent
commit
1ad40de487
No account linked to committer's email address

+ 8
- 0
modules/API/API.js View File

23
     pinParticipant,
23
     pinParticipant,
24
     kickParticipant
24
     kickParticipant
25
 } from '../../react/features/base/participants';
25
 } from '../../react/features/base/participants';
26
+import { isToggleCameraEnabled, toggleCamera } from '../../react/features/base/tracks';
26
 import { setPrivateMessageRecipient } from '../../react/features/chat/actions';
27
 import { setPrivateMessageRecipient } from '../../react/features/chat/actions';
27
 import { openChat } from '../../react/features/chat/actions.web';
28
 import { openChat } from '../../react/features/chat/actions.web';
28
 import {
29
 import {
169
             sendAnalytics(createApiEvent('film.strip.toggled'));
170
             sendAnalytics(createApiEvent('film.strip.toggled'));
170
             APP.UI.toggleFilmstrip();
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
         'toggle-chat': () => {
180
         'toggle-chat': () => {
173
             sendAnalytics(createApiEvent('chat.toggled'));
181
             sendAnalytics(createApiEvent('chat.toggled'));
174
             APP.UI.toggleChat();
182
             APP.UI.toggleChat();

+ 1
- 0
modules/API/external/external_api.js View File

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

+ 15
- 0
react/features/base/tracks/functions.js View File

1
 /* global APP */
1
 /* global APP */
2
 
2
 
3
+import { isMobileBrowser } from '../environment/utils';
3
 import JitsiMeetJS, { JitsiTrackErrors, browser } from '../lib-jitsi-meet';
4
 import JitsiMeetJS, { JitsiTrackErrors, browser } from '../lib-jitsi-meet';
4
 import { MEDIA_TYPE, VIDEO_TYPE, setAudioMuted } from '../media';
5
 import { MEDIA_TYPE, VIDEO_TYPE, setAudioMuted } from '../media';
6
+import { toState } from '../redux';
5
 import {
7
 import {
6
     getUserSelectedCameraDeviceId,
8
     getUserSelectedCameraDeviceId,
7
     getUserSelectedMicDeviceId
9
     getUserSelectedMicDeviceId
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 View File

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

Loading…
Cancel
Save