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

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