You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

helpers.js 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. const logger = require("jitsi-meet-logger").getLogger(__filename);
  2. /**
  3. * Create deferred object.
  4. *
  5. * @returns {{promise, resolve, reject}}
  6. */
  7. export function createDeferred() {
  8. const deferred = {};
  9. deferred.promise = new Promise((resolve, reject) => {
  10. deferred.resolve = resolve;
  11. deferred.reject = reject;
  12. });
  13. return deferred;
  14. }
  15. /**
  16. * Returns the namespace for all global variables, functions, etc that we need.
  17. *
  18. * @returns {Object} the namespace.
  19. *
  20. * NOTE: After React-ifying everything this should be the only global.
  21. */
  22. export function getJitsiMeetGlobalNS() {
  23. if (!window.JitsiMeetJS) {
  24. window.JitsiMeetJS = {};
  25. }
  26. if (!window.JitsiMeetJS.app) {
  27. window.JitsiMeetJS.app = {};
  28. }
  29. return window.JitsiMeetJS.app;
  30. }
  31. /**
  32. * Reload page.
  33. */
  34. export function reload() {
  35. window.location.reload();
  36. }
  37. /**
  38. * Redirects to a specific new URL by replacing the current location (in the
  39. * history).
  40. *
  41. * @param {string} url the URL pointing to the location where the user should
  42. * be redirected to.
  43. */
  44. export function replace(url) {
  45. window.location.replace(url);
  46. }
  47. /**
  48. * Prints the error and reports it to the global error handler.
  49. *
  50. * @param e {Error} the error
  51. * @param msg {string} [optional] the message printed in addition to the error
  52. */
  53. export function reportError(e, msg = "") {
  54. logger.error(msg, e);
  55. window.onerror && window.onerror(msg, null, null, null, e);
  56. }