Browse Source

feat(rtcstats): send dominant speaker stats (#9883)

* send dominant speaker stats

* fix lint
master
Andrei Gavrilescu 4 years ago
parent
commit
f51e65d129
No account linked to committer's email address

+ 10
- 0
react/features/rtcstats/RTCStats.js View File

85
         this.trace && this.trace.identity('identity', null, identityData);
85
         this.trace && this.trace.identity('identity', null, identityData);
86
     }
86
     }
87
 
87
 
88
+    /**
89
+     * Send dominant speaker data, the data will be processed by rtcstats-server and saved in the dump file.
90
+     *
91
+     * @param {Object} dominantSpeakerData - Dominant speaker data to be saved in the rtcstats dump.
92
+     * @returns {void}
93
+     */
94
+    sendDominantSpeakerData(dominantSpeakerData) {
95
+        this.trace && this.trace.statsEntry('dominantSpeaker', null, dominantSpeakerData);
96
+    }
97
+
88
     /**
98
     /**
89
      * Connect to the rtcstats server instance. Stats (data obtained from getstats) won't be send until the
99
      * Connect to the rtcstats server instance. Stats (data obtained from getstats) won't be send until the
90
      * connect successfully initializes, however calls to GUM are recorded in an internal buffer even if not
100
      * connect successfully initializes, however calls to GUM are recorded in an internal buffer even if not

+ 13
- 0
react/features/rtcstats/functions.js View File

2
 
2
 
3
 import { toState } from '../base/redux';
3
 import { toState } from '../base/redux';
4
 
4
 
5
+import RTCStats from './RTCStats';
6
+
5
 /**
7
 /**
6
  * Checks whether rtcstats is enabled or not.
8
  * Checks whether rtcstats is enabled or not.
7
  *
9
  *
19
 
21
 
20
     return config?.analytics?.rtcstatsEnabled ?? false;
22
     return config?.analytics?.rtcstatsEnabled ?? false;
21
 }
23
 }
24
+
25
+/**
26
+ * Can the rtcstats service send data.
27
+ *
28
+ * @param {Function|Object} stateful - The redux store or {@code getState} function.
29
+ * @returns {boolean}
30
+ */
31
+export function canSendRtcstatsData(stateful: Function | Object) {
32
+
33
+    return isRtcstatsEnabled(stateful) && RTCStats.isInitialized();
34
+}

+ 18
- 5
react/features/rtcstats/middleware.js View File

1
 // @flow
1
 // @flow
2
 
2
 
3
 import { getAmplitudeIdentity } from '../analytics';
3
 import { getAmplitudeIdentity } from '../analytics';
4
-import { CONFERENCE_UNIQUE_ID_SET, getRoomName } from '../base/conference';
4
+import { CONFERENCE_UNIQUE_ID_SET, getConferenceOptions, getRoomName } from '../base/conference';
5
 import { LIB_WILL_INIT } from '../base/lib-jitsi-meet';
5
 import { LIB_WILL_INIT } from '../base/lib-jitsi-meet';
6
-import { getLocalParticipant } from '../base/participants';
6
+import { DOMINANT_SPEAKER_CHANGED, getLocalParticipant } from '../base/participants';
7
 import { MiddlewareRegistry } from '../base/redux';
7
 import { MiddlewareRegistry } from '../base/redux';
8
 
8
 
9
 import RTCStats from './RTCStats';
9
 import RTCStats from './RTCStats';
10
-import { isRtcstatsEnabled } from './functions';
10
+import { canSendRtcstatsData, isRtcstatsEnabled } from './functions';
11
 import logger from './logger';
11
 import logger from './logger';
12
 
12
 
13
 /**
13
 /**
50
         break;
50
         break;
51
     }
51
     }
52
     case CONFERENCE_UNIQUE_ID_SET: {
52
     case CONFERENCE_UNIQUE_ID_SET: {
53
-        if (isRtcstatsEnabled(state) && RTCStats.isInitialized()) {
53
+        if (canSendRtcstatsData(state)) {
54
+
54
             // Once the conference started connect to the rtcstats server and send data.
55
             // Once the conference started connect to the rtcstats server and send data.
55
             try {
56
             try {
56
                 RTCStats.connect();
57
                 RTCStats.connect();
57
 
58
 
58
                 const localParticipant = getLocalParticipant(state);
59
                 const localParticipant = getLocalParticipant(state);
60
+                const options = getConferenceOptions(state);
61
+
59
 
62
 
60
                 // Unique identifier for a conference session, not to be confused with meeting name
63
                 // Unique identifier for a conference session, not to be confused with meeting name
61
                 // i.e. If all participants leave a meeting it will have a different value on the next join.
64
                 // i.e. If all participants leave a meeting it will have a different value on the next join.
71
                 // conference with a specific version.
74
                 // conference with a specific version.
72
                 RTCStats.sendIdentityData({
75
                 RTCStats.sendIdentityData({
73
                     ...getAmplitudeIdentity(),
76
                     ...getAmplitudeIdentity(),
74
-                    ...config,
77
+                    ...options,
78
+                    endpointId: localParticipant?.id,
75
                     confName: getRoomName(state),
79
                     confName: getRoomName(state),
76
                     displayName: localParticipant?.name,
80
                     displayName: localParticipant?.name,
77
                     meetingUniqueId
81
                     meetingUniqueId
83
         }
87
         }
84
         break;
88
         break;
85
     }
89
     }
90
+    case DOMINANT_SPEAKER_CHANGED: {
91
+        if (canSendRtcstatsData(state)) {
92
+            const { id, previousSpeakers } = action.participant;
93
+
94
+            RTCStats.sendDominantSpeakerData({ dominantSpeakerEndpoint: id,
95
+                previousSpeakers });
96
+        }
97
+        break;
98
+    }
86
     }
99
     }
87
 
100
 
88
     return next(action);
101
     return next(action);

Loading…
Cancel
Save