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 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import JitsiMeetJS from './';
  2. import {
  3. LIB_DISPOSED,
  4. LIB_INIT_ERROR,
  5. LIB_INITIALIZED,
  6. SET_CONFIG
  7. } from './actionTypes';
  8. import './middleware';
  9. import './reducer';
  10. /**
  11. * Disposes lib-jitsi-meet.
  12. *
  13. * @returns {Function}
  14. */
  15. export function disposeLib() {
  16. // XXX We're wrapping it with Promise, because:
  17. // a) to be better aligned with initLib() method, which is async.
  18. // b) as currently there is no implementation for it in lib-jitsi-meet, and
  19. // there is a big chance it will be async.
  20. // TODO Currently, lib-jitsi-meet doesn't have any functionality to
  21. // dispose itself.
  22. return dispatch => {
  23. dispatch({ type: LIB_DISPOSED });
  24. return Promise.resolve();
  25. };
  26. }
  27. /**
  28. * Initializes lib-jitsi-meet with passed configuration.
  29. *
  30. * @returns {Function}
  31. */
  32. export function initLib() {
  33. return (dispatch, getState) => {
  34. const config = getState()['features/base/lib'].config;
  35. if (!config) {
  36. throw new Error('Cannot initialize lib-jitsi-meet without config');
  37. }
  38. return JitsiMeetJS.init(config)
  39. .then(() => dispatch({ type: LIB_INITIALIZED }))
  40. .catch(error => {
  41. dispatch({
  42. type: LIB_INIT_ERROR,
  43. lib: { error }
  44. });
  45. // TODO Handle LIB_INIT_ERROR error somewhere instead.
  46. console.error('lib-jitsi-meet failed to init due to ', error);
  47. throw error;
  48. });
  49. };
  50. }
  51. /**
  52. * Sets config.
  53. *
  54. * @param {Object} config - Config object accepted by JitsiMeetJS#init()
  55. * method.
  56. * @returns {{
  57. * type: SET_CONFIG,
  58. * config: Object
  59. * }}
  60. */
  61. export function setConfig(config) {
  62. return {
  63. type: SET_CONFIG,
  64. config
  65. };
  66. }