Browse Source

Add/fix JSDoc comments

While reviewing "[PREVIEW|RN]: Handle getUserMedia in progress" I
discovered JSDoc comments which could be improved. They are not
necessarily 100% related to the PR.
master
Lyubo Marinov 8 years ago
parent
commit
decf9c4991

+ 5
- 5
react/features/base/conference/actions.js View File

@@ -211,12 +211,12 @@ export function conferenceLeft(conference: Object) {
211 211
 }
212 212
 
213 213
 /**
214
- * Attaches any pre-existing local media to the conference, before
215
- * the conference will be joined. Then signals the intention of the application
216
- * to have the local participant join a specific conference.
214
+ * Adds any existing local tracks to a specific conference before the conference
215
+ * is joined. Then signals the intention of the application to have the local
216
+ * participant join the specified conference.
217 217
  *
218
- * @param {JitsiConference} conference - The JitsiConference instance the
219
- * local participant will (try to) join.
218
+ * @param {JitsiConference} conference - The {@code JitsiConference} instance
219
+ * the local participant will (try to) join.
220 220
  * @returns {Function}
221 221
  */
222 222
 function _conferenceWillJoin(conference: Object) {

+ 18
- 15
react/features/base/tracks/actionTypes.js View File

@@ -1,6 +1,6 @@
1 1
 /**
2
- * Action for when a track has been added to the conference,
3
- * local or remote.
2
+ * The type of redux action dispatched when a track has been (locally or
3
+ * remotely) added to the conference.
4 4
  *
5 5
  * {
6 6
  *     type: TRACK_ADDED,
@@ -10,18 +10,19 @@
10 10
 export const TRACK_ADDED = Symbol('TRACK_ADDED');
11 11
 
12 12
 /**
13
- * Action triggered when a local track starts being created through the WebRTC
14
- * getUserMedia call. It will include extra 'gumProcess' field which is
15
- * a Promise with extra 'cancel' method which can be used to cancel the process.
16
- * Canceling will result in disposing any JitsiLocalTrack returned by the GUM
17
- * callback. There will be TRACK_CREATE_CANCELED event instead of track
18
- * added/gum failed events.
13
+ * The type of redux action dispatched when a local track starts being created
14
+ * via a WebRTC {@code getUserMedia} call. The action's payload includes an
15
+ * extra {@code gumProcess} property which is a {@code Promise} with an extra
16
+ * {@code cancel} method which can be used to cancel the process. Canceling will
17
+ * result in disposing any {@code JitsiLocalTrack} returned by the
18
+ * {@code getUserMedia} callback. There will be a {@code TRACK_CREATE_CANCELED}
19
+ * action instead of a {@code TRACK_ADDED} or {@code TRACK_CREATE_ERROR} action.
19 20
  *
20 21
  * {
21 22
  *     type: TRACK_BEING_CREATED
22 23
  *     track: {
24
+ *         gumProcess: Promise with a `cancel` method to cancel the process,
23 25
  *         local: true,
24
- *         gumProcess: Promise with cancel() method to abort,
25 26
  *         mediaType: MEDIA_TYPE
26 27
  *     }
27 28
  * }
@@ -29,8 +30,9 @@ export const TRACK_ADDED = Symbol('TRACK_ADDED');
29 30
 export const TRACK_BEING_CREATED = Symbol('TRACK_BEING_CREATED');
30 31
 
31 32
 /**
32
- * Action sent when canceled GUM process completes either successfully or with
33
- * an error (error is ignored and track is immediately disposed if created).
33
+ * The type of redux action dispatched when a canceled {@code getUserMedia}
34
+ * process completes either successfully or with an error (the error is ignored
35
+ * and the track is immediately disposed if it has been created).
34 36
  *
35 37
  * {
36 38
  *     type: TRACK_CREATE_CANCELED,
@@ -40,7 +42,8 @@ export const TRACK_BEING_CREATED = Symbol('TRACK_BEING_CREATED');
40 42
 export const TRACK_CREATE_CANCELED = Symbol('TRACK_CREATE_CANCELED');
41 43
 
42 44
 /**
43
- * Action sent when GUM fails with an error other than permission denied.
45
+ * The type of redux action dispatched when {@code getUserMedia} fails with an
46
+ * error (such as permission denied).
44 47
  *
45 48
  * {
46 49
  *     type: TRACK_CREATE_ERROR,
@@ -51,8 +54,8 @@ export const TRACK_CREATE_CANCELED = Symbol('TRACK_CREATE_CANCELED');
51 54
 export const TRACK_CREATE_ERROR = Symbol('TRACK_CREATE_ERROR');
52 55
 
53 56
 /**
54
- * Action for when a track has been removed from the conference,
55
- * local or remote.
57
+ * The type of redux action dispatched when a track has been (locally or
58
+ * remotely) removed from the conference.
56 59
  *
57 60
  * {
58 61
  *     type: TRACK_REMOVED,
@@ -62,7 +65,7 @@ export const TRACK_CREATE_ERROR = Symbol('TRACK_CREATE_ERROR');
62 65
 export const TRACK_REMOVED = Symbol('TRACK_REMOVED');
63 66
 
64 67
 /**
65
- * Action for when a track properties were updated.
68
+ * The type of redux action dispatched when a track's properties were updated.
66 69
  *
67 70
  * {
68 71
  *     type: TRACK_UPDATED,

+ 88
- 82
react/features/base/tracks/actions.js View File

@@ -37,7 +37,7 @@ export function createDesiredLocalTracks(...desiredTypes) {
37 37
             const { audio, video } = state['features/base/media'];
38 38
 
39 39
             audio.muted || desiredTypes.push(MEDIA_TYPE.AUDIO);
40
-            Boolean(video.muted) || desiredTypes.push(MEDIA_TYPE.VIDEO);
40
+            video.muted || desiredTypes.push(MEDIA_TYPE.VIDEO);
41 41
         }
42 42
 
43 43
         const availableTypes
@@ -85,44 +85,52 @@ export function createLocalTracksA(options = {}) {
85 85
                     .find(t => t.local && t.mediaType === device)) {
86 86
                 throw new Error(`Local track for ${device} already exists`);
87 87
             }
88
-            const gumProcess = createLocalTracksF(
89
-                {
90
-                    cameraDeviceId: options.cameraDeviceId,
91
-                    devices: [ device ],
92
-                    facingMode: options.facingMode || CAMERA_FACING_MODE.USER,
93
-                    micDeviceId: options.micDeviceId
94
-                },
95
-                /* firePermissionPromptIsShownEvent */ false,
96
-                store)
97
-            .then(
98
-                localTracks => {
99
-                    // Because GUM is called for 1 device (which is actually
100
-                    // a media type 'audio','video', 'screen' etc.) we should
101
-                    // not get more than one JitsiTrack.
102
-                    if (localTracks.length !== 1) {
103
-                        throw new Error(
104
-                            'Expected exactly 1 track, but was '
105
-                                + `given ${localTracks.length} tracks`
106
-                                + `for device: ${device}.`);
107
-                    }
108 88
 
109
-                    if (gumProcess.canceled) {
110
-                        return _disposeTracks(localTracks)
111
-                                    .then(
112
-                                        () =>
113
-                                            dispatch(
114
-                                                _trackCreateCanceled(device)));
115
-                    }
89
+            const gumProcess
90
+                = createLocalTracksF(
91
+                    {
92
+                        cameraDeviceId: options.cameraDeviceId,
93
+                        devices: [ device ],
94
+                        facingMode:
95
+                            options.facingMode || CAMERA_FACING_MODE.USER,
96
+                        micDeviceId: options.micDeviceId
97
+                    },
98
+                    /* firePermissionPromptIsShownEvent */ false,
99
+                    store)
100
+                .then(
101
+                    localTracks => {
102
+                        // Because GUM is called for 1 device (which is actually
103
+                        // a media type 'audio', 'video', 'screen', etc.) we
104
+                        // should not get more than one JitsiTrack.
105
+                        if (localTracks.length !== 1) {
106
+                            throw new Error(
107
+                                `Expected exactly 1 track, but was given ${
108
+                                    localTracks.length} tracks for device: ${
109
+                                    device}.`);
110
+                        }
116 111
 
117
-                    return dispatch(trackAdded(localTracks[0]));
118
-                },
119
-                // eslint-disable-next-line no-confusing-arrow
120
-                reason =>
121
-                    dispatch(
122
-                        gumProcess.canceled
123
-                            ? _trackCreateCanceled(device)
124
-                            : _onCreateLocalTracksRejected(reason, device)));
112
+                        if (gumProcess.canceled) {
113
+                            return _disposeTracks(localTracks)
114
+                                .then(() =>
115
+                                    dispatch(_trackCreateCanceled(device)));
116
+                        }
125 117
 
118
+                        return dispatch(trackAdded(localTracks[0]));
119
+                    },
120
+                    reason =>
121
+                        dispatch(
122
+                            gumProcess.canceled
123
+                                ? _trackCreateCanceled(device)
124
+                                : _onCreateLocalTracksRejected(
125
+                                    reason,
126
+                                    device)));
127
+
128
+            /**
129
+             * Cancels the {@code getUserMedia} process represented by this
130
+             * {@code Promise}.
131
+             *
132
+             * @returns {Promise} This {@code Promise} i.e. {@code gumProcess}.
133
+             */
126 134
             gumProcess.cancel = () => {
127 135
                 gumProcess.canceled = true;
128 136
 
@@ -132,8 +140,8 @@ export function createLocalTracksA(options = {}) {
132 140
             dispatch({
133 141
                 type: TRACK_BEING_CREATED,
134 142
                 track: {
135
-                    local: true,
136 143
                     gumProcess,
144
+                    local: true,
137 145
                     mediaType: device
138 146
                 }
139 147
             });
@@ -151,9 +159,9 @@ export function destroyLocalTracks() {
151 159
     return (dispatch, getState) => {
152 160
         // First wait until any getUserMedia in progress is settled and then get
153 161
         // rid of all local tracks.
154
-        _cancelAllGumInProgress(getState)
155
-            .then(
156
-                () => dispatch(
162
+        _cancelGUMProcesses(getState)
163
+            .then(() =>
164
+                dispatch(
157 165
                     _disposeAndRemoveTracks(
158 166
                         getState()['features/base/tracks']
159 167
                             .filter(t => t.local)
@@ -366,49 +374,27 @@ function _addTracks(tracks) {
366 374
 }
367 375
 
368 376
 /**
369
- * Signals that track create operation for given media track has been canceled.
370
- * Will clean up local track stub from the Redux state which holds the
371
- * 'gumProcess' reference.
372
- *
373
- * @param {MEDIA_TYPE} mediaType - The type of the media for which the track was
374
- * being created.
375
- * @returns {{
376
- *      type,
377
- *      trackType: MEDIA_TYPE
378
- * }}
379
- * @private
380
- */
381
-function _trackCreateCanceled(mediaType) {
382
-    return {
383
-        type: TRACK_CREATE_CANCELED,
384
-        trackType: mediaType
385
-    };
386
-}
387
-
388
-/**
389
- * Cancels and waits for any get user media operations currently in progress to
390
- * complete.
377
+ * Cancels and waits for any {@code getUserMedia} process/currently in progress
378
+ * to complete/settle.
391 379
  *
392
- * @param {Function} getState - The Redux store {@code getState} method used to
393
- * obtain the state.
394
- * @returns {Promise} - A Promise resolved once all {@code gumProcess.cancel}
395
- * Promises are settled. That is when they are either resolved or rejected,
396
- * because all we care about here is to be sure that get user media callbacks
397
- * have completed (returned from the native side).
380
+ * @param {Function} getState - The redux store {@code getState} function used
381
+ * to obtain the state.
398 382
  * @private
383
+ * @returns {Promise} - A {@code Promise} resolved once all
384
+ * {@code gumProcess.cancel()} {@code Promise}s are settled because all we care
385
+ * about here is to be sure that the {@code getUserMedia} callbacks have
386
+ * completed (i.e. returned from the native side).
399 387
  */
400
-function _cancelAllGumInProgress(getState) {
401
-    // FIXME use logger
388
+function _cancelGUMProcesses(getState) {
402 389
     const logError
403 390
         = error =>
404
-            console.error('gumProcess.cancel failed', JSON.stringify(error));
391
+            logger.error('gumProcess.cancel failed', JSON.stringify(error));
405 392
 
406 393
     return Promise.all(
407 394
         getState()['features/base/tracks']
408 395
             .filter(t => t.local)
409
-            .map(
410
-                t => t.gumProcess
411
-                    && t.gumProcess.cancel().catch(logError)));
396
+            .map(({ gumProcess }) =>
397
+                gumProcess && gumProcess.cancel().catch(logError)));
412 398
 }
413 399
 
414 400
 /**
@@ -421,15 +407,15 @@ function _cancelAllGumInProgress(getState) {
421 407
 export function _disposeAndRemoveTracks(tracks) {
422 408
     return dispatch =>
423 409
         _disposeTracks(tracks)
424
-            .then(
425
-                () => Promise.all(tracks.map(t => dispatch(trackRemoved(t)))));
410
+            .then(() =>
411
+                Promise.all(tracks.map(t => dispatch(trackRemoved(t)))));
426 412
 }
427 413
 
428 414
 /**
429 415
  * Disposes passed tracks.
430 416
  *
431 417
  * @param {(JitsiLocalTrack|JitsiRemoteTrack)[]} tracks - List of tracks.
432
- * @protected
418
+ * @private
433 419
  * @returns {Promise} - A Promise resolved once {@link JitsiTrack.dispose()} is
434 420
  * done for every track from the list.
435 421
  */
@@ -438,13 +424,12 @@ function _disposeTracks(tracks) {
438 424
         tracks.map(t =>
439 425
             t.dispose()
440 426
                 .catch(err => {
441
-                    // Track might be already disposed so ignore such an
442
-                    // error. Of course, re-throw any other error(s).
427
+                    // Track might be already disposed so ignore such an error.
428
+                    // Of course, re-throw any other error(s).
443 429
                     if (err.name !== JitsiTrackErrors.TRACK_IS_DISPOSED) {
444 430
                         throw err;
445 431
                     }
446
-                })
447
-        ));
432
+                })));
448 433
 }
449 434
 
450 435
 /**
@@ -496,7 +481,8 @@ function _onCreateLocalTracksRejected({ gum }, device) {
496 481
 }
497 482
 
498 483
 /**
499
- * Returns true if the provided JitsiTrack should be rendered as a mirror.
484
+ * Returns true if the provided {@code JitsiTrack} should be rendered as a
485
+ * mirror.
500 486
  *
501 487
  * We only want to show a video in mirrored mode when:
502 488
  * 1) The video source is local, and not remote.
@@ -524,3 +510,23 @@ function _shouldMirror(track) {
524 510
             // but that may not be the case tomorrow.
525 511
             && track.getCameraFacingMode() === CAMERA_FACING_MODE.USER);
526 512
 }
513
+
514
+/**
515
+ * Signals that track create operation for given media track has been canceled.
516
+ * Will clean up local track stub from the redux state which holds the
517
+ * {@code gumProcess} reference.
518
+ *
519
+ * @param {MEDIA_TYPE} mediaType - The type of the media for which the track was
520
+ * being created.
521
+ * @private
522
+ * @returns {{
523
+ *     type,
524
+ *     trackType: MEDIA_TYPE
525
+ * }}
526
+ */
527
+function _trackCreateCanceled(mediaType) {
528
+    return {
529
+        type: TRACK_CREATE_CANCELED,
530
+        trackType: mediaType
531
+    };
532
+}

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

@@ -110,21 +110,21 @@ export function getLocalTrack(tracks, mediaType) {
110 110
 }
111 111
 
112 112
 /**
113
- * Returns an array containing local tracks. Local tracks without valid
114
- * JitsiTrack will not be included in the list.
113
+ * Returns an array containing the local tracks with a (valid)
114
+ * {@code JitsiTrack}.
115 115
  *
116
- * @param {Track[]} tracks - An array of all local tracks.
116
+ * @param {Track[]} tracks - An array containing all local tracks.
117 117
  * @returns {Track[]}
118 118
  */
119 119
 export function getLocalTracks(tracks) {
120 120
 
121
-    // XXX A local track is considered ready only once it has 'jitsiTrack' field
122
-    // set by the TRACK_ADDED action. Until then there is a stub added just
123
-    // before get user media call with a cancellable 'gumInProgress' field which
124
-    // then can be used to destroy the track that has not yet been added to
125
-    // the Redux store. Once GUM is cancelled it will never make it to the store
126
-    // nor there will be any TRACK_ADDED/TRACK_REMOVED related events fired for
127
-    // it.
121
+    // XXX A local track is considered ready only once it has its `jitsiTrack`
122
+    // property set by the `TRACK_ADDED` action. Until then there is a stub
123
+    // added just before the `getUserMedia` call with a cancellable
124
+    // `gumInProgress` property which then can be used to destroy the track that
125
+    // has not yet been added to the redux store. Once GUM is cancelled, it will
126
+    // never make it to the store nor there will be any
127
+    // `TRACK_ADDED`/`TRACK_REMOVED` actions dispatched for it.
128 128
     return tracks.filter(t => t.local && t.jitsiTrack);
129 129
 }
130 130
 
@@ -215,7 +215,7 @@ export function setTrackMuted(track, muted) {
215 215
 
216 216
     return track[f]().catch(error => {
217 217
 
218
-        // FIXME emit mute failed, so that the app can show error dialog
218
+        // FIXME Emit mute failed, so that the app can show error dialog.
219 219
         console.error(`set track ${f} failed`, error);
220 220
     });
221 221
 }

+ 15
- 14
react/features/base/tracks/reducer.js View File

@@ -12,23 +12,24 @@ import {
12 12
 
13 13
 /**
14 14
  * @typedef {Object} Track
15
- * @property {(JitsiLocalTrack|JitsiRemoteTrack)} [jitsiTrack] - JitsiTrack
16
- * instance. Optional for local tracks if those are being created (GUM in
17
- * progress).
18
- * @property {boolean} local=false - If track is local.
19
- * @property {Promise} [gumProcess] - if local track is being created it
20
- * will have no JitsiTrack, but a 'gumProcess' set to a Promise with and extra
21
- * cancel().
22
- * @property {MEDIA_TYPE} mediaType=false - Media type of track.
15
+ * @property {(JitsiLocalTrack|JitsiRemoteTrack)} [jitsiTrack] - The associated
16
+ * {@code JitsiTrack} instance. Optional for local tracks if those are still
17
+ * being created (i.e. {@code getUserMedia} is still in progress).
18
+ * @property {Promise} [gumProcess] - If a local track is still being created,
19
+ * it will have no {@code JitsiTrack}, but a {@code gumProcess} set to a
20
+ * {@code Promise} with and extra {@code cancel()}.
21
+ * @property {boolean} local=false - If the track is local.
22
+ * @property {MEDIA_TYPE} mediaType=false - The media type of the track.
23 23
  * @property {boolean} mirror=false - The indicator which determines whether the
24 24
  * display/rendering of the track should be mirrored. It only makes sense in the
25 25
  * context of video (at least at the time of this writing).
26
- * @property {boolean} muted=false - If track is muted.
27
- * @property {(string|undefined)} participantId - ID of participant whom this
28
- * track belongs to.
29
- * @property {boolean} videoStarted=false - If video track has already started
30
- * to play.
31
- * @property {(VIDEO_TYPE|undefined)} videoType - Type of video track if any.
26
+ * @property {boolean} muted=false - If the track is muted.
27
+ * @property {(string|undefined)} participantId - The ID of the participant whom
28
+ * the track belongs to.
29
+ * @property {boolean} videoStarted=false - If the video track has already
30
+ * started to play.
31
+ * @property {(VIDEO_TYPE|undefined)} videoType - The type of video track if
32
+ * any.
32 33
  */
33 34
 
34 35
 /**

+ 2
- 2
react/features/remote-video-menu/components/MuteRemoteParticipantDialog.web.js View File

@@ -95,9 +95,9 @@ class MuteRemoteParticipantDialog extends Component {
95 95
     /**
96 96
      * Renders the content of the dialog.
97 97
      *
98
-     * @returns {Component} the react component, which is the view of the dialog
99
-     * content
100 98
      * @private
99
+     * @returns {Component} The React {@code Component} which is the view of the
100
+     * dialog content.
101 101
      */
102 102
     _renderContent() {
103 103
         const { t } = this.props;

Loading…
Cancel
Save