Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import { appNavigate } from '../app';
  4. import { checkIfCanJoin, conferenceLeft } from '../base/conference';
  5. import { connectionFailed } from '../base/connection';
  6. import { openDialog } from '../base/dialog';
  7. import { set } from '../base/redux';
  8. import {
  9. CANCEL_LOGIN,
  10. STOP_WAIT_FOR_OWNER,
  11. UPGRADE_ROLE_FINISHED,
  12. UPGRADE_ROLE_STARTED,
  13. WAIT_FOR_OWNER
  14. } from './actionTypes';
  15. import { LoginDialog, WaitForOwnerDialog } from './components';
  16. import logger from './logger';
  17. /**
  18. * Initiates authenticating and upgrading the role of the local participant to
  19. * moderator which will allow to create and join a new conference on an XMPP
  20. * password + guest access configuration. Refer to {@link LoginDialog} for more
  21. * info.
  22. *
  23. * @param {string} id - The XMPP user's ID (e.g. {@code user@domain.com}).
  24. * @param {string} password - The XMPP user's password.
  25. * @param {JitsiConference} conference - The conference for which the local
  26. * participant's role will be upgraded.
  27. * @returns {Function}
  28. */
  29. export function authenticateAndUpgradeRole(
  30. id: string,
  31. password: string,
  32. conference: Object) {
  33. return (dispatch: Dispatch<any>, getState: Function) => {
  34. const { password: roomPassword }
  35. = getState()['features/base/conference'];
  36. const process
  37. = conference.authenticateAndUpgradeRole({
  38. id,
  39. password,
  40. roomPassword,
  41. onLoginSuccessful() {
  42. // When the login succeeds, the process has completed half
  43. // of its job (i.e. 0.5).
  44. return dispatch(_upgradeRoleFinished(process, 0.5));
  45. }
  46. });
  47. dispatch(_upgradeRoleStarted(process));
  48. process.then(
  49. /* onFulfilled */ () => dispatch(_upgradeRoleFinished(process, 1)),
  50. /* onRejected */ error => {
  51. // The lack of an error signals a cancellation.
  52. if (error.authenticationError || error.connectionError) {
  53. logger.error('authenticateAndUpgradeRole failed', error);
  54. }
  55. dispatch(_upgradeRoleFinished(process, error));
  56. });
  57. return process;
  58. };
  59. }
  60. /**
  61. * Cancels {@ink LoginDialog}.
  62. *
  63. * @returns {{
  64. * type: CANCEL_LOGIN
  65. * }}
  66. */
  67. export function cancelLogin() {
  68. return (dispatch: Dispatch<any>, getState: Function) => {
  69. dispatch({ type: CANCEL_LOGIN });
  70. // XXX The error associated with CONNECTION_FAILED was marked as
  71. // recoverable by the authentication feature and, consequently,
  72. // recoverable-aware features such as mobile's external-api did not
  73. // deliver the CONFERENCE_FAILED to the SDK clients/consumers (as
  74. // a reaction to CONNECTION_FAILED). Since the
  75. // app/user is going to navigate to WelcomePage, the SDK
  76. // clients/consumers need an event.
  77. const { error, passwordRequired }
  78. = getState()['features/base/connection'];
  79. passwordRequired
  80. && dispatch(
  81. connectionFailed(
  82. passwordRequired,
  83. set(error, 'recoverable', false)));
  84. };
  85. }
  86. /**
  87. * Cancels {@link WaitForOwnerDialog}. Will navigate back to the welcome page.
  88. *
  89. * @returns {Function}
  90. */
  91. export function cancelWaitForOwner() {
  92. return (dispatch: Dispatch<any>, getState: Function) => {
  93. dispatch(stopWaitForOwner());
  94. // XXX The error associated with CONFERENCE_FAILED was marked as
  95. // recoverable by the feature room-lock and, consequently,
  96. // recoverable-aware features such as mobile's external-api did not
  97. // deliver the CONFERENCE_FAILED to the SDK clients/consumers. Since the
  98. // app/user is going to nativate to WelcomePage, the SDK
  99. // clients/consumers need an event.
  100. const { authRequired } = getState()['features/base/conference'];
  101. authRequired && dispatch(conferenceLeft(authRequired));
  102. dispatch(appNavigate(undefined));
  103. };
  104. }
  105. /**
  106. * Opens {@link LoginDialog} which will ask to enter username and password
  107. * for the current conference.
  108. *
  109. * @protected
  110. * @returns {Action}
  111. */
  112. export function _openLoginDialog() {
  113. return openDialog(LoginDialog);
  114. }
  115. /**
  116. * Opens {@link WaitForOnwerDialog}.
  117. *
  118. * @protected
  119. * @returns {Action}
  120. */
  121. export function _openWaitForOwnerDialog() {
  122. return openDialog(WaitForOwnerDialog);
  123. }
  124. /**
  125. * Stops waiting for the conference owner.
  126. *
  127. * @returns {{
  128. * type: STOP_WAIT_FOR_OWNER
  129. * }}
  130. */
  131. export function stopWaitForOwner() {
  132. return {
  133. type: STOP_WAIT_FOR_OWNER
  134. };
  135. }
  136. /**
  137. * Signals that the process of authenticating and upgrading the local
  138. * participant's role has finished either with success or with a specific error.
  139. *
  140. * @param {Object} thenableWithCancel - The process of authenticating and
  141. * upgrading the local participant's role.
  142. * @param {Object} progressOrError - If the value is a {@code number}, then the
  143. * process of authenticating and upgrading the local participant's role has
  144. * succeeded in one of its two/multiple steps; otherwise, it has failed with the
  145. * specified error. Refer to {@link JitsiConference#authenticateAndUpgradeRole}
  146. * in lib-jitsi-meet for the error details.
  147. * @private
  148. * @returns {{
  149. * type: UPGRADE_ROLE_FINISHED,
  150. * error: ?Object,
  151. * progress: number
  152. * }}
  153. */
  154. function _upgradeRoleFinished(
  155. thenableWithCancel,
  156. progressOrError: number | Object) {
  157. let error;
  158. let progress;
  159. if (typeof progressOrError === 'number') {
  160. progress = progressOrError;
  161. } else {
  162. // Make the specified error object resemble an Error instance (to the
  163. // extent that jitsi-meet needs it).
  164. const {
  165. authenticationError,
  166. connectionError,
  167. ...other
  168. } = progressOrError;
  169. error = {
  170. name: authenticationError || connectionError,
  171. ...other
  172. };
  173. progress = authenticationError ? 0.5 : 0;
  174. }
  175. return {
  176. type: UPGRADE_ROLE_FINISHED,
  177. error,
  178. progress,
  179. thenableWithCancel
  180. };
  181. }
  182. /**
  183. * Signals that a process of authenticating and upgrading the local
  184. * participant's role has started.
  185. *
  186. * @param {Object} thenableWithCancel - The process of authenticating and
  187. * upgrading the local participant's role.
  188. * @private
  189. * @returns {{
  190. * type: UPGRADE_ROLE_STARTED,
  191. * thenableWithCancel: Object
  192. * }}
  193. */
  194. function _upgradeRoleStarted(thenableWithCancel) {
  195. return {
  196. type: UPGRADE_ROLE_STARTED,
  197. thenableWithCancel
  198. };
  199. }
  200. /**
  201. * Called when Jicofo rejects to create the room for anonymous user. Will
  202. * start the process of "waiting for the owner" by periodically trying to join
  203. * the room every five seconds.
  204. *
  205. * @returns {Function}
  206. */
  207. export function waitForOwner() {
  208. return (dispatch: Dispatch<any>) =>
  209. dispatch({
  210. type: WAIT_FOR_OWNER,
  211. handler: () => dispatch(checkIfCanJoin()),
  212. timeoutMs: 5000
  213. });
  214. }