Compare commits

...

6 Commits

Author SHA1 Message Date
George Politis
202210797a Removes obsolette comment. 2023-04-14 14:21:48 +00:00
George Politis
c6b1560534 Bind the statsEntry callback to this. 2023-04-14 14:17:31 +00:00
George Politis
fbec4276c1 Fixes the linter and adds a warning. 2023-04-14 13:41:26 +00:00
George Politis
7545bfbe55 Uses lighter syntax. 2023-04-12 14:29:11 +00:00
George Politis
5c4f94e730 Wrap the sendStats method. 2023-04-12 14:26:48 +00:00
George Politis
b893105a6d fix: Reinitialize rtcstats when the config changes
The mobile app does not exit after the user has left the meeting. This
means we need to re-initialize rtcstats every time a user joins a call to
be sure we are using the correct deployment information.
2023-04-06 12:22:57 +00:00
2 changed files with 73 additions and 14 deletions

View File

@@ -47,9 +47,46 @@ function connectionFilter(config: any) {
*/
class RTCStats {
trace: any;
initialized = false;
options?: InitOptions;
isPeerConnectionWrapped = false;
connStateEvents: any = [];
/**
* Initialize the rtcstats components, if the options have changed.
*
* @param {Oject} newOptions -.
* @returns {void}
*/
maybeInit(newOptions: InitOptions) {
const oldOptions = this.options;
const changed = !oldOptions || (oldOptions.endpoint !== newOptions.endpoint
|| oldOptions.meetingFqn !== newOptions.meetingFqn
|| oldOptions.pollInterval !== newOptions.pollInterval
|| oldOptions.sendSdp !== newOptions.sendSdp
|| oldOptions.useLegacy !== newOptions.useLegacy);
if (changed) {
this.reset();
if (newOptions.meetingFqn && newOptions.endpoint) {
this.init(newOptions);
} else {
logger.warn('RTCStats is enabled but it has not been configured.');
}
}
}
/**
* Wrapper method for the underlying trace object to be used as a static reference from inside the wrapped
* PeerConnection.
*
* @param {any[]} data - The stats entry to send to the rtcstats endpoint.
* @returns {void}
*/
statsEntry(...data: any[]) {
this.trace?.statsEntry(data);
}
/**
* Initialize the rtcstats components. First off we initialize the trace, which is a wrapped websocket
* that does the actual communication with the server. Secondly, the rtcstats component is initialized,
@@ -77,17 +114,22 @@ class RTCStats {
useLegacy
};
const rtcstatsOptions = {
connectionFilter,
pollInterval,
useLegacy,
sendSdp,
eventCallback: this.handleRtcstatsEvent.bind(this)
};
this.trace = traceInit(traceOptions);
rtcstatsInit(this.trace, rtcstatsOptions);
this.initialized = true;
if (!this.isPeerConnectionWrapped) {
const rtcstatsOptions = {
connectionFilter,
pollInterval,
useLegacy,
sendSdp,
eventCallback: this.handleRtcstatsEvent.bind(this)
};
const statsEntryCallback = { statsEntry: this.statsEntry.bind(this) };
rtcstatsInit(statsEntryCallback, rtcstatsOptions);
this.isPeerConnectionWrapped = true;
}
this.options = options;
}
/**
@@ -96,7 +138,21 @@ class RTCStats {
* @returns {boolean}
*/
isInitialized() {
return this.initialized;
return this.options !== undefined;
}
/**
* Resets the rtcstats.
*
* @returns {void}
*/
reset() {
delete this.options;
if (this.trace) {
this.trace.close();
delete this.trace;
}
}
/**

View File

@@ -41,7 +41,7 @@ MiddlewareRegistry.register((store: IStore) => (next: Function) => (action: AnyA
switch (action.type) {
case LIB_WILL_INIT: {
if (isRtcstatsEnabled(state) && !RTCStats.isInitialized()) {
if (isRtcstatsEnabled(state)) {
// 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
@@ -54,7 +54,8 @@ MiddlewareRegistry.register((store: IStore) => (next: Function) => (action: AnyA
// 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({
RTCStats.maybeInit({
endpoint: analytics?.rtcstatsEndpoint,
meetingFqn: extractFqnFromPath(state),
useLegacy,
@@ -64,6 +65,8 @@ MiddlewareRegistry.register((store: IStore) => (next: Function) => (action: AnyA
} catch (error) {
logger.error('Failed to initialize RTCStats: ', error);
}
} else {
RTCStats.reset();
}
break;
}