您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

helpers.js 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * Returns the namespace for all global variables, functions, etc that we need.
  3. *
  4. * @returns {Object} The namespace.
  5. *
  6. * NOTE: After React-ifying everything this should be the only global.
  7. */
  8. export function getJitsiMeetGlobalNS() {
  9. if (!window.JitsiMeetJS) {
  10. window.JitsiMeetJS = {};
  11. }
  12. if (!window.JitsiMeetJS.app) {
  13. window.JitsiMeetJS.app = {};
  14. }
  15. return window.JitsiMeetJS.app;
  16. }
  17. /**
  18. * Makes the given promise fail with a timeout error if it wasn't fulfilled in
  19. * the given timeout.
  20. *
  21. * @param {Promise} promise - The promise which will be wrapped for timeout.
  22. * @param {number} ms - The amount of milliseconds to wait for a response before
  23. * failing with a timeout error.
  24. * @returns {Promise} - The wrapped promise.
  25. */
  26. export function timeoutPromise(promise, ms) {
  27. return new Promise((resolve, reject) => {
  28. const timeoutId = setTimeout(() => {
  29. reject(new Error('timeout'));
  30. }, ms);
  31. promise.then(
  32. res => {
  33. clearTimeout(timeoutId);
  34. resolve(res);
  35. },
  36. err => {
  37. clearTimeout(timeoutId);
  38. reject(err);
  39. }
  40. );
  41. });
  42. }