|
@@ -16,13 +16,16 @@ import EventEmitter from '../util/EventEmitter';
|
16
|
16
|
|
17
|
17
|
import DefaultLogStorage from './DefaulLogStorage';
|
18
|
18
|
import { RTC_STATS_PC_EVENT, RTC_STATS_WC_DISCONNECTED } from './RTCStatsEvents';
|
19
|
|
-import { IRTCStatsConfiguration, ITraceOptions } from './interfaces';
|
|
19
|
+import { ITraceOptions } from './interfaces';
|
20
|
20
|
|
21
|
21
|
const logger = getLogger('modules/RTCStats/RTCStats');
|
22
|
22
|
|
23
|
23
|
/**
|
24
|
24
|
* RTCStats Singleton that is initialized only once for the lifetime of the app, subsequent calls to init will be
|
25
|
25
|
* ignored. Config and conference changes are handled by the start method.
|
|
26
|
+ * RTCStats "proxies" WebRTC functions such as GUM and RTCPeerConnection by rewriting the global objects.
|
|
27
|
+ * The proxies will then send data to the rtcstats server via the trace object.
|
|
28
|
+ * The initialization procedure must be called once after lib-jitsi-meet is loaded.
|
26
|
29
|
*/
|
27
|
30
|
class RTCStats {
|
28
|
31
|
public events: EventEmitter = new EventEmitter();
|
|
@@ -31,47 +34,12 @@ class RTCStats {
|
31
|
34
|
private _initialized: boolean = false;
|
32
|
35
|
private _trace: any = null;
|
33
|
36
|
|
34
|
|
- /**
|
35
|
|
- * RTCStats "proxies" WebRTC functions such as GUM and RTCPeerConnection by rewriting the global objects.
|
36
|
|
- * The proxies will then send data to the rtcstats server via the trace object.
|
37
|
|
- * The initialization procedure must be called once when lib-jitsi-meet is loaded.
|
38
|
|
- *
|
39
|
|
- * @param {IRTCStatsConfiguration} initConfig initial config for rtcstats.
|
40
|
|
- * @returns {void}
|
41
|
|
- */
|
42
|
|
- init(initConfig: IRTCStatsConfiguration) {
|
43
|
|
- const {
|
44
|
|
- analytics: {
|
45
|
|
- rtcstatsPollInterval: pollInterval = 10000,
|
46
|
|
- rtcstatsSendSdp: sendSdp = false,
|
47
|
|
- rtcstatsEnabled = false
|
48
|
|
- } = {}
|
49
|
|
- } = initConfig;
|
50
|
|
-
|
51
|
|
- // If rtcstats is not enabled or already initialized, do nothing.
|
52
|
|
- // Calling rtcsatsInit multiple times will cause the global objects to be rewritten multiple times,
|
53
|
|
- // with unforeseen consequences.
|
54
|
|
- if (!rtcstatsEnabled || this._initialized) {
|
55
|
|
- return;
|
56
|
|
- }
|
57
|
|
-
|
58
|
|
- rtcstatsInit(
|
59
|
|
- { statsEntry: this.sendStatsEntry.bind(this) },
|
60
|
|
- { pollInterval,
|
61
|
|
- useLegacy: false,
|
62
|
|
- sendSdp,
|
63
|
|
- eventCallback: event => this.events.emit(RTC_STATS_PC_EVENT, event) }
|
64
|
|
- );
|
65
|
|
-
|
66
|
|
- this._initialized = true;
|
67
|
|
- }
|
68
|
|
-
|
69
|
37
|
isTraceAvailable() {
|
70
|
38
|
return this._trace !== null;
|
71
|
39
|
}
|
72
|
40
|
|
73
|
41
|
/**
|
74
|
|
- * A JitsiConnection instance is created before the conference is joined, so even though
|
|
42
|
+ * A JitsiConnection instance is created before the conference is joined, so even though
|
75
|
43
|
* we don't have any conference specific data yet, we can initialize the trace module and
|
76
|
44
|
* send any logs that might of otherwise be missed in case an error occurs between the connection
|
77
|
45
|
* and conference initialization.
|
|
@@ -85,7 +53,9 @@ class RTCStats {
|
85
|
53
|
const {
|
86
|
54
|
analytics: {
|
87
|
55
|
rtcstatsEndpoint: endpoint = '',
|
88
|
|
- rtcstatsEnabled = false
|
|
56
|
+ rtcstatsEnabled = false,
|
|
57
|
+ rtcstatsPollInterval: pollInterval = 10000,
|
|
58
|
+ rtcstatsSendSdp: sendSdp = false
|
89
|
59
|
} = {},
|
90
|
60
|
} = options;
|
91
|
61
|
|
|
@@ -93,11 +63,18 @@ class RTCStats {
|
93
|
63
|
// don't always re-initialize the module and could create multiple connections with different options.
|
94
|
64
|
if (!rtcstatsEnabled) return;
|
95
|
65
|
|
96
|
|
- // If rtcstats proxy module is not initialized, do nothing (should never happen).
|
|
66
|
+ // If rtcstats already initialized, do nothing.
|
|
67
|
+ // Calling rtcsatsInit multiple times will cause the global objects to be rewritten multiple times,
|
|
68
|
+ // with unforeseen consequences.
|
97
|
69
|
if (!this._initialized) {
|
98
|
|
- logger.error('Calling startWithConnection before RTCStats proxy module is initialized.');
|
99
|
|
-
|
100
|
|
- return;
|
|
70
|
+ rtcstatsInit(
|
|
71
|
+ { statsEntry: this.sendStatsEntry.bind(this) },
|
|
72
|
+ { pollInterval,
|
|
73
|
+ useLegacy: false,
|
|
74
|
+ sendSdp,
|
|
75
|
+ eventCallback: event => this.events.emit(RTC_STATS_PC_EVENT, event) }
|
|
76
|
+ );
|
|
77
|
+ this._initialized = true;
|
101
|
78
|
}
|
102
|
79
|
|
103
|
80
|
const traceOptions: ITraceOptions = {
|