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

actions.js 6.2KB

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