Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

actions.js 7.1KB

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