|
@@ -0,0 +1,133 @@
|
|
1
|
+import { getLogger } from 'jitsi-meet-logger';
|
|
2
|
+
|
|
3
|
+import * as ConferenceEvents from '../../JitsiConferenceEvents';
|
|
4
|
+import * as ConnectionQualityEvents from '../../service/connectivity/ConnectionQualityEvents';
|
|
5
|
+import * as MediaType from '../../service/RTC/MediaType';
|
|
6
|
+import { createAudioOutputProblemEvent } from '../../service/statistics/AnalyticsEvents';
|
|
7
|
+
|
|
8
|
+import Statistics from './statistics';
|
|
9
|
+
|
|
10
|
+const logger = getLogger(__filename);
|
|
11
|
+
|
|
12
|
+/**
|
|
13
|
+ * Number of remote samples that will be used for comparison with local ones.
|
|
14
|
+ */
|
|
15
|
+const NUMBER_OF_REMOTE_SAMPLES = 3;
|
|
16
|
+
|
|
17
|
+/**
|
|
18
|
+ * Collects the average audio levels per participant from the local stats and the stats received by every remote
|
|
19
|
+ * participant and compares them to detect potential audio problem for a participant.
|
|
20
|
+ */
|
|
21
|
+export default class AudioOutputProblemDetector {
|
|
22
|
+
|
|
23
|
+ /**
|
|
24
|
+ * Creates new <tt>AudioOutputProblemDetector</tt> instance.
|
|
25
|
+ *
|
|
26
|
+ * @param {JitsiCofnerence} conference - The conference instance to be monitored.
|
|
27
|
+ */
|
|
28
|
+ constructor(conference) {
|
|
29
|
+ this._conference = conference;
|
|
30
|
+ this._lastReceivedAudioLevel = {};
|
|
31
|
+ this._reportedParticipants = [];
|
|
32
|
+ this._onLocalAudioLevelsReport = this._onLocalAudioLevelsReport.bind(this);
|
|
33
|
+ this._onRemoteAudioLevelReceived = this._onRemoteAudioLevelReceived.bind(this);
|
|
34
|
+ this._clearUserData = this._clearUserData.bind(this);
|
|
35
|
+ this._conference.on(ConnectionQualityEvents.REMOTE_STATS_UPDATED, this._onRemoteAudioLevelReceived);
|
|
36
|
+ this._conference.statistics.addConnectionStatsListener(this._onLocalAudioLevelsReport);
|
|
37
|
+ this._conference.on(ConferenceEvents.USER_LEFT, this._clearUserData);
|
|
38
|
+ }
|
|
39
|
+
|
|
40
|
+ /**
|
|
41
|
+ * A listener for audio level data received by a remote participant.
|
|
42
|
+ *
|
|
43
|
+ * @param {string} userID - The user id of the participant that sent the data.
|
|
44
|
+ * @param {number} audioLevel - The average audio level value.
|
|
45
|
+ * @returns {void}
|
|
46
|
+ */
|
|
47
|
+ _onRemoteAudioLevelReceived(userID, { avgAudioLevels }) {
|
|
48
|
+ if (this._reportedParticipants.indexOf(userID) !== -1) {
|
|
49
|
+ return;
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ if (!Array.isArray(this._lastReceivedAudioLevel[userID])) {
|
|
53
|
+ this._lastReceivedAudioLevel[userID] = [ ];
|
|
54
|
+ } else if (this._lastReceivedAudioLevel[userID].length >= NUMBER_OF_REMOTE_SAMPLES) {
|
|
55
|
+ this._lastReceivedAudioLevel[userID].shift();
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ this._lastReceivedAudioLevel[userID].push(avgAudioLevels);
|
|
59
|
+
|
|
60
|
+ }
|
|
61
|
+
|
|
62
|
+ /**
|
|
63
|
+ * A listener for audio level data retrieved by the local stats.
|
|
64
|
+ *
|
|
65
|
+ * @param {TraceablePeerConnection} tpc - The <tt>TraceablePeerConnection</tt> instance used to gather the data.
|
|
66
|
+ * @param {Object} avgAudioLevels - The average audio levels per participant.
|
|
67
|
+ * @returns {void}
|
|
68
|
+ */
|
|
69
|
+ _onLocalAudioLevelsReport(tpc, { avgAudioLevels }) {
|
|
70
|
+ if (tpc !== this._conference.getActivePeerConnection()) {
|
|
71
|
+ return;
|
|
72
|
+ }
|
|
73
|
+
|
|
74
|
+ Object.keys(this._lastReceivedAudioLevel).forEach(userID => {
|
|
75
|
+ if (this._reportedParticipants.indexOf(userID) !== -1) {
|
|
76
|
+ // Do not report the participant again.
|
|
77
|
+ return;
|
|
78
|
+ }
|
|
79
|
+
|
|
80
|
+ const remoteAudioLevels = this._lastReceivedAudioLevel[userID];
|
|
81
|
+ const participant = this._conference.getParticipantById(userID);
|
|
82
|
+
|
|
83
|
+ if (participant) {
|
|
84
|
+ const tracks = participant.getTracksByMediaType(MediaType.AUDIO);
|
|
85
|
+
|
|
86
|
+ if (tracks.length > 0 && participant.isAudioMuted()) {
|
|
87
|
+ // We don't need to report an error if everything seems fine with the participant and its tracks but
|
|
88
|
+ // the participant is audio muted.
|
|
89
|
+ return;
|
|
90
|
+ }
|
|
91
|
+ }
|
|
92
|
+
|
|
93
|
+ if ((!(userID in avgAudioLevels) || avgAudioLevels[userID] === 0)
|
|
94
|
+ && Array.isArray(remoteAudioLevels)
|
|
95
|
+ && remoteAudioLevels.length === NUMBER_OF_REMOTE_SAMPLES
|
|
96
|
+ && remoteAudioLevels.every(audioLevel => audioLevel > 0)) {
|
|
97
|
+ const remoteAudioLevelsString = JSON.stringify(remoteAudioLevels);
|
|
98
|
+
|
|
99
|
+ Statistics.sendAnalytics(
|
|
100
|
+ createAudioOutputProblemEvent(userID, avgAudioLevels[userID], remoteAudioLevelsString));
|
|
101
|
+ logger.warn(`A potential problem is detected with the audio output for participant ${
|
|
102
|
+ userID}, local audio levels: ${avgAudioLevels[userID]}, remote audio levels: ${
|
|
103
|
+ remoteAudioLevelsString}`);
|
|
104
|
+ this._reportedParticipants.push(userID);
|
|
105
|
+ this._clearUserData();
|
|
106
|
+ }
|
|
107
|
+ });
|
|
108
|
+ }
|
|
109
|
+
|
|
110
|
+ /**
|
|
111
|
+ * Clears the data stored for a participant.
|
|
112
|
+ *
|
|
113
|
+ * @param {string} userID - The id of the participant.
|
|
114
|
+ * @returns {void}
|
|
115
|
+ */
|
|
116
|
+ _clearUserData(userID) {
|
|
117
|
+ delete this._lastReceivedAudioLevel[userID];
|
|
118
|
+ }
|
|
119
|
+
|
|
120
|
+ /**
|
|
121
|
+ * Disposes the allocated resources.
|
|
122
|
+ *
|
|
123
|
+ * @returns {void}
|
|
124
|
+ */
|
|
125
|
+ dispose() {
|
|
126
|
+ this._conference.off(ConnectionQualityEvents.REMOTE_STATS_UPDATED, this._onRemoteAudioLevelReceived);
|
|
127
|
+ this._conference.off(ConferenceEvents.USER_LEFT, this._clearUserData);
|
|
128
|
+ this._conference.statistics.removeConnectionStatsListener(this._onLocalAudioLevelsReport);
|
|
129
|
+ this._lastReceivedAudioLevel = undefined;
|
|
130
|
+ this._reportedParticipants = undefined;
|
|
131
|
+ this._conference = undefined;
|
|
132
|
+ }
|
|
133
|
+}
|