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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import { setRoom } from '../base/conference';
  2. import { getDomain, setDomain } from '../base/connection';
  3. import { loadConfig, setConfig } from '../base/lib-jitsi-meet';
  4. import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
  5. import {
  6. _getRouteToRender,
  7. _parseURIString,
  8. init
  9. } from './functions';
  10. import './reducer';
  11. /**
  12. * Temporary solution. Should dispatch actions related to initial settings of
  13. * the app like setting log levels, reading the config parameters from query
  14. * string etc.
  15. *
  16. * @returns {Function}
  17. */
  18. export function appInit() {
  19. return () => init();
  20. }
  21. /**
  22. * Triggers an in-app navigation to a different route. Allows navigation to be
  23. * abstracted between the mobile and web versions.
  24. *
  25. * @param {(string|undefined)} urlOrRoom - The URL or room name to which to
  26. * navigate.
  27. * @returns {Function}
  28. */
  29. export function appNavigate(urlOrRoom) {
  30. return (dispatch, getState) => {
  31. const state = getState();
  32. const oldDomain = getDomain(state);
  33. const { domain, room } = _parseURIString(urlOrRoom);
  34. // TODO Kostiantyn Tsaregradskyi: We should probably detect if user is
  35. // currently in a conference and ask her if she wants to close the
  36. // current conference and start a new one with the new room name or
  37. // domain.
  38. if (typeof domain === 'undefined' || oldDomain === domain) {
  39. dispatchSetRoomAndNavigate();
  40. } else if (oldDomain !== domain) {
  41. // Update domain without waiting for config to be loaded to prevent
  42. // race conditions when we will start to load config multiple times.
  43. dispatch(setDomain(domain));
  44. // If domain has changed, we need to load the config of the new
  45. // domain and set it, and only after that we can navigate to
  46. // different route.
  47. loadConfig(`https://${domain}`)
  48. .then(
  49. config => configLoaded(/* err */ undefined, config),
  50. err => configLoaded(err, /* config */ undefined))
  51. .then(dispatchSetRoomAndNavigate);
  52. }
  53. /**
  54. * Notifies that an attempt to load the config(uration) of domain has
  55. * completed.
  56. *
  57. * @param {string|undefined} err - If the loading has failed, the error
  58. * detailing the cause of the failure.
  59. * @param {Object|undefined} config - If the loading has succeeded, the
  60. * loaded config(uration).
  61. * @returns {void}
  62. */
  63. function configLoaded(err, config) {
  64. if (err) {
  65. // XXX The failure could be, for example, because of a
  66. // certificate-related error. In which case the connection will
  67. // fail later in Strophe anyway even if we use the default
  68. // config here.
  69. // The function loadConfig will log the err.
  70. return;
  71. }
  72. dispatch(setConfig(config));
  73. }
  74. /**
  75. * Dispatches _setRoomAndNavigate in the Redux store.
  76. *
  77. * @returns {void}
  78. */
  79. function dispatchSetRoomAndNavigate() {
  80. // If both domain and room vars became undefined, that means we're
  81. // actually dealing with just room name and not with URL.
  82. dispatch(
  83. _setRoomAndNavigate(
  84. typeof room === 'undefined' && typeof domain === 'undefined'
  85. ? urlOrRoom
  86. : room));
  87. }
  88. };
  89. }
  90. /**
  91. * Signals that a specific App will mount (in the terms of React).
  92. *
  93. * @param {App} app - The App which will mount.
  94. * @returns {{
  95. * type: APP_WILL_MOUNT,
  96. * app: App
  97. * }}
  98. */
  99. export function appWillMount(app) {
  100. return {
  101. type: APP_WILL_MOUNT,
  102. app
  103. };
  104. }
  105. /**
  106. * Signals that a specific App will unmount (in the terms of React).
  107. *
  108. * @param {App} app - The App which will unmount.
  109. * @returns {{
  110. * type: APP_WILL_UNMOUNT,
  111. * app: App
  112. * }}
  113. */
  114. export function appWillUnmount(app) {
  115. return {
  116. type: APP_WILL_UNMOUNT,
  117. app
  118. };
  119. }
  120. /**
  121. * Navigates to a route in accord with a specific Redux state.
  122. *
  123. * @param {Object} state - The Redux state which determines/identifies the route
  124. * to navigate to.
  125. * @private
  126. * @returns {void}
  127. */
  128. function _navigate(state) {
  129. const app = state['features/app'].app;
  130. const routeToRender = _getRouteToRender(state);
  131. app._navigate(routeToRender);
  132. }
  133. /**
  134. * Sets room and navigates to new route if needed.
  135. *
  136. * @param {string} newRoom - New room name.
  137. * @private
  138. * @returns {Function}
  139. */
  140. function _setRoomAndNavigate(newRoom) {
  141. return (dispatch, getState) => {
  142. dispatch(setRoom(newRoom));
  143. _navigate(getState());
  144. };
  145. }