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

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