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.any.ts 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import { IStore } from '../app/types';
  2. import { checkIfCanJoin } from '../base/conference/actions';
  3. import { IJitsiConference } from '../base/conference/reducer';
  4. import { hideDialog, openDialog } from '../base/dialog/actions';
  5. import {
  6. SET_TOKEN_AUTH_URL_SUCCESS,
  7. STOP_WAIT_FOR_OWNER,
  8. UPGRADE_ROLE_FINISHED,
  9. UPGRADE_ROLE_STARTED, WAIT_FOR_OWNER
  10. } from './actionTypes';
  11. import { LoginDialog, WaitForOwnerDialog } from './components';
  12. import logger from './logger';
  13. /**
  14. * Initiates authenticating and upgrading the role of the local participant to
  15. * moderator which will allow to create and join a new conference on an XMPP
  16. * password + guest access configuration. Refer to {@link LoginDialog} for more
  17. * info.
  18. *
  19. * @param {string} id - The XMPP user's ID (e.g. {@code user@domain.com}).
  20. * @param {string} password - The XMPP user's password.
  21. * @param {JitsiConference} conference - The conference for which the local
  22. * participant's role will be upgraded.
  23. * @returns {Function}
  24. */
  25. export function authenticateAndUpgradeRole(
  26. id: string,
  27. password: string,
  28. conference: IJitsiConference) {
  29. return (dispatch: IStore['dispatch']) => {
  30. const process
  31. = conference.authenticateAndUpgradeRole({
  32. id,
  33. password,
  34. onLoginSuccessful() {
  35. // When the login succeeds, the process has completed half
  36. // of its job (i.e. 0.5).
  37. return dispatch(_upgradeRoleFinished(process, 0.5));
  38. }
  39. });
  40. dispatch(_upgradeRoleStarted(process));
  41. process.then(
  42. /* onFulfilled */ () => dispatch(_upgradeRoleFinished(process, 1)),
  43. /* onRejected */ (error: any) => {
  44. // The lack of an error signals a cancellation.
  45. if (error.authenticationError || error.connectionError) {
  46. logger.error('authenticateAndUpgradeRole failed', error);
  47. }
  48. dispatch(_upgradeRoleFinished(process, error));
  49. });
  50. return process;
  51. };
  52. }
  53. /**
  54. * Signals that the process of authenticating and upgrading the local
  55. * participant's role has finished either with success or with a specific error.
  56. *
  57. * @param {Object} thenableWithCancel - The process of authenticating and
  58. * upgrading the local participant's role.
  59. * @param {Object} progressOrError - If the value is a {@code number}, then the
  60. * process of authenticating and upgrading the local participant's role has
  61. * succeeded in one of its two/multiple steps; otherwise, it has failed with the
  62. * specified error. Refer to {@link JitsiConference#authenticateAndUpgradeRole}
  63. * in lib-jitsi-meet for the error details.
  64. * @private
  65. * @returns {{
  66. * type: UPGRADE_ROLE_FINISHED,
  67. * error: ?Object,
  68. * progress: number
  69. * }}
  70. */
  71. function _upgradeRoleFinished(
  72. thenableWithCancel: Object,
  73. progressOrError: number | any) {
  74. let error;
  75. let progress;
  76. if (typeof progressOrError === 'number') {
  77. progress = progressOrError;
  78. } else {
  79. // Make the specified error object resemble an Error instance (to the
  80. // extent that jitsi-meet needs it).
  81. const {
  82. authenticationError,
  83. connectionError,
  84. ...other
  85. } = progressOrError;
  86. error = {
  87. name: authenticationError || connectionError,
  88. ...other
  89. };
  90. progress = 0;
  91. }
  92. return {
  93. type: UPGRADE_ROLE_FINISHED,
  94. error,
  95. progress,
  96. thenableWithCancel
  97. };
  98. }
  99. /**
  100. * Signals that a process of authenticating and upgrading the local
  101. * participant's role has started.
  102. *
  103. * @param {Object} thenableWithCancel - The process of authenticating and
  104. * upgrading the local participant's role.
  105. * @private
  106. * @returns {{
  107. * type: UPGRADE_ROLE_STARTED,
  108. * thenableWithCancel: Object
  109. * }}
  110. */
  111. function _upgradeRoleStarted(thenableWithCancel: Object) {
  112. return {
  113. type: UPGRADE_ROLE_STARTED,
  114. thenableWithCancel
  115. };
  116. }
  117. /**
  118. * Hides an authentication dialog where the local participant
  119. * should authenticate.
  120. *
  121. * @returns {Function}.
  122. */
  123. export function hideLoginDialog() {
  124. return hideDialog(LoginDialog);
  125. }
  126. /**
  127. * Opens {@link WaitForOnwerDialog}.
  128. *
  129. * @protected
  130. * @returns {Action}
  131. */
  132. export function openWaitForOwnerDialog() {
  133. return openDialog(WaitForOwnerDialog);
  134. }
  135. /**
  136. * Stops waiting for the conference owner.
  137. *
  138. * @returns {{
  139. * type: STOP_WAIT_FOR_OWNER
  140. * }}
  141. */
  142. export function stopWaitForOwner() {
  143. return {
  144. type: STOP_WAIT_FOR_OWNER
  145. };
  146. }
  147. /**
  148. * Called when Jicofo rejects to create the room for anonymous user. Will
  149. * start the process of "waiting for the owner" by periodically trying to join
  150. * the room every five seconds.
  151. *
  152. * @returns {Function}
  153. */
  154. export function waitForOwner() {
  155. return (dispatch: IStore['dispatch']) =>
  156. dispatch({
  157. type: WAIT_FOR_OWNER,
  158. handler: () => dispatch(checkIfCanJoin()),
  159. timeoutMs: 5000
  160. });
  161. }
  162. /**
  163. * Opens {@link LoginDialog} which will ask to enter username and password
  164. * for the current conference.
  165. *
  166. * @protected
  167. * @returns {Action}
  168. */
  169. export function openLoginDialog() {
  170. return openDialog(LoginDialog);
  171. }
  172. /**
  173. * Updates the config with new options.
  174. *
  175. * @param {boolean} value - The new value.
  176. * @returns {Function}
  177. */
  178. export function setTokenAuthUrlSuccess(value: boolean) {
  179. return {
  180. type: SET_TOKEN_AUTH_URL_SUCCESS,
  181. value
  182. };
  183. }