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

* send dominant speaker stats

* fix lint
This commit is contained in:
Andrei Gavrilescu 2021-09-07 16:20:50 +03:00 committed by GitHub
parent 56c0edc896
commit f51e65d129
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 5 deletions

View File

@ -85,6 +85,16 @@ class RTCStats {
this.trace && this.trace.identity('identity', null, identityData);
}
/**
* Send dominant speaker data, the data will be processed by rtcstats-server and saved in the dump file.
*
* @param {Object} dominantSpeakerData - Dominant speaker data to be saved in the rtcstats dump.
* @returns {void}
*/
sendDominantSpeakerData(dominantSpeakerData) {
this.trace && this.trace.statsEntry('dominantSpeaker', null, dominantSpeakerData);
}
/**
* Connect to the rtcstats server instance. Stats (data obtained from getstats) won't be send until the
* connect successfully initializes, however calls to GUM are recorded in an internal buffer even if not

View File

@ -2,6 +2,8 @@
import { toState } from '../base/redux';
import RTCStats from './RTCStats';
/**
* Checks whether rtcstats is enabled or not.
*
@ -19,3 +21,14 @@ export function isRtcstatsEnabled(stateful: Function | Object) {
return config?.analytics?.rtcstatsEnabled ?? false;
}
/**
* Can the rtcstats service send data.
*
* @param {Function|Object} stateful - The redux store or {@code getState} function.
* @returns {boolean}
*/
export function canSendRtcstatsData(stateful: Function | Object) {
return isRtcstatsEnabled(stateful) && RTCStats.isInitialized();
}

View File

@ -1,13 +1,13 @@
// @flow
import { getAmplitudeIdentity } from '../analytics';
import { CONFERENCE_UNIQUE_ID_SET, getRoomName } from '../base/conference';
import { CONFERENCE_UNIQUE_ID_SET, getConferenceOptions, getRoomName } from '../base/conference';
import { LIB_WILL_INIT } from '../base/lib-jitsi-meet';
import { getLocalParticipant } from '../base/participants';
import { DOMINANT_SPEAKER_CHANGED, getLocalParticipant } from '../base/participants';
import { MiddlewareRegistry } from '../base/redux';
import RTCStats from './RTCStats';
import { isRtcstatsEnabled } from './functions';
import { canSendRtcstatsData, isRtcstatsEnabled } from './functions';
import logger from './logger';
/**
@ -50,12 +50,15 @@ MiddlewareRegistry.register(store => next => action => {
break;
}
case CONFERENCE_UNIQUE_ID_SET: {
if (isRtcstatsEnabled(state) && RTCStats.isInitialized()) {
if (canSendRtcstatsData(state)) {
// Once the conference started connect to the rtcstats server and send data.
try {
RTCStats.connect();
const localParticipant = getLocalParticipant(state);
const options = getConferenceOptions(state);
// Unique identifier for a conference session, not to be confused with meeting name
// i.e. If all participants leave a meeting it will have a different value on the next join.
@ -71,7 +74,8 @@ MiddlewareRegistry.register(store => next => action => {
// conference with a specific version.
RTCStats.sendIdentityData({
...getAmplitudeIdentity(),
...config,
...options,
endpointId: localParticipant?.id,
confName: getRoomName(state),
displayName: localParticipant?.name,
meetingUniqueId
@ -83,6 +87,15 @@ MiddlewareRegistry.register(store => next => action => {
}
break;
}
case DOMINANT_SPEAKER_CHANGED: {
if (canSendRtcstatsData(state)) {
const { id, previousSpeakers } = action.participant;
RTCStats.sendDominantSpeakerData({ dominantSpeakerEndpoint: id,
previousSpeakers });
}
break;
}
}
return next(action);