Bladeren bron

Reports initial device list and subsequent device changes to callstats.

dev1
damencho 9 jaren geleden
bovenliggende
commit
0322825701
5 gewijzigde bestanden met toevoegingen van 103 en 6 verwijderingen
  1. 10
    0
      JitsiConference.js
  2. 32
    0
      JitsiMediaDevices.js
  3. 17
    0
      modules/RTC/RTC.js
  4. 42
    5
      modules/RTC/RTCUtils.js
  5. 2
    1
      service/RTC/RTCEvents.js

+ 10
- 0
JitsiConference.js Bestand weergeven

@@ -331,6 +331,16 @@ JitsiConference.prototype.addTrack = function (track) {
331 331
     this.room.addListener(XMPPEvents.SENDRECV_STREAMS_CHANGED,
332 332
         track.ssrcHandler);
333 333
 
334
+    // Report active device to statistics
335
+    var devices = RTC.getCurrentlyAvailableMediaDevices();
336
+    device = devices.find(function (d) {
337
+        return d.kind === track.getTrack().kind + 'input'
338
+            && d.label === track.getTrack().label;
339
+    });
340
+
341
+    Statistics.sendАctiveDeviceListEvent(
342
+        RTC.getEventDataForActiveDevice(device));
343
+
334 344
     return new Promise(function (resolve, reject) {
335 345
         this.room.addStream(track.getOriginalStream(), function () {
336 346
             if (track.isVideoTrack()) {

+ 32
- 0
JitsiMediaDevices.js Bestand weergeven

@@ -3,6 +3,7 @@ var RTCEvents = require('./service/RTC/RTCEvents');
3 3
 var RTC = require("./modules/RTC/RTC");
4 4
 var MediaType = require('./service/RTC/MediaType');
5 5
 var JitsiMediaDevicesEvents = require('./JitsiMediaDevicesEvents');
6
+var Statistics = require("./modules/statistics/statistics");
6 7
 
7 8
 var eventEmitter = new EventEmitter();
8 9
 
@@ -11,6 +12,28 @@ RTC.addListener(RTCEvents.DEVICE_LIST_CHANGED,
11 12
         eventEmitter.emit(JitsiMediaDevicesEvents.DEVICE_LIST_CHANGED, devices);
12 13
     });
13 14
 
15
+RTC.addListener(RTCEvents.DEVICE_LIST_AVAILABLE,
16
+    function (devices) {
17
+        // log output device
18
+        logOutputDevice(
19
+            JitsiMediaDevices.getAudioOutputDevice(),
20
+            devices);
21
+    });
22
+
23
+/**
24
+ * Gathers data and sends it to statistics.
25
+ * @param deviceID the device id to log
26
+ * @param devices list of devices
27
+ */
28
+function logOutputDevice (deviceID, devices) {
29
+    var device = devices.find(function (d) {
30
+        return d.kind === 'audiooutput' && d.deviceId === deviceID;
31
+    });
32
+
33
+    Statistics.sendАctiveDeviceListEvent(
34
+        RTC.getEventDataForActiveDevice(device));
35
+}
36
+
14 37
 var JitsiMediaDevices = {
15 38
     /**
16 39
      * Executes callback with list of media devices connected.
@@ -71,6 +94,15 @@ var JitsiMediaDevices = {
71 94
      *      otherwise
72 95
      */
73 96
     setAudioOutputDevice: function (deviceId) {
97
+
98
+        if (RTC.getCurrentlyAvailableMediaDevices().length > 0)
99
+        {
100
+            // if we have devices info report device to stats
101
+            // normally this will not happen on startup as this method is called
102
+            // too early. This will happen only on user selection of new device
103
+            logOutputDevice(deviceId, RTC.getCurrentlyAvailableMediaDevices());
104
+        }
105
+
74 106
         return RTC.setAudioOutputDevice(deviceId);
75 107
     },
76 108
     /**

+ 17
- 0
modules/RTC/RTC.js Bestand weergeven

@@ -345,6 +345,23 @@ RTC.getAudioOutputDevice = function () {
345 345
     return RTCUtils.getAudioOutputDevice();
346 346
 };
347 347
 
348
+/**
349
+ * Returns list of available media devices if its obtained, otherwise an
350
+ * empty array is returned/
351
+ * @returns {Array} list of available media devices.
352
+ */
353
+RTC.getCurrentlyAvailableMediaDevices = function () {
354
+    return RTCUtils.getCurrentlyAvailableMediaDevices();
355
+};
356
+
357
+/**
358
+ * Returns event data for device to be reported to stats.
359
+ * @returns {MediaDeviceInfo} device.
360
+ */
361
+RTC.getEventDataForActiveDevice = function (device) {
362
+    return RTCUtils.getEventDataForActiveDevice(device);
363
+};
364
+
348 365
 /**
349 366
  * Sets current audio output device.
350 367
  * @param {string} deviceId - id of 'audiooutput' device from

+ 42
- 5
modules/RTC/RTCUtils.js Bestand weergeven

@@ -386,12 +386,24 @@ function onReady (options, GUM) {
386 386
     eventEmitter.emit(RTCEvents.RTC_READY, true);
387 387
     screenObtainer.init(options, GUM);
388 388
 
389
-    if (isDeviceChangeEventSupported && RTCUtils.isDeviceListAvailable()) {
390
-        navigator.mediaDevices.addEventListener('devicechange', function () {
391
-            RTCUtils.enumerateDevices(onMediaDevicesListChanged);
389
+    if (RTCUtils.isDeviceListAvailable() && rawEnumerateDevicesWithCallback) {
390
+        rawEnumerateDevicesWithCallback(function (devices) {
391
+            currentlyAvailableMediaDevices = devices.splice(0);
392
+
393
+            eventEmitter.emit(RTCEvents.DEVICE_LIST_AVAILABLE,
394
+                currentlyAvailableMediaDevices);
395
+
396
+            if (isDeviceChangeEventSupported) {
397
+                navigator.mediaDevices.addEventListener(
398
+                    'devicechange',
399
+                    function () {
400
+                        RTCUtils.enumerateDevices(
401
+                            onMediaDevicesListChanged);
402
+                    });
403
+            } else {
404
+                pollForAvailableMediaDevices();
405
+            }
392 406
         });
393
-    } else if (RTCUtils.isDeviceListAvailable()) {
394
-        pollForAvailableMediaDevices();
395 407
     }
396 408
 }
397 409
 
@@ -1207,6 +1219,31 @@ var RTCUtils = {
1207 1219
      */
1208 1220
     getAudioOutputDevice: function () {
1209 1221
         return audioOutputDeviceId;
1222
+    },
1223
+
1224
+    /**
1225
+     * Returns list of available media devices if its obtained, otherwise an
1226
+     * empty array is returned/
1227
+     * @returns {Array} list of available media devices.
1228
+     */
1229
+    getCurrentlyAvailableMediaDevices: function () {
1230
+        return currentlyAvailableMediaDevices;
1231
+    },
1232
+
1233
+    /**
1234
+     * Returns event data for device to be reported to stats.
1235
+     * @returns {MediaDeviceInfo} device.
1236
+     */
1237
+    getEventDataForActiveDevice: function (device) {
1238
+        var devices = [];
1239
+        var deviceData = {
1240
+            "deviceId": device.deviceId,
1241
+            "kind":     device.kind,
1242
+            "label":    device.label,
1243
+            "groupId":  device.groupId
1244
+        };
1245
+        devices.push(deviceData);
1246
+        return { deviceList: devices };
1210 1247
     }
1211 1248
 };
1212 1249
 

+ 2
- 1
service/RTC/RTCEvents.js Bestand weergeven

@@ -7,7 +7,8 @@ var RTCEvents = {
7 7
     AVAILABLE_DEVICES_CHANGED: "rtc.available_devices_changed",
8 8
     TRACK_ATTACHED: "rtc.track_attached",
9 9
     AUDIO_OUTPUT_DEVICE_CHANGED: "rtc.audio_output_device_changed",
10
-    DEVICE_LIST_CHANGED: "rtc.device_list_changed"
10
+    DEVICE_LIST_CHANGED: "rtc.device_list_changed",
11
+    DEVICE_LIST_AVAILABLE: "rtc.device_list_available"
11 12
 };
12 13
 
13 14
 module.exports = RTCEvents;

Laden…
Annuleren
Opslaan