Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

Simplify the source code

Lyubomir Marinov6c5468d904b8
diff --git a/modules/util/helpers.js b/modules/util/helpers.js
index ef10528c5c..55408151a1 100644
--- a/modules/util/helpers.js
+++ b/modules/util/helpers.js
@@ -2,12 +2,13 @@ const logger = require("jitsi-meet-logger").getLogger(__filename);
/**
* Create deferred object.
+ *
* @returns {{promise, resolve, reject}}
*/
-export function createDeferred () {
- let deferred = {};
+export function createDeferred() {
+ const deferred = {};
- deferred.promise = new Promise(function (resolve, reject) {
+ deferred.promise = new Promise((resolve, reject) => {
deferred.resolve = resolve;
deferred.reject = reject;
});
@@ -18,7 +19,7 @@ export function createDeferred () {
/**
* Reload page.
*/
-export function reload () {
+export function reload() {
window.location.reload();
}
@@ -35,48 +36,41 @@ export function replace(url) {
/**
* Prints the error and reports it to the global error handler.
+ *
* @param e {Error} the error
* @param msg {string} [optional] the message printed in addition to the error
*/
-export function reportError (e, msg = "") {
+export function reportError(e, msg = "") {
logger.error(msg, e);
- if(window.onerror)
- window.onerror(msg, null, null,
- null, e);
+ window.onerror && window.onerror(msg, null, null, null, e);
}
/**
* Creates a debounced function that delays invoking func until after wait
- * milliseconds have elapsed since the last time the debounced
- * function was invoked
+ * milliseconds have elapsed since the last time the debounced function was
+ * invoked.
+ *
* @param fn
* @param wait
* @param options
* @returns {function(...[*])}
*/
export function debounce(fn, wait = 0, options = {}) {
- let leading = options.leading || false;
- let trailing = true;
- let isCalled = false;
-
- if (typeof options.trailing !== 'undefined') {
- trailing = options.trailing;
- }
+ const leading = options.leading || false;
+ const trailing
+ = (typeof options.trailing === 'undefined') || options.trailing;
+ let called = false;
return (...args) => {
- if(!isCalled) {
- if (leading) {
- fn(...args);
- }
+ if (!called) {
+ leading && fn(...args);
setTimeout(() => {
- isCalled = false;
- if (trailing) {
- fn(...args);
- }
+ called = false;
+ trailing && fn(...args);
}, wait);
- isCalled = true;
+ called = true;
}
};
}