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.

actions.js 2.3KB

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