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

helpers.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // @flow
  2. const logger = require('jitsi-meet-logger').getLogger(__filename);
  3. /**
  4. * Returns the namespace for all global variables, functions, etc that we need.
  5. *
  6. * @returns {Object} The namespace.
  7. *
  8. * NOTE: After React-ifying everything this should be the only global.
  9. */
  10. export function getJitsiMeetGlobalNS() {
  11. if (!window.JitsiMeetJS) {
  12. window.JitsiMeetJS = {};
  13. }
  14. if (!window.JitsiMeetJS.app) {
  15. window.JitsiMeetJS.app = {};
  16. }
  17. return window.JitsiMeetJS.app;
  18. }
  19. /**
  20. * A helper function that behaves similar to Object.assign, but only reassigns a
  21. * property in target if it's defined in source.
  22. *
  23. * @param {Object} target - The target object to assign the values into.
  24. * @param {Object} source - The source object.
  25. * @returns {Object}
  26. */
  27. export function assignIfDefined(target: Object, source: Object) {
  28. const to = Object(target);
  29. for (const nextKey in source) {
  30. if (source.hasOwnProperty(nextKey)) {
  31. const value = source[nextKey];
  32. if (typeof value !== 'undefined') {
  33. to[nextKey] = value;
  34. }
  35. }
  36. }
  37. return to;
  38. }
  39. /**
  40. * Prints the error and reports it to the global error handler.
  41. *
  42. * @param {Error} e - The error object.
  43. * @param {string} msg - A custom message to print in addition to the error.
  44. * @returns {void}
  45. */
  46. export function reportError(e: Object, msg: string = '') {
  47. logger.error(msg, e);
  48. window.onerror && window.onerror(msg, null, null, null, e);
  49. }