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.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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-jitsi-meet'].config;
  35. if (!config) {
  36. throw new Error('Cannot initialize lib-jitsi-meet without config');
  37. }
  38. // XXX Temporarily until conference.js is moved to the React app we
  39. // shouldn't use JitsiMeetJS from the React app.
  40. if (typeof APP !== 'undefined') {
  41. return Promise.resolve();
  42. }
  43. return JitsiMeetJS.init(config)
  44. .then(() => dispatch({ type: LIB_INITIALIZED }))
  45. .catch(error => {
  46. dispatch({
  47. type: LIB_INIT_ERROR,
  48. lib: { error }
  49. });
  50. // TODO Handle LIB_INIT_ERROR error somewhere instead.
  51. console.error('lib-jitsi-meet failed to init due to ', error);
  52. throw error;
  53. });
  54. };
  55. }
  56. /**
  57. * Sets config.
  58. *
  59. * @param {Object} config - Config object accepted by JitsiMeetJS#init()
  60. * method.
  61. * @returns {{
  62. * type: SET_CONFIG,
  63. * config: Object
  64. * }}
  65. */
  66. export function setConfig(config) {
  67. return {
  68. type: SET_CONFIG,
  69. config
  70. };
  71. }