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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* @flow */
  2. import type { Dispatch } from 'redux';
  3. import JitsiMeetJS from './_';
  4. import {
  5. LIB_DID_DISPOSE,
  6. LIB_DID_INIT,
  7. LIB_INIT_ERROR,
  8. LIB_INIT_PROMISE_CREATED,
  9. LIB_WILL_DISPOSE,
  10. LIB_WILL_INIT,
  11. SET_WEBRTC_READY
  12. } from './actionTypes';
  13. import { isAnalyticsEnabled } from './functions';
  14. declare var APP: Object;
  15. /**
  16. * Disposes (of) lib-jitsi-meet.
  17. *
  18. * @returns {Function}
  19. */
  20. export function disposeLib() {
  21. return (dispatch: Dispatch<*>) => {
  22. dispatch({ type: LIB_WILL_DISPOSE });
  23. // TODO Currently, lib-jitsi-meet doesn't have the functionality to
  24. // dispose itself.
  25. dispatch({ type: LIB_DID_DISPOSE });
  26. };
  27. }
  28. /**
  29. * Initializes lib-jitsi-meet (i.e. {@link invokes JitsiMeetJS.init()}) with the
  30. * current config(uration).
  31. *
  32. * @returns {Function}
  33. */
  34. export function initLib() {
  35. return (dispatch: Dispatch<*>, getState: Function): Promise<void> => {
  36. const config = getState()['features/base/config'];
  37. if (!config) {
  38. throw new Error('Cannot init lib-jitsi-meet without config');
  39. }
  40. dispatch({ type: LIB_WILL_INIT });
  41. const initPromise = JitsiMeetJS.init({
  42. enableAnalyticsLogging: isAnalyticsEnabled(getState),
  43. ...config
  44. });
  45. dispatch({
  46. type: LIB_INIT_PROMISE_CREATED,
  47. initPromise
  48. });
  49. return (
  50. initPromise
  51. .then(() => dispatch({ type: LIB_DID_INIT }))
  52. .catch(error => {
  53. // TODO: See the comment in the connect action in
  54. // base/connection/actions.web.js.
  55. if (typeof APP === 'undefined') {
  56. dispatch(libInitError(error));
  57. }
  58. // TODO Handle LIB_INIT_ERROR error somewhere instead.
  59. console.error('lib-jitsi-meet failed to init:', error);
  60. throw error;
  61. }));
  62. };
  63. }
  64. /**
  65. * Notifies about a specific error raised by {@link JitsiMeetJS.init()}.
  66. *
  67. * @param {Error} error - The Error raised by JitsiMeetJS.init().
  68. * @returns {{
  69. * type: LIB_INIT_ERROR,
  70. * error: Error
  71. * }}
  72. */
  73. export function libInitError(error: Error) {
  74. return {
  75. type: LIB_INIT_ERROR,
  76. error
  77. };
  78. }
  79. /**
  80. * Sets the indicator which determines whether WebRTC is ready.
  81. *
  82. * @param {boolean} webRTCReady - The indicator which determines
  83. * whether WebRTC is ready.
  84. * @returns {Function}
  85. */
  86. export function setWebRTCReady(webRTCReady: boolean) {
  87. return (dispatch: Function, getState: Function) => {
  88. if (getState()['features/base/lib-jitsi-meet'].webRTCReady
  89. !== webRTCReady) {
  90. dispatch({
  91. type: SET_WEBRTC_READY,
  92. webRTCReady
  93. });
  94. }
  95. };
  96. }