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

actions.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import React from 'react';
  2. import JitsiMeetJS from './';
  3. import {
  4. LIB_DISPOSED,
  5. LIB_INIT_ERROR,
  6. LIB_INITIALIZED,
  7. SET_CONFIG
  8. } from './actionTypes';
  9. import './middleware';
  10. import './reducer';
  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 => {
  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, getState) => {
  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. if (!React.View) {
  40. // XXX Temporarily until conference.js is moved to the React app we
  41. // shouldn't use JitsiMeetJS from the React app.
  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. lib: { 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) {
  68. return {
  69. type: SET_CONFIG,
  70. config
  71. };
  72. }