您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

actions.js 7.0KB

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