|
@@ -2,12 +2,13 @@ const logger = require("jitsi-meet-logger").getLogger(__filename);
|
2
|
2
|
|
3
|
3
|
/**
|
4
|
4
|
* Create deferred object.
|
|
5
|
+ *
|
5
|
6
|
* @returns {{promise, resolve, reject}}
|
6
|
7
|
*/
|
7
|
|
-export function createDeferred () {
|
8
|
|
- let deferred = {};
|
|
8
|
+export function createDeferred() {
|
|
9
|
+ const deferred = {};
|
9
|
10
|
|
10
|
|
- deferred.promise = new Promise(function (resolve, reject) {
|
|
11
|
+ deferred.promise = new Promise((resolve, reject) => {
|
11
|
12
|
deferred.resolve = resolve;
|
12
|
13
|
deferred.reject = reject;
|
13
|
14
|
});
|
|
@@ -18,7 +19,7 @@ export function createDeferred () {
|
18
|
19
|
/**
|
19
|
20
|
* Reload page.
|
20
|
21
|
*/
|
21
|
|
-export function reload () {
|
|
22
|
+export function reload() {
|
22
|
23
|
window.location.reload();
|
23
|
24
|
}
|
24
|
25
|
|
|
@@ -35,48 +36,41 @@ export function replace(url) {
|
35
|
36
|
|
36
|
37
|
/**
|
37
|
38
|
* Prints the error and reports it to the global error handler.
|
|
39
|
+ *
|
38
|
40
|
* @param e {Error} the error
|
39
|
41
|
* @param msg {string} [optional] the message printed in addition to the error
|
40
|
42
|
*/
|
41
|
|
-export function reportError (e, msg = "") {
|
|
43
|
+export function reportError(e, msg = "") {
|
42
|
44
|
logger.error(msg, e);
|
43
|
|
- if(window.onerror)
|
44
|
|
- window.onerror(msg, null, null,
|
45
|
|
- null, e);
|
|
45
|
+ window.onerror && window.onerror(msg, null, null, null, e);
|
46
|
46
|
}
|
47
|
47
|
|
48
|
48
|
/**
|
49
|
49
|
* Creates a debounced function that delays invoking func until after wait
|
50
|
|
- * milliseconds have elapsed since the last time the debounced
|
51
|
|
- * function was invoked
|
|
50
|
+ * milliseconds have elapsed since the last time the debounced function was
|
|
51
|
+ * invoked.
|
|
52
|
+ *
|
52
|
53
|
* @param fn
|
53
|
54
|
* @param wait
|
54
|
55
|
* @param options
|
55
|
56
|
* @returns {function(...[*])}
|
56
|
57
|
*/
|
57
|
58
|
export function debounce(fn, wait = 0, options = {}) {
|
58
|
|
- let leading = options.leading || false;
|
59
|
|
- let trailing = true;
|
60
|
|
- let isCalled = false;
|
61
|
|
-
|
62
|
|
- if (typeof options.trailing !== 'undefined') {
|
63
|
|
- trailing = options.trailing;
|
64
|
|
- }
|
|
59
|
+ const leading = options.leading || false;
|
|
60
|
+ const trailing
|
|
61
|
+ = (typeof options.trailing === 'undefined') || options.trailing;
|
|
62
|
+ let called = false;
|
65
|
63
|
|
66
|
64
|
return (...args) => {
|
67
|
|
- if(!isCalled) {
|
68
|
|
- if (leading) {
|
69
|
|
- fn(...args);
|
70
|
|
- }
|
|
65
|
+ if (!called) {
|
|
66
|
+ leading && fn(...args);
|
71
|
67
|
|
72
|
68
|
setTimeout(() => {
|
73
|
|
- isCalled = false;
|
74
|
|
- if (trailing) {
|
75
|
|
- fn(...args);
|
76
|
|
- }
|
|
69
|
+ called = false;
|
|
70
|
+ trailing && fn(...args);
|
77
|
71
|
}, wait);
|
78
|
72
|
|
79
|
|
- isCalled = true;
|
|
73
|
+ called = true;
|
80
|
74
|
}
|
81
|
75
|
};
|
82
|
76
|
}
|