2022-09-06 07:42:59 +00:00
|
|
|
// @ts-ignore
|
|
|
|
import { jitsiLocalStorage } from '@jitsi/js-utils';
|
|
|
|
|
2022-09-07 08:20:05 +00:00
|
|
|
import { getAmplitudeIdentity } from '../analytics/functions';
|
2022-10-11 10:47:54 +00:00
|
|
|
import { IStore } from '../app/types';
|
|
|
|
import { IStateful } from '../base/app/types';
|
|
|
|
import { getAnalyticsRoomName, getConferenceOptions } from '../base/conference/functions';
|
|
|
|
import { getLocalParticipant } from '../base/participants/functions';
|
2022-09-22 10:06:31 +00:00
|
|
|
import { toState } from '../base/redux/functions';
|
2022-09-06 07:42:59 +00:00
|
|
|
|
|
|
|
import RTCStats from './RTCStats';
|
|
|
|
import logger from './logger';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether rtcstats is enabled or not.
|
|
|
|
*
|
2022-09-22 10:06:31 +00:00
|
|
|
* @param {IStateful} stateful - The redux store or {@code getState} function.
|
2022-09-06 07:42:59 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-09-22 10:06:31 +00:00
|
|
|
export function isRtcstatsEnabled(stateful: IStateful) {
|
2022-09-06 07:42:59 +00:00
|
|
|
const state = toState(stateful);
|
2022-09-22 10:06:31 +00:00
|
|
|
const { analytics } = state['features/base/config'];
|
2022-09-06 07:42:59 +00:00
|
|
|
|
2022-09-22 10:06:31 +00:00
|
|
|
return analytics?.rtcstatsEnabled ?? false;
|
2022-09-06 07:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Can the rtcstats service send data.
|
|
|
|
*
|
2022-09-22 10:06:31 +00:00
|
|
|
* @param {IStateful} stateful - The redux store or {@code getState} function.
|
2022-09-06 07:42:59 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-09-22 10:06:31 +00:00
|
|
|
export function canSendRtcstatsData(stateful: IStateful) {
|
2022-09-06 07:42:59 +00:00
|
|
|
return isRtcstatsEnabled(stateful) && RTCStats.isInitialized();
|
|
|
|
}
|
|
|
|
|
|
|
|
type Identity = {
|
|
|
|
isBreakoutRoom: boolean;
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
meetingUniqueId?: string;
|
|
|
|
roomId?: string;
|
2022-09-08 09:52:36 +00:00
|
|
|
};
|
2022-09-06 07:42:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Connects to the rtcstats service and sends the identity data.
|
|
|
|
*
|
2022-09-22 10:06:31 +00:00
|
|
|
* @param {IStore} store - Redux Store.
|
2022-09-06 07:42:59 +00:00
|
|
|
* @param {Identity} identity - Identity data for the client.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-09-22 10:06:31 +00:00
|
|
|
export function connectAndSendIdentity({ getState, dispatch }: IStore, identity: Identity) {
|
|
|
|
const state = getState();
|
2022-09-06 07:42:59 +00:00
|
|
|
|
|
|
|
if (canSendRtcstatsData(state)) {
|
|
|
|
|
|
|
|
// Once the conference started connect to the rtcstats server and send data.
|
|
|
|
try {
|
|
|
|
RTCStats.connect(identity.isBreakoutRoom);
|
|
|
|
const localParticipant = getLocalParticipant(state);
|
|
|
|
const options = getConferenceOptions(state);
|
|
|
|
|
|
|
|
// The current implementation of rtcstats-server is configured to send data to amplitude, thus
|
|
|
|
// we add identity specific information so we can correlate on the amplitude side. If amplitude is
|
|
|
|
// not configured an empty object will be sent.
|
|
|
|
// The current configuration of the conference is also sent as metadata to rtcstats server.
|
|
|
|
// This is done in order to facilitate queries based on different conference configurations.
|
|
|
|
// e.g. Find all RTCPeerConnections that connect to a specific shard or were created in a
|
|
|
|
// conference with a specific version.
|
|
|
|
// XXX(george): we also want to be able to correlate between rtcstats and callstats, so we're
|
|
|
|
// appending the callstats user name (if it exists) to the display name.
|
|
|
|
const displayName = options.statisticsId
|
|
|
|
|| options.statisticsDisplayName
|
|
|
|
|| jitsiLocalStorage.getItem('callStatsUserName');
|
|
|
|
|
|
|
|
RTCStats.sendIdentityData({
|
|
|
|
...getAmplitudeIdentity(),
|
|
|
|
...options,
|
|
|
|
endpointId: localParticipant?.id,
|
|
|
|
confName: getAnalyticsRoomName(state, dispatch),
|
|
|
|
displayName,
|
|
|
|
...identity
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
// If the connection failed do not impact jitsi-meet just silently fail.
|
|
|
|
logger.error('RTCStats connect failed with: ', error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-09-22 10:06:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the faceLandmarks data can be sent to the rtcstats server.
|
|
|
|
*
|
|
|
|
* @param {IStateful} stateful - The redux store or {@code getState} function.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
export function canSendFaceLandmarksRtcstatsData(stateful: IStateful): boolean {
|
|
|
|
const state = toState(stateful);
|
|
|
|
const { faceLandmarks } = state['features/base/config'];
|
|
|
|
|
|
|
|
if (faceLandmarks?.enableRTCStats && canSendRtcstatsData(state)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|