|
@@ -33,20 +33,48 @@ let isCallstatsLoaded = false;
|
33
|
33
|
* downloading their API as soon as possible and (2) do the downloading
|
34
|
34
|
* asynchronously.
|
35
|
35
|
*
|
36
|
|
- * @param customScriptUrl
|
|
36
|
+ * @param {StatisticsOptions} options - Options to use for downloading and
|
|
37
|
+ * initializing callstats backend.
|
37
|
38
|
*/
|
38
|
|
-function loadCallStatsAPI(customScriptUrl) {
|
|
39
|
+function loadCallStatsAPI(options) {
|
39
|
40
|
if (!isCallstatsLoaded) {
|
40
|
41
|
ScriptUtil.loadScript(
|
41
|
|
- customScriptUrl
|
|
42
|
+ options.customScriptUrl
|
42
|
43
|
|| 'https://api.callstats.io/static/callstats-ws.min.js',
|
43
|
44
|
/* async */ true,
|
44
|
|
- /* prepend */ true);
|
|
45
|
+ /* prepend */ true,
|
|
46
|
+ /* relativeURL */ undefined,
|
|
47
|
+ /* loadCallback */ () => _initCallStatsBackend(options)
|
|
48
|
+ );
|
45
|
49
|
isCallstatsLoaded = true;
|
46
|
50
|
}
|
|
51
|
+}
|
47
|
52
|
|
48
|
|
- // FIXME At the time of this writing, we hope that the callstats.io API will
|
49
|
|
- // have loaded by the time we needed it (i.e. CallStats.init is invoked).
|
|
53
|
+/**
|
|
54
|
+ * Initializes Callstats backend.
|
|
55
|
+ *
|
|
56
|
+ * @param {StatisticsOptions} options - The options to use for initializing
|
|
57
|
+ * callstats backend.
|
|
58
|
+ * @private
|
|
59
|
+ */
|
|
60
|
+function _initCallStatsBackend(options) {
|
|
61
|
+ if (CallStats.isBackendInitialized()) {
|
|
62
|
+ return;
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+ const userName = Settings.callStatsUserName;
|
|
66
|
+
|
|
67
|
+ if (!CallStats.initBackend({
|
|
68
|
+ callStatsID: options.callStatsID,
|
|
69
|
+ callStatsSecret: options.callStatsSecret,
|
|
70
|
+ userName: options.swapUserNameAndAlias
|
|
71
|
+ ? options.callStatsAliasName : userName,
|
|
72
|
+ aliasName: options.swapUserNameAndAlias
|
|
73
|
+ ? userName : options.callStatsAliasName,
|
|
74
|
+ applicationName: options.applicationName
|
|
75
|
+ })) {
|
|
76
|
+ logger.error('CallStats Backend initialization failed bad');
|
|
77
|
+ }
|
50
|
78
|
}
|
51
|
79
|
|
52
|
80
|
/**
|
|
@@ -92,10 +120,28 @@ Statistics.init = function(options) {
|
92
|
120
|
Statistics.disableThirdPartyRequests = options.disableThirdPartyRequests;
|
93
|
121
|
};
|
94
|
122
|
|
|
123
|
+/**
|
|
124
|
+ * The options to configure Statistics.
|
|
125
|
+ * @typedef {Object} StatisticsOptions
|
|
126
|
+ * @property {string} applicationName - The application name to pass to
|
|
127
|
+ * callstats.
|
|
128
|
+ * @property {string} callStatsAliasName - The alias name to use when
|
|
129
|
+ * initializing callstats.
|
|
130
|
+ * @property {string} callStatsConfIDNamespace - A namespace to prepend the
|
|
131
|
+ * callstats conference ID with.
|
|
132
|
+ * @property {string} callStatsID - Callstats credentials - the id.
|
|
133
|
+ * @property {string} callStatsSecret - Callstats credentials - the secret.
|
|
134
|
+ * @property {string} customScriptUrl - A custom lib url to use when downloading
|
|
135
|
+ * callstats library.
|
|
136
|
+ * @property {string} roomName - The room name we are currently in.
|
|
137
|
+ * @property {boolean} swapUserNameAndAlias - Whether to swap the places of
|
|
138
|
+ * username and alias when initiating callstats.
|
|
139
|
+ */
|
95
|
140
|
/**
|
96
|
141
|
*
|
97
|
142
|
* @param xmpp
|
98
|
|
- * @param options
|
|
143
|
+ * @param {StatisticsOptions} options - The options to use creating the
|
|
144
|
+ * Statistics.
|
99
|
145
|
*/
|
100
|
146
|
export default function Statistics(xmpp, options) {
|
101
|
147
|
/**
|
|
@@ -116,8 +162,10 @@ export default function Statistics(xmpp, options) {
|
116
|
162
|
// requests to any third parties.
|
117
|
163
|
&& (Statistics.disableThirdPartyRequests !== true);
|
118
|
164
|
if (this.callStatsIntegrationEnabled) {
|
119
|
|
- if (!RTCBrowserType.isReactNative()) {
|
120
|
|
- loadCallStatsAPI(this.options.callStatsCustomScriptUrl);
|
|
165
|
+ if (RTCBrowserType.isReactNative()) {
|
|
166
|
+ _initCallStatsBackend(this.options);
|
|
167
|
+ } else {
|
|
168
|
+ loadCallStatsAPI(this.options);
|
121
|
169
|
}
|
122
|
170
|
|
123
|
171
|
if (!this.options.callStatsConfIDNamespace) {
|
|
@@ -312,24 +360,6 @@ Statistics.prototype.startCallStats = function(tpc, remoteUserID) {
|
312
|
360
|
return;
|
313
|
361
|
}
|
314
|
362
|
|
315
|
|
- if (!CallStats.isBackendInitialized()) {
|
316
|
|
- const userName = Settings.callStatsUserName;
|
317
|
|
-
|
318
|
|
- if (!CallStats.initBackend({
|
319
|
|
- callStatsID: this.options.callStatsID,
|
320
|
|
- callStatsSecret: this.options.callStatsSecret,
|
321
|
|
- userName: this.options.swapUserNameAndAlias
|
322
|
|
- ? this.options.callStatsAliasName : userName,
|
323
|
|
- aliasName: this.options.swapUserNameAndAlias
|
324
|
|
- ? userName : this.options.callStatsAliasName,
|
325
|
|
- applicationName: this.options.applicationName
|
326
|
|
- })) {
|
327
|
|
-
|
328
|
|
- // Backend initialization failed bad
|
329
|
|
- return;
|
330
|
|
- }
|
331
|
|
- }
|
332
|
|
-
|
333
|
363
|
logger.info(`Starting CallStats for ${tpc}...`);
|
334
|
364
|
|
335
|
365
|
const newInstance
|