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

actions.js 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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'].config;
  36. if (!config) {
  37. throw new Error('Cannot initialize 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({
  48. type: LIB_INIT_ERROR,
  49. error
  50. });
  51. // TODO Handle LIB_INIT_ERROR error somewhere instead.
  52. console.error('lib-jitsi-meet failed to init due to ', error);
  53. throw error;
  54. });
  55. };
  56. }
  57. /**
  58. * Sets config.
  59. *
  60. * @param {Object} config - Config object accepted by JitsiMeetJS#init()
  61. * method.
  62. * @returns {{
  63. * type: SET_CONFIG,
  64. * config: Object
  65. * }}
  66. */
  67. export function setConfig(config: Object) {
  68. return {
  69. type: SET_CONFIG,
  70. config
  71. };
  72. }