Skip to content

Commit

Permalink
feat(analytics)connection time stats in join event
Browse files Browse the repository at this point in the history
  • Loading branch information
hristoterezov committed Dec 6, 2023
1 parent 7841a38 commit f5fd83f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 12 deletions.
23 changes: 21 additions & 2 deletions JitsiConference.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import LocalStatsCollector from './modules/statistics/LocalStatsCollector';
import SpeakerStatsCollector from './modules/statistics/SpeakerStatsCollector';
import Statistics from './modules/statistics/statistics';
import GlobalOnErrorHandler from './modules/util/GlobalOnErrorHandler';
import { safeSubtract } from './modules/util/MathUtil';
import RandomUtil from './modules/util/RandomUtil';
import ComponentsVersions from './modules/version/ComponentsVersions';
import VideoSIPGW from './modules/videosipgw/VideoSIPGW';
Expand Down Expand Up @@ -1788,11 +1789,10 @@ JitsiConference.prototype.onMemberJoined = function(
/**
* Get notified when we joined the room.
*
* FIXME This should NOT be exposed!
*
* @private
*/
JitsiConference.prototype._onMucJoined = function() {
this._numberOfParticipantsOnJoin = this.getParticipantCount();
this._maybeStartOrStopP2P();
};

Expand Down Expand Up @@ -3670,7 +3670,26 @@ JitsiConference.prototype._sendConferenceJoinAnalyticsEvent = function() {
return;
}

const conferenceConnectionTimes = this.getConnectionTimes();
const xmppConnectionTimes = this.connection.getConnectionTimes();
const gumStart = window.connectionTimes['firstObtainPermissions.start'];
const gumEnd = window.connectionTimes['firstObtainPermissions.end'];
const globalNSConnectionTimes = window.JitsiMeetJS?.app?.connectionTimes ?? {};
const connectionTimes = {
...conferenceConnectionTimes,
...xmppConnectionTimes,
...globalNSConnectionTimes,
gumDuration: safeSubtract(gumEnd, gumStart),
xmppConnectingTime: safeSubtract(xmppConnectionTimes.connected, xmppConnectionTimes.connecting),
connectedToMUCJoinedTime: safeSubtract(
conferenceConnectionTimes['muc.joined'], xmppConnectionTimes.connected),
connectingToMUCJoinedTime: safeSubtract(
conferenceConnectionTimes['muc.joined'], xmppConnectionTimes.connecting),
numberOfParticipantsOnJoin: this._numberOfParticipantsOnJoin
};

Statistics.sendAnalytics(createConferenceEvent('joined', {
...connectionTimes,
meetingId,
participantId: `${meetingId}.${this._statsCurrentId}`
}));
Expand Down
43 changes: 33 additions & 10 deletions JitsiMeetJS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ const logger = Logger.getLogger(__filename);
*/
const USER_MEDIA_SLOW_PROMISE_TIMEOUT = 1000;

/**
* Indicates whether GUM has been executed or not.
*/
let hasGUMExecuted = false;

/**
* Extracts from an 'options' objects with a specific format (TODO what IS the
* format?) the attributes which are to be logged in analytics events.
Expand Down Expand Up @@ -186,17 +191,17 @@ export default {
},

/**
* Expose rtcstats to the public API.
* Expose rtcstats to the public API.
*/
rtcstats: {
/**
* Sends identity data to the rtcstats server. This data is used
* to identify the specifics of a particular client, it can be any object
* and will show in the generated rtcstats dump under "identity" entries.
*
*
* @param {Object} identityData - Identity data to send.
* @returns {void}
*/
*/
sendIdentityEntry(identityData) {
RTCStats.sendIdentity(identityData);
},
Expand All @@ -213,7 +218,7 @@ export default {
/**
* Events generated by rtcstats, such as PeerConnections state,
* and websocket connection state.
*
*
* @param {RTCStatsEvents} event - The event name.
* @param {function} handler - The event handler.
*/
Expand Down Expand Up @@ -320,18 +325,31 @@ export default {
}, USER_MEDIA_SLOW_PROMISE_TIMEOUT);
}

let isFirstGUM = false;
let startTS = window.performance.now();

if (!window.connectionTimes) {
window.connectionTimes = {};
}
window.connectionTimes['obtainPermissions.start']
= window.performance.now();

if (!hasGUMExecuted) {
hasGUMExecuted = true;
isFirstGUM = true;
window.connectionTimes['firstObtainPermissions.start'] = startTS;
}
window.connectionTimes['obtainPermissions.start'] = startTS;

return RTC.obtainAudioAndVideoPermissions(restOptions)
.then(tracks => {
promiseFulfilled = true;

window.connectionTimes['obtainPermissions.end']
= window.performance.now();
let endTS = window.performance.now();

window.connectionTimes['obtainPermissions.end'] = endTS;

if (isFirstGUM) {
window.connectionTimes['firstObtainPermissions.end'] = endTS;
}

Statistics.sendAnalytics(
createGetUserMediaEvent(
Expand Down Expand Up @@ -391,8 +409,13 @@ export default {
createGetUserMediaEvent('error', attributes));
}

window.connectionTimes['obtainPermissions.end']
= window.performance.now();
let endTS = window.performance.now();

window.connectionTimes['obtainPermissions.end'] = endTS;

if (isFirstGUM) {
window.connectionTimes['firstObtainPermissions.end'] = endTS;
}

return Promise.reject(error);
});
Expand Down
12 changes: 12 additions & 0 deletions modules/util/MathUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,15 @@ export class RunningAverage {
return this.average;
}
}


/**
* Subtracts the two numbers passed or returns 0 if any of the arguments are not a number.
*
* @param {*} x - The number we subtract from.
* @param {*} y - The number we subtract.
* @returns {number} - x - y or 0 if x or is not a number.
*/
export function safeSubtract(x, y) {
return !isNaN(x) && !isNaN(y) ? x - y : 0;
}

0 comments on commit f5fd83f

Please sign in to comment.