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

actions.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import type { Dispatch } from 'redux';
  2. import JitsiMeetJS from './_';
  3. import {
  4. LIB_DID_DISPOSE,
  5. LIB_DID_INIT,
  6. LIB_INIT_ERROR,
  7. LIB_WILL_DISPOSE,
  8. LIB_WILL_INIT,
  9. SET_CONFIG
  10. } from './actionTypes';
  11. declare var APP: Object;
  12. /**
  13. * Disposes (of) lib-jitsi-meet.
  14. *
  15. * @returns {Function}
  16. */
  17. export function disposeLib() {
  18. return (dispatch: Dispatch<*>) => {
  19. dispatch({ type: LIB_WILL_DISPOSE });
  20. // XXX We're wrapping it with Promise because:
  21. // a) to be better aligned with initLib() method which is async;
  22. // b) as currently there is no implementation for it in lib-jitsi-meet
  23. // and there is a big chance it will be async.
  24. // TODO Currently, lib-jitsi-meet doesn't have the functionality to
  25. // dispose itself.
  26. return (
  27. Promise.resolve()
  28. .then(() => dispatch({ type: LIB_DID_DISPOSE })));
  29. };
  30. }
  31. /**
  32. * Initializes lib-jitsi-meet (i.e. {@link invokes JitsiMeetJS.init()}) with the
  33. * current config(uration).
  34. *
  35. * @returns {Function}
  36. */
  37. export function initLib() {
  38. return (dispatch: Dispatch<*>, getState: Function) => {
  39. const { config } = getState()['features/base/lib-jitsi-meet'];
  40. if (!config) {
  41. throw new Error('Cannot init lib-jitsi-meet without config');
  42. }
  43. // XXX Temporarily until conference.js is moved to the React app we
  44. // shouldn't use JitsiMeetJS from the React app.
  45. if (typeof APP !== 'undefined') {
  46. return Promise.resolve();
  47. }
  48. dispatch({ type: LIB_WILL_INIT });
  49. return (
  50. JitsiMeetJS.init(config)
  51. .then(() => dispatch({ type: LIB_DID_INIT }))
  52. .catch(error => {
  53. dispatch(libInitError(error));
  54. // TODO Handle LIB_INIT_ERROR error somewhere instead.
  55. console.error('lib-jitsi-meet failed to init:', error);
  56. throw error;
  57. }));
  58. };
  59. }
  60. /**
  61. * Notifies about a specific error raised by {@link JitsiMeetJS.init()}.
  62. *
  63. * @param {Error} error - The Error raised by JitsiMeetJS.init().
  64. * @returns {{
  65. * type: LIB_INIT_ERROR,
  66. * error: Error
  67. * }}
  68. */
  69. export function libInitError(error: Error) {
  70. return {
  71. type: LIB_INIT_ERROR,
  72. error
  73. };
  74. }
  75. /**
  76. * Sets config.
  77. *
  78. * @param {Object} config - The config(uration) object in the format accepted by
  79. * the JitsiMeetJS.init() method.
  80. * @returns {{
  81. * type: SET_CONFIG,
  82. * config: Object
  83. * }}
  84. */
  85. export function setConfig(config: Object) {
  86. return {
  87. type: SET_CONFIG,
  88. config
  89. };
  90. }