Browse Source

Extract shouldRenderParticipantVideo from ParticipantView

j8
Bettenbuk Zoltan 6 years ago
parent
commit
f2b2cfda44

+ 10
- 25
react/features/base/participants/components/ParticipantView.native.js View File

@@ -9,7 +9,6 @@ import { translate } from '../../i18n';
9 9
 import { JitsiParticipantConnectionStatus } from '../../lib-jitsi-meet';
10 10
 import {
11 11
     MEDIA_TYPE,
12
-    shouldRenderVideoTrack,
13 12
     VideoTrack
14 13
 } from '../../media';
15 14
 import { Container, TintedView } from '../../react';
@@ -20,7 +19,8 @@ import Avatar from './Avatar';
20 19
 import {
21 20
     getAvatarURL,
22 21
     getParticipantById,
23
-    getParticipantDisplayName
22
+    getParticipantDisplayName,
23
+    shouldRenderParticipantVideo
24 24
 } from '../functions';
25 25
 import styles from './styles';
26 26
 
@@ -29,14 +29,6 @@ import styles from './styles';
29 29
  */
30 30
 type Props = {
31 31
 
32
-    /**
33
-     * The indicator which determines whether conferencing is in audio-only
34
-     * mode.
35
-     *
36
-     * @private
37
-     */
38
-    _audioOnly: boolean,
39
-
40 32
     /**
41 33
      * The source (e.g. URI, URL) of the avatar image of the participant with
42 34
      * {@link #participantId}.
@@ -61,6 +53,11 @@ type Props = {
61 53
      */
62 54
     _participantName: string,
63 55
 
56
+    /**
57
+     * True if the video should be rendered, false otherwise.
58
+     */
59
+    _renderVideo: boolean,
60
+
64 61
     /**
65 62
      * The video Track of the participant with {@link #participantId}.
66 63
      */
@@ -192,23 +189,11 @@ class ParticipantView extends Component<Props> {
192 189
             onPress,
193 190
             _avatar: avatar,
194 191
             _connectionStatus: connectionStatus,
192
+            _renderVideo: renderVideo,
195 193
             _videoTrack: videoTrack
196 194
         } = this.props;
197 195
 
198
-        // Is the video to be rendered?
199
-        // FIXME It's currently impossible to have true as the value of
200
-        // waitForVideoStarted because videoTrack's state videoStarted will be
201
-        // updated only after videoTrack is rendered.
202
-        // XXX Note that, unlike on web, we don't render video when the
203
-        // connection status is interrupted, this is because the renderer
204
-        // doesn't retain the last frame forever, so we would end up with a
205
-        // black screen.
206 196
         const waitForVideoStarted = false;
207
-        const renderVideo
208
-            = !this.props._audioOnly
209
-                && (connectionStatus
210
-                    === JitsiParticipantConnectionStatus.ACTIVE)
211
-                && shouldRenderVideoTrack(videoTrack, waitForVideoStarted);
212 197
 
213 198
         // Is the avatar to be rendered?
214 199
         const renderAvatar = Boolean(!renderVideo && avatar);
@@ -271,10 +256,10 @@ class ParticipantView extends Component<Props> {
271 256
  * associated (instance of) {@code ParticipantView}.
272 257
  * @private
273 258
  * @returns {{
274
- *     _audioOnly: boolean,
275 259
  *     _avatar: string,
276 260
  *     _connectionStatus: string,
277 261
  *     _participantName: string,
262
+ *     _renderVideo: boolean,
278 263
  *     _videoTrack: Track
279 264
  * }}
280 265
  */
@@ -308,12 +293,12 @@ function _mapStateToProps(state, ownProps) {
308 293
     }
309 294
 
310 295
     return {
311
-        _audioOnly: state['features/base/conference'].audioOnly,
312 296
         _avatar: avatar,
313 297
         _connectionStatus:
314 298
             connectionStatus
315 299
                 || JitsiParticipantConnectionStatus.ACTIVE,
316 300
         _participantName: participantName,
301
+        _renderVideo: shouldRenderParticipantVideo(state, participantId),
317 302
         _videoTrack:
318 303
             getTrackByMediaTypeAndParticipant(
319 304
                 state['features/base/tracks'],

+ 48
- 1
react/features/base/participants/functions.js View File

@@ -3,6 +3,10 @@ import { getAvatarURL as _getAvatarURL } from 'js-utils/avatar';
3 3
 
4 4
 import { toState } from '../redux';
5 5
 
6
+import { JitsiParticipantConnectionStatus } from '../lib-jitsi-meet';
7
+import { MEDIA_TYPE, shouldRenderVideoTrack } from '../media';
8
+import { getTrackByMediaTypeAndParticipant } from '../tracks';
9
+
6 10
 import {
7 11
     DEFAULT_AVATAR_RELATIVE_PATH,
8 12
     LOCAL_PARTICIPANT_DEFAULT_ID,
@@ -121,7 +125,8 @@ export function getNormalizedDisplayName(name: string) {
121 125
  * @private
122 126
  * @returns {(Participant|undefined)}
123 127
  */
124
-export function getParticipantById(stateful: Object | Function, id: string) {
128
+export function getParticipantById(
129
+        stateful: Object | Function, id: string): ?Object {
125 130
     const participants = _getAllParticipants(stateful);
126 131
 
127 132
     return participants.find(p => p.id === id);
@@ -276,3 +281,45 @@ export function isLocalParticipantModerator(stateful: Object | Function) {
276 281
             && (!state['features/base/config'].enableUserRolesBasedOnToken
277 282
                 || !state['features/base/jwt'].isGuest));
278 283
 }
284
+
285
+/**
286
+ * Returns true if the video of the participant should be rendered.
287
+ *
288
+ * @param {Object|Function} stateful - Object or function that can be resolved
289
+ * to the Redux state.
290
+ * @param {string} id - The ID of the participant.
291
+ * @returns {boolean}
292
+ */
293
+export function shouldRenderParticipantVideo(
294
+        stateful: Object | Function, id: string) {
295
+    const state = toState(stateful);
296
+    const participant = getParticipantById(state, id);
297
+
298
+    if (!participant) {
299
+        return false;
300
+    }
301
+
302
+    const audioOnly = state['features/base/conference'].audioOnly;
303
+    const connectionStatus = participant.connectionStatus
304
+        || JitsiParticipantConnectionStatus.ACTIVE;
305
+    const videoTrack = getTrackByMediaTypeAndParticipant(
306
+        state['features/base/tracks'],
307
+        MEDIA_TYPE.VIDEO,
308
+        id);
309
+
310
+    // Is the video to be rendered?
311
+    // FIXME It's currently impossible to have true as the value of
312
+    // waitForVideoStarted because videoTrack's state videoStarted will be
313
+    // updated only after videoTrack is rendered.
314
+    // XXX Note that, unlike on web, we don't render video when the
315
+    // connection status is interrupted, this is because the renderer
316
+    // doesn't retain the last frame forever, so we would end up with a
317
+    // black screen.
318
+    const waitForVideoStarted = false;
319
+
320
+    return !audioOnly
321
+        && (connectionStatus
322
+            === JitsiParticipantConnectionStatus.ACTIVE)
323
+        && shouldRenderVideoTrack(videoTrack, waitForVideoStarted);
324
+
325
+}

Loading…
Cancel
Save