2022-09-06 07:42:59 +00:00
|
|
|
/* eslint-disable import/order */
|
|
|
|
import { IStore } from '../app/types';
|
2022-06-21 06:53:07 +00:00
|
|
|
import {
|
|
|
|
E2E_RTT_CHANGED,
|
2022-09-06 07:42:59 +00:00
|
|
|
CONFERENCE_JOINED,
|
2022-06-21 06:53:07 +00:00
|
|
|
CONFERENCE_TIMESTAMP_CHANGED,
|
2022-09-06 07:42:59 +00:00
|
|
|
CONFERENCE_UNIQUE_ID_SET,
|
|
|
|
CONFERENCE_WILL_LEAVE
|
|
|
|
|
|
|
|
// @ts-ignore
|
2022-06-21 06:53:07 +00:00
|
|
|
} from '../base/conference';
|
2022-04-08 12:24:58 +00:00
|
|
|
import { LIB_WILL_INIT } from '../base/lib-jitsi-meet/actionTypes';
|
2022-09-06 07:42:59 +00:00
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
import { DOMINANT_SPEAKER_CHANGED } from '../base/participants';
|
|
|
|
|
|
|
|
// @ts-ignore
|
2020-07-15 15:22:00 +00:00
|
|
|
import { MiddlewareRegistry } from '../base/redux';
|
2022-09-06 07:42:59 +00:00
|
|
|
|
|
|
|
// @ts-ignore
|
2022-05-16 13:56:37 +00:00
|
|
|
import { TRACK_ADDED, TRACK_UPDATED } from '../base/tracks';
|
2022-09-06 07:42:59 +00:00
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
import { isInBreakoutRoom, getCurrentRoomId } from '../breakout-rooms/functions';
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
import { extractFqnFromPath } from '../dynamic-branding/functions.any';
|
2022-04-06 09:10:31 +00:00
|
|
|
import { ADD_FACE_EXPRESSION } from '../face-landmarks/actionTypes';
|
2020-07-15 15:22:00 +00:00
|
|
|
|
|
|
|
import RTCStats from './RTCStats';
|
2022-09-06 07:42:59 +00:00
|
|
|
import { canSendRtcstatsData, connectAndSendIdentity, isRtcstatsEnabled } from './functions';
|
2020-07-15 15:22:00 +00:00
|
|
|
import logger from './logger';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Middleware which intercepts lib-jitsi-meet initialization and conference join in order init the
|
|
|
|
* rtcstats-client.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2022-09-06 07:42:59 +00:00
|
|
|
MiddlewareRegistry.register((store: IStore) => (next: Function) => (action: any) => {
|
|
|
|
const { dispatch, getState } = store;
|
|
|
|
const state = getState();
|
2020-07-15 15:22:00 +00:00
|
|
|
const config = state['features/base/config'];
|
2022-06-16 11:13:36 +00:00
|
|
|
const { analytics, faceLandmarks } = config;
|
2020-07-15 15:22:00 +00:00
|
|
|
|
|
|
|
switch (action.type) {
|
|
|
|
case LIB_WILL_INIT: {
|
2022-09-06 07:42:59 +00:00
|
|
|
if (isRtcstatsEnabled(state) && !RTCStats.isInitialized()) {
|
2020-07-15 15:22:00 +00:00
|
|
|
// RTCStats "proxies" WebRTC functions such as GUM and RTCPeerConnection by rewriting the global
|
|
|
|
// window functions. Because lib-jitsi-meet uses references to those functions that are taken on
|
|
|
|
// init, we need to add these proxies before it initializes, otherwise lib-jitsi-meet will use the
|
|
|
|
// original non proxy versions of these functions.
|
|
|
|
try {
|
2022-08-17 19:58:09 +00:00
|
|
|
// Default poll interval is 10000ms and standard stats will be used, if not provided in the config.
|
2022-09-06 07:42:59 +00:00
|
|
|
const pollInterval = analytics?.rtcstatsPollInterval || 10000;
|
|
|
|
const useLegacy = analytics?.rtcstatsUseLegacy || false;
|
|
|
|
const sendSdp = analytics?.rtcstatsSendSdp || false;
|
2020-07-15 15:22:00 +00:00
|
|
|
|
|
|
|
// Initialize but don't connect to the rtcstats server wss, as it will start sending data for all
|
|
|
|
// media calls made even before the conference started.
|
|
|
|
RTCStats.init({
|
2022-09-06 07:42:59 +00:00
|
|
|
endpoint: analytics?.rtcstatsEndpoint,
|
|
|
|
meetingFqn: extractFqnFromPath(state),
|
2021-04-14 09:32:16 +00:00
|
|
|
useLegacy,
|
2022-08-26 18:03:08 +00:00
|
|
|
pollInterval,
|
|
|
|
sendSdp
|
2020-07-15 15:22:00 +00:00
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
logger.error('Failed to initialize RTCStats: ', error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-09-06 07:42:59 +00:00
|
|
|
|
|
|
|
// Used for connecting to rtcstats server when joining a breakout room.
|
|
|
|
// Breakout rooms do not have a meetingUniqueId.
|
|
|
|
case CONFERENCE_JOINED: {
|
|
|
|
if (isInBreakoutRoom(getState())) {
|
|
|
|
connectAndSendIdentity(
|
|
|
|
dispatch,
|
|
|
|
state,
|
|
|
|
{
|
|
|
|
isBreakoutRoom: true,
|
|
|
|
roomId: getCurrentRoomId(getState())
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Used for connecting to rtcstats server when joining the main room.
|
|
|
|
// Using this event to be sure the meetingUniqueId can be retrieved.
|
|
|
|
case CONFERENCE_UNIQUE_ID_SET: {
|
|
|
|
if (!isInBreakoutRoom(getState())) {
|
|
|
|
// 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.
|
|
|
|
const { conference } = action;
|
|
|
|
const meetingUniqueId = conference && conference.getMeetingUniqueId();
|
|
|
|
|
|
|
|
connectAndSendIdentity(
|
|
|
|
dispatch,
|
|
|
|
state,
|
|
|
|
{
|
|
|
|
isBreakoutRoom: false,
|
|
|
|
meetingUniqueId
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-05-16 13:56:37 +00:00
|
|
|
case TRACK_ADDED: {
|
|
|
|
if (canSendRtcstatsData(state)) {
|
|
|
|
const jitsiTrack = action?.track?.jitsiTrack;
|
|
|
|
const { ssrc, videoType } = jitsiTrack || { };
|
|
|
|
|
|
|
|
// Remote tracks store their ssrc in the jitsiTrack object. Local tracks don't. See getSsrcByTrack.
|
2022-06-30 14:21:42 +00:00
|
|
|
if (videoType && ssrc && !jitsiTrack.isLocal() && !jitsiTrack.isAudioTrack()) {
|
2022-05-16 13:56:37 +00:00
|
|
|
RTCStats.sendVideoTypeData({
|
|
|
|
ssrc,
|
|
|
|
videoType
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TRACK_UPDATED: {
|
|
|
|
if (canSendRtcstatsData(state)) {
|
|
|
|
const { videoType, jitsiTrack } = action?.track || { };
|
|
|
|
const { ssrc } = jitsiTrack || { };
|
|
|
|
|
|
|
|
// if the videoType of the remote track has changed we expect to find it in track.videoType. grep for
|
|
|
|
// trackVideoTypeChanged.
|
2022-06-30 14:21:42 +00:00
|
|
|
if (videoType && ssrc && !jitsiTrack.isLocal() && !jitsiTrack.isAudioTrack()) {
|
2022-05-16 13:56:37 +00:00
|
|
|
|
|
|
|
RTCStats.sendVideoTypeData({
|
|
|
|
ssrc,
|
|
|
|
videoType
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2021-09-07 13:20:50 +00:00
|
|
|
case DOMINANT_SPEAKER_CHANGED: {
|
|
|
|
if (canSendRtcstatsData(state)) {
|
|
|
|
const { id, previousSpeakers } = action.participant;
|
|
|
|
|
|
|
|
RTCStats.sendDominantSpeakerData({ dominantSpeakerEndpoint: id,
|
|
|
|
previousSpeakers });
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-04-01 12:50:52 +00:00
|
|
|
case E2E_RTT_CHANGED: {
|
|
|
|
if (canSendRtcstatsData(state)) {
|
|
|
|
const { participant, rtt } = action.e2eRtt;
|
|
|
|
|
|
|
|
RTCStats.sendE2eRttData({
|
|
|
|
remoteEndpointId: participant.getId(),
|
|
|
|
rtt,
|
|
|
|
remoteRegion: participant.getProperty('region')
|
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-04-06 09:10:31 +00:00
|
|
|
case ADD_FACE_EXPRESSION: {
|
2022-06-16 11:13:36 +00:00
|
|
|
if (canSendRtcstatsData(state) && faceLandmarks && faceLandmarks.enableRTCStats) {
|
2022-04-11 09:26:31 +00:00
|
|
|
const { duration, faceExpression, timestamp } = action;
|
2021-11-26 10:24:28 +00:00
|
|
|
|
2022-09-06 07:42:59 +00:00
|
|
|
RTCStats.sendFaceLandmarksData({
|
2021-11-26 10:24:28 +00:00
|
|
|
duration,
|
2022-05-17 11:57:18 +00:00
|
|
|
faceLandmarks: faceExpression,
|
2022-04-11 09:26:31 +00:00
|
|
|
timestamp
|
2021-11-26 10:24:28 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-06-15 22:22:15 +00:00
|
|
|
case CONFERENCE_TIMESTAMP_CHANGED: {
|
|
|
|
if (canSendRtcstatsData(state)) {
|
2022-09-06 07:42:59 +00:00
|
|
|
const { conferenceTimestamp } = action;
|
2022-06-15 22:22:15 +00:00
|
|
|
|
|
|
|
RTCStats.sendConferenceTimestamp(conferenceTimestamp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-09-06 07:42:59 +00:00
|
|
|
case CONFERENCE_WILL_LEAVE: {
|
|
|
|
if (canSendRtcstatsData(state)) {
|
|
|
|
RTCStats.close();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2020-07-15 15:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
});
|