Browse Source

Reports initial device list and subsequent device changes to callstats.

dev1
damencho 9 years ago
parent
commit
0322825701
5 changed files with 103 additions and 6 deletions
  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 View File

331
     this.room.addListener(XMPPEvents.SENDRECV_STREAMS_CHANGED,
331
     this.room.addListener(XMPPEvents.SENDRECV_STREAMS_CHANGED,
332
         track.ssrcHandler);
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
     return new Promise(function (resolve, reject) {
344
     return new Promise(function (resolve, reject) {
335
         this.room.addStream(track.getOriginalStream(), function () {
345
         this.room.addStream(track.getOriginalStream(), function () {
336
             if (track.isVideoTrack()) {
346
             if (track.isVideoTrack()) {

+ 32
- 0
JitsiMediaDevices.js View File

3
 var RTC = require("./modules/RTC/RTC");
3
 var RTC = require("./modules/RTC/RTC");
4
 var MediaType = require('./service/RTC/MediaType');
4
 var MediaType = require('./service/RTC/MediaType');
5
 var JitsiMediaDevicesEvents = require('./JitsiMediaDevicesEvents');
5
 var JitsiMediaDevicesEvents = require('./JitsiMediaDevicesEvents');
6
+var Statistics = require("./modules/statistics/statistics");
6
 
7
 
7
 var eventEmitter = new EventEmitter();
8
 var eventEmitter = new EventEmitter();
8
 
9
 
11
         eventEmitter.emit(JitsiMediaDevicesEvents.DEVICE_LIST_CHANGED, devices);
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
 var JitsiMediaDevices = {
37
 var JitsiMediaDevices = {
15
     /**
38
     /**
16
      * Executes callback with list of media devices connected.
39
      * Executes callback with list of media devices connected.
71
      *      otherwise
94
      *      otherwise
72
      */
95
      */
73
     setAudioOutputDevice: function (deviceId) {
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
         return RTC.setAudioOutputDevice(deviceId);
106
         return RTC.setAudioOutputDevice(deviceId);
75
     },
107
     },
76
     /**
108
     /**

+ 17
- 0
modules/RTC/RTC.js View File

345
     return RTCUtils.getAudioOutputDevice();
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
  * Sets current audio output device.
366
  * Sets current audio output device.
350
  * @param {string} deviceId - id of 'audiooutput' device from
367
  * @param {string} deviceId - id of 'audiooutput' device from

+ 42
- 5
modules/RTC/RTCUtils.js View File

386
     eventEmitter.emit(RTCEvents.RTC_READY, true);
386
     eventEmitter.emit(RTCEvents.RTC_READY, true);
387
     screenObtainer.init(options, GUM);
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
      */
1219
      */
1208
     getAudioOutputDevice: function () {
1220
     getAudioOutputDevice: function () {
1209
         return audioOutputDeviceId;
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 View File

7
     AVAILABLE_DEVICES_CHANGED: "rtc.available_devices_changed",
7
     AVAILABLE_DEVICES_CHANGED: "rtc.available_devices_changed",
8
     TRACK_ATTACHED: "rtc.track_attached",
8
     TRACK_ATTACHED: "rtc.track_attached",
9
     AUDIO_OUTPUT_DEVICE_CHANGED: "rtc.audio_output_device_changed",
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
 module.exports = RTCEvents;
14
 module.exports = RTCEvents;

Loading…
Cancel
Save