瀏覽代碼

feat(rtcstats): move rtcstats init (#2766)

* move rtcstats init

* tame lint
master
Andrei Gavrilescu 6 月之前
父節點
當前提交
7016c799c8
沒有連結到貢獻者的電子郵件帳戶。
共有 4 個檔案被更改,包括 23 行新增54 行删除
  1. 4
    0
      JitsiConnection.ts
  2. 19
    42
      modules/RTCStats/RTCStats.ts
  3. 0
    11
      modules/RTCStats/interfaces.ts
  4. 0
    1
      modules/statistics/statistics.js

+ 4
- 0
JitsiConnection.ts 查看文件

@@ -2,6 +2,7 @@ import { getLogger } from '@jitsi/logger';
2 2
 
3 3
 import JitsiConference from './JitsiConference';
4 4
 import { JitsiConnectionEvents } from './JitsiConnectionEvents';
5
+import RTCStats from './modules/RTCStats/RTCStats';
5 6
 import FeatureFlags from './modules/flags/FeatureFlags';
6 7
 import Statistics from './modules/statistics/statistics';
7 8
 import XMPP from './modules/xmpp/xmpp';
@@ -95,6 +96,9 @@ export default class JitsiConnection {
95 96
      * to be used.
96 97
      */
97 98
     connect(options: IConnectOptions = {}): void {
99
+
100
+        RTCStats.startWithConnection(this);
101
+
98 102
         // if we get redirected, we set disableFocus to skip sending the conference request twice
99 103
         if (this.xmpp.moderator.targetUrl && !this.options.disableFocus && options.name) {
100 104
             // The domain (optional) will uses this.options.hosts.muc.toLowerCase() if not provided

+ 19
- 42
modules/RTCStats/RTCStats.ts 查看文件

@@ -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 = {

+ 0
- 11
modules/RTCStats/interfaces.ts 查看文件

@@ -1,14 +1,3 @@
1
-export interface IRTCStatsConfiguration {
2
-    analytics?: {
3
-        obfuscateRoomName?: boolean;
4
-        rtcstatsEnabled?: boolean;
5
-        rtcstatsEndpoint?: string;
6
-        rtcstatsPollInterval?: number;
7
-        rtcstatsSendSdp?: boolean;
8
-        rtcstatsStoreLogs?: boolean;
9
-    };
10
-}
11
-
12 1
 export interface ITraceOptions {
13 2
     endpoint: string;
14 3
     isBreakoutRoom: boolean;

+ 0
- 1
modules/statistics/statistics.js 查看文件

@@ -42,7 +42,6 @@ Statistics.init = function(options) {
42 42
 
43 43
     LocalStats.init();
44 44
     WatchRTC.init(options);
45
-    RTCStats.init(options);
46 45
 };
47 46
 
48 47
 /**

Loading…
取消
儲存