Просмотр исходного кода

feat(precallTest):disable if callstats is disabled

dev1
Hristo Terezov 5 лет назад
Родитель
Сommit
4980889b24
1 измененных файлов: 24 добавлений и 20 удалений
  1. 24
    20
      modules/statistics/PrecallTest.js

+ 24
- 20
modules/statistics/PrecallTest.js Просмотреть файл

@@ -47,26 +47,24 @@ function _loadScript() {
47 47
  */
48 48
 function _initialize(options) {
49 49
     return new Promise((resolve, reject) => {
50
-        if (!options.disableThirdPartyRequests) {
51
-            const appId = options.callStatsID;
52
-            const appSecret = options.callStatsSecret;
53
-            const userId = options.statisticsId || options.statisticsDisplayName || Settings.callStatsUserName;
54
-
55
-            api.initialize(appId, appSecret, userId, (status, message) => {
56
-                if (status === 'success') {
57
-                    api.on(PRECALL_TEST_RESULTS, (...args) => {
58
-                        emitter.emit(PRECALL_TEST_RESULTS, ...args);
59
-                    });
60
-                    _initialized = true;
61
-                    resolve();
62
-                } else {
63
-                    reject({
64
-                        status,
65
-                        message
66
-                    });
67
-                }
68
-            }, null, { disablePrecalltest: true });
69
-        }
50
+        const appId = options.callStatsID;
51
+        const appSecret = options.callStatsSecret;
52
+        const userId = options.statisticsId || options.statisticsDisplayName || Settings.callStatsUserName;
53
+
54
+        api.initialize(appId, appSecret, userId, (status, message) => {
55
+            if (status === 'success') {
56
+                api.on(PRECALL_TEST_RESULTS, (...args) => {
57
+                    emitter.emit(PRECALL_TEST_RESULTS, ...args);
58
+                });
59
+                _initialized = true;
60
+                resolve();
61
+            } else {
62
+                reject({
63
+                    status,
64
+                    message
65
+                });
66
+            }
67
+        }, null, { disablePrecalltest: true });
70 68
     });
71 69
 }
72 70
 
@@ -81,6 +79,12 @@ export async function init(options) {
81 79
         throw new Error('Precall Test already initialized');
82 80
     }
83 81
 
82
+    const { callStatsID, callStatsSecret, disableThirdPartyRequests } = options;
83
+
84
+    if (!callStatsID || !callStatsSecret || disableThirdPartyRequests) {
85
+        throw new Error('Callstats is disabled');
86
+    }
87
+
84 88
     await _loadScript();
85 89
     // eslint-disable-next-line new-cap
86 90
     api = new window.callstats();

Загрузка…
Отмена
Сохранить