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

actions.js 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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_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({ dispatch: Dispatch, getState: 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. });
  39. dispatch(_upgradeRoleStarted(process));
  40. process.then(
  41. /* onFulfilled */ () => dispatch(_upgradeRoleFinished()),
  42. /* onRejected */ error => {
  43. // The lack of an error signals a cancellation.
  44. if (error.authenticationError || error.connectionError) {
  45. logger.error('authenticateAndUpgradeRole failed', error);
  46. }
  47. dispatch(_upgradeRoleFinished(error));
  48. });
  49. return process;
  50. };
  51. }
  52. /**
  53. * Cancels {@ink LoginDialog}.
  54. *
  55. * @returns {{
  56. * type: CANCEL_LOGIN
  57. * }}
  58. */
  59. export function cancelLogin() {
  60. return {
  61. type: CANCEL_LOGIN
  62. };
  63. }
  64. /**
  65. * Cancels {@link WaitForOwnerDialog}. Will navigate back to the welcome page.
  66. *
  67. * @returns {{
  68. * type: CANCEL_WAIT_FOR_OWNER
  69. * }}
  70. */
  71. export function cancelWaitForOwner() {
  72. return {
  73. type: CANCEL_WAIT_FOR_OWNER
  74. };
  75. }
  76. /**
  77. * Opens {@link LoginDialog} which will ask to enter username and password
  78. * for the current conference.
  79. *
  80. * @protected
  81. * @returns {Action}
  82. */
  83. export function _openLoginDialog() {
  84. return openDialog(LoginDialog);
  85. }
  86. /**
  87. * Opens {@link WaitForOnwerDialog}.
  88. *
  89. * @protected
  90. * @returns {Action}
  91. */
  92. export function _openWaitForOwnerDialog() {
  93. return openDialog(WaitForOwnerDialog);
  94. }
  95. /**
  96. * Stops waiting for the conference owner.
  97. *
  98. * @returns {{
  99. * type: STOP_WAIT_FOR_OWNER
  100. * }}
  101. */
  102. export function stopWaitForOwner() {
  103. return {
  104. type: STOP_WAIT_FOR_OWNER
  105. };
  106. }
  107. /**
  108. * Signals that the process of authenticating and upgrading the local
  109. * participant's role has finished either with success or with a specific error.
  110. *
  111. * @param {Object} error - If <tt>undefined</tt>, then the process of
  112. * authenticating and upgrading the local participant's role has succeeded;
  113. * otherwise, it has failed with the specified error. Refer to
  114. * {@link JitsiConference#authenticateAndUpgradeRole} in lib-jitsi-meet for the
  115. * error details.
  116. * @private
  117. * @returns {{
  118. * type: UPGRADE_ROLE_FINISHED,
  119. * error: ?Object
  120. * }}
  121. */
  122. function _upgradeRoleFinished(error: ?Object) {
  123. if (error) {
  124. // Make the specified error object resemble an Error instance (to the
  125. // extent that jitsi-meet needs it).
  126. const {
  127. authenticationError,
  128. connectionError,
  129. ...other
  130. } = error;
  131. error = { // eslint-disable-line no-param-reassign
  132. name: authenticationError || connectionError,
  133. ...other
  134. };
  135. }
  136. return {
  137. type: UPGRADE_ROLE_FINISHED,
  138. error
  139. };
  140. }
  141. /**
  142. * Signals that a process of authenticating and upgrading the local
  143. * participant's role has started.
  144. *
  145. * @param {Object} thenableWithCancel - The process of authenticating and
  146. * upgrading the local participant's role.
  147. * @private
  148. * @returns {{
  149. * type: UPGRADE_ROLE_STARTED,
  150. * thenableWithCancel: Object
  151. * }}
  152. */
  153. function _upgradeRoleStarted(thenableWithCancel) {
  154. return {
  155. type: UPGRADE_ROLE_STARTED,
  156. thenableWithCancel
  157. };
  158. }
  159. /**
  160. * Called when Jicofo rejects to create the room for anonymous user. Will
  161. * start the process of "waiting for the owner" by periodically trying to join
  162. * the room every five seconds.
  163. *
  164. * @returns {function({ dispatch: Dispatch })}
  165. */
  166. export function waitForOwner() {
  167. return (dispatch: Dispatch) =>
  168. dispatch({
  169. type: WAIT_FOR_OWNER,
  170. handler: () => dispatch(checkIfCanJoin()),
  171. timeoutMs: 5000
  172. });
  173. }