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

helpers.js 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // @flow
  2. /**
  3. * Returns the namespace for all global variables, functions, etc that we need.
  4. *
  5. * @returns {Object} The namespace.
  6. *
  7. * NOTE: After React-ifying everything this should be the only global.
  8. */
  9. export function getJitsiMeetGlobalNS() {
  10. if (!window.JitsiMeetJS) {
  11. window.JitsiMeetJS = {};
  12. }
  13. if (!window.JitsiMeetJS.app) {
  14. window.JitsiMeetJS.app = {};
  15. }
  16. return window.JitsiMeetJS.app;
  17. }
  18. /**
  19. * Gets the description of a specific {@code Symbol}.
  20. *
  21. * @param {Symbol} symbol - The {@code Symbol} to retrieve the description of.
  22. * @private
  23. * @returns {string} The description of {@code symbol}.
  24. */
  25. export function getSymbolDescription(symbol: ?Symbol) {
  26. let description = symbol ? symbol.toString() : 'undefined';
  27. if (description.startsWith('Symbol(') && description.endsWith(')')) {
  28. description = description.slice(7, -1);
  29. }
  30. // The polyfill es6-symbol that we use does not appear to comply with the
  31. // Symbol standard and, merely, adds @@ at the beginning of the description.
  32. if (description.startsWith('@@')) {
  33. description = description.slice(2);
  34. }
  35. return description;
  36. }
  37. /**
  38. * A helper function that behaves similar to Object.assign, but only reassigns a
  39. * property in target if it's defined in source.
  40. *
  41. * @param {Object} target - The target object to assign the values into.
  42. * @param {Object} source - The source object.
  43. * @returns {Object}
  44. */
  45. export function assignIfDefined(target: Object, source: Object) {
  46. const to = Object(target);
  47. for (const nextKey in source) {
  48. if (source.hasOwnProperty(nextKey)) {
  49. const value = source[nextKey];
  50. if (typeof value !== 'undefined') {
  51. to[nextKey] = value;
  52. }
  53. }
  54. }
  55. return to;
  56. }