瀏覽代碼

ref(JitsiLocalTrack): NO_DATA_FROM_SOURCE logic

dev1
Hristo Terezov 6 年之前
父節點
當前提交
e7c5f53378
共有 2 個文件被更改,包括 52 次插入66 次删除
  1. 47
    64
      modules/RTC/JitsiLocalTrack.js
  2. 5
    2
      service/statistics/AnalyticsEvents.js

+ 47
- 64
modules/RTC/JitsiLocalTrack.js 查看文件

147
          */
147
          */
148
         this._noDataFromSourceTimeout = null;
148
         this._noDataFromSourceTimeout = null;
149
 
149
 
150
+        this._onTrackMuted = this._onTrackMuted.bind(this);
151
+
152
+        this._trackMutedTS = 0;
153
+
150
         this._onDeviceListWillChange = devices => {
154
         this._onDeviceListWillChange = devices => {
151
             const oldRealDeviceId = this._realDeviceId;
155
             const oldRealDeviceId = this._realDeviceId;
152
 
156
 
207
      * issues.
211
      * issues.
208
      */
212
      */
209
     _initNoDataFromSourceHandlers() {
213
     _initNoDataFromSourceHandlers() {
214
+        if (!this._isNoDataFromSourceEventsEnabled()) {
215
+            return;
216
+        }
217
+
218
+        this._setHandler('track_mute', () => {
219
+            this._trackMutedTS = window.performance.now();
220
+            this._fireNoDataFromSourceEvent();
221
+        });
222
+
223
+        this._setHandler('track_unmute', () => {
224
+            this._fireNoDataFromSourceEvent();
225
+            Statistics.sendAnalyticsAndLog(
226
+                TRACK_UNMUTED,
227
+                {
228
+                    'media_type': this.getType(),
229
+                    'track_type': 'local',
230
+                    value: window.performance.now() - this._trackMutedTS
231
+                });
232
+        });
233
+
210
         if (this.isVideoTrack() && this.videoType === VideoType.CAMERA) {
234
         if (this.isVideoTrack() && this.videoType === VideoType.CAMERA) {
211
-            const _onNoDataFromSourceError
212
-                = this._onNoDataFromSourceError.bind(this);
213
-
214
-            this._setHandler('track_mute', () => {
215
-                if (this._checkForCameraIssues()) {
216
-                    const now = window.performance.now();
217
-
218
-                    this._noDataFromSourceTimeout
219
-                        = setTimeout(_onNoDataFromSourceError, 5000);
220
-                    this._setHandler('track_unmute', () => {
221
-                        this._clearNoDataFromSourceMuteResources();
222
-                        Statistics.sendAnalyticsAndLog(
223
-                            TRACK_UNMUTED,
224
-                            {
225
-                                'media_type': this.getType(),
226
-                                'track_type': 'local',
227
-                                value: window.performance.now() - now
228
-                            });
229
-                    });
235
+            this._setHandler('track_ended', () => {
236
+                if (!this.isReceivingData()) {
237
+                    this._fireNoDataFromSourceEvent();
230
                 }
238
                 }
231
             });
239
             });
232
-            this._setHandler('track_ended', _onNoDataFromSourceError);
233
-        }
234
-    }
235
-
236
-    /**
237
-     * Clears all timeouts and handlers set on MediaStreamTrack mute event.
238
-     * FIXME: Change the name of the method with better one.
239
-     */
240
-    _clearNoDataFromSourceMuteResources() {
241
-        if (this._noDataFromSourceTimeout) {
242
-            clearTimeout(this._noDataFromSourceTimeout);
243
-            this._noDataFromSourceTimeout = null;
244
         }
240
         }
245
-        this._setHandler('track_unmute', undefined);
246
     }
241
     }
247
 
242
 
248
     /**
243
     /**
249
-     * Called when potential camera issue is detected. Clears the handlers and
250
-     * timeouts set on MediaStreamTrack muted event. Verifies that the camera
251
-     * issue persists and fires NO_DATA_FROM_SOURCE event.
244
+     * Returns true if no data from source events are enabled for this JitsiLocalTrack and false otherwise.
245
+     *
246
+     * @returns {boolean} - True if no data from source events are enabled for this JitsiLocalTrack and false otherwise.
252
      */
247
      */
253
-    _onNoDataFromSourceError() {
254
-        this._clearNoDataFromSourceMuteResources();
255
-        if (this._checkForCameraIssues()) {
256
-            this._fireNoDataFromSourceEvent();
257
-        }
248
+    _isNoDataFromSourceEventsEnabled() {
249
+        // Disable the events for screen sharing.
250
+        return !this.isVideoTrack() || this.videoType !== VideoType.DESKTOP;
258
     }
251
     }
259
 
252
 
260
     /**
253
     /**
261
      * Fires NO_DATA_FROM_SOURCE event and logs it to analytics and callstats.
254
      * Fires NO_DATA_FROM_SOURCE event and logs it to analytics and callstats.
262
      */
255
      */
263
     _fireNoDataFromSourceEvent() {
256
     _fireNoDataFromSourceEvent() {
264
-        this.emit(NO_DATA_FROM_SOURCE);
257
+        const value = !this.isReceivingData();
265
 
258
 
266
-        Statistics.sendAnalytics(createNoDataFromSourceEvent(this.getType()));
267
-        const log = { name: NO_DATA_FROM_SOURCE };
259
+        this.emit(NO_DATA_FROM_SOURCE, value);
268
 
260
 
269
-        if (this.isAudioTrack()) {
270
-            log.isReceivingData = this._isReceivingData();
271
-        }
272
-        Statistics.sendLog(JSON.stringify(log));
261
+        // FIXME: Should we report all of those events
262
+        Statistics.sendAnalytics(createNoDataFromSourceEvent(this.getType(), value));
263
+        Statistics.sendLog(JSON.stringify({
264
+            name: NO_DATA_FROM_SOURCE,
265
+            log: value
266
+        }));
273
     }
267
     }
274
 
268
 
275
     /**
269
     /**
738
         }
732
         }
739
     }
733
     }
740
 
734
 
741
-    /**
742
-     * Detects camera issues, i.e. returns true if we expect this track to be
743
-     * receiving data from its source, but it isn't receiving data.
744
-     *
745
-     * @returns {boolean} true if an issue is detected and false otherwise
746
-     */
747
-    _checkForCameraIssues() {
748
-        if (!this.isVideoTrack()
749
-                || this._stopStreamInProgress
750
-                || this.videoType === VideoType.DESKTOP) {
751
-            return false;
752
-        }
753
-
754
-        return !this._isReceivingData();
755
-    }
756
-
757
     /**
735
     /**
758
      * Checks whether the attached MediaStream is receiving data from source or
736
      * Checks whether the attached MediaStream is receiving data from source or
759
      * not. If the stream property is null(because of mute or another reason)
737
      * not. If the stream property is null(because of mute or another reason)
765
      * @returns {boolean} true if the stream is receiving data and false
743
      * @returns {boolean} true if the stream is receiving data and false
766
      * this otherwise.
744
      * this otherwise.
767
      */
745
      */
768
-    _isReceivingData() {
746
+    isReceivingData() {
747
+        if (this.isVideoTrack()
748
+            && (this.isMuted() || this._stopStreamInProgress || this.videoType === VideoType.DESKTOP)) {
749
+            return true;
750
+        }
751
+
769
         if (!this.stream) {
752
         if (!this.stream) {
770
             return false;
753
             return false;
771
         }
754
         }

+ 5
- 2
service/statistics/AnalyticsEvents.js 查看文件

344
  * @param mediaType {String} the media type of the local track ('audio' or
344
  * @param mediaType {String} the media type of the local track ('audio' or
345
  * 'video').
345
  * 'video').
346
  */
346
  */
347
-export const createNoDataFromSourceEvent = function(mediaType) {
347
+export const createNoDataFromSourceEvent = function(mediaType, value) {
348
     return {
348
     return {
349
-        attributes: { 'media_type': mediaType },
349
+        attributes: {
350
+            'media_type': mediaType,
351
+            value
352
+        },
350
         action: 'track.no.data.from.source',
353
         action: 'track.no.data.from.source',
351
         type: TYPE_OPERATIONAL
354
         type: TYPE_OPERATIONAL
352
     };
355
     };

Loading…
取消
儲存