2016-11-11 15:00:54 +00:00
|
|
|
const logger = require("jitsi-meet-logger").getLogger(__filename);
|
|
|
|
|
2016-01-22 15:08:58 +00:00
|
|
|
/**
|
|
|
|
* Create deferred object.
|
|
|
|
* @returns {{promise, resolve, reject}}
|
|
|
|
*/
|
|
|
|
export function createDeferred () {
|
|
|
|
let deferred = {};
|
|
|
|
|
|
|
|
deferred.promise = new Promise(function (resolve, reject) {
|
|
|
|
deferred.resolve = resolve;
|
|
|
|
deferred.reject = reject;
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred;
|
|
|
|
}
|
2016-02-05 15:04:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reload page.
|
|
|
|
*/
|
|
|
|
export function reload () {
|
|
|
|
window.location.reload();
|
|
|
|
}
|
2016-07-25 22:04:39 +00:00
|
|
|
|
2016-10-13 17:42:59 +00:00
|
|
|
/**
|
|
|
|
* Redirects to new URL.
|
|
|
|
* @param {string} url the URL pointing to the location where the user should
|
|
|
|
* be redirected to.
|
|
|
|
*/
|
|
|
|
export function redirect (url) {
|
|
|
|
window.location.replace(url);
|
|
|
|
}
|
|
|
|
|
2016-07-25 22:04:39 +00:00
|
|
|
/**
|
|
|
|
* 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 = "") {
|
2016-11-11 15:00:54 +00:00
|
|
|
logger.error(msg, e);
|
2016-07-25 22:04:39 +00:00
|
|
|
if(window.onerror)
|
|
|
|
window.onerror(msg, null, null,
|
|
|
|
null, e);
|
|
|
|
}
|
2016-10-25 11:55:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a debounced function that delays invoking func until after wait
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (...args) => {
|
|
|
|
if(!isCalled) {
|
|
|
|
if (leading) {
|
|
|
|
fn(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
isCalled = false;
|
|
|
|
if (trailing) {
|
|
|
|
fn(...args);
|
|
|
|
}
|
|
|
|
}, wait);
|
|
|
|
|
|
|
|
isCalled = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|