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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import {
  4. appNavigate,
  5. maybeRedirectToWelcomePage
  6. } from '../app';
  7. import {
  8. conferenceLeft,
  9. JITSI_CONFERENCE_URL_KEY,
  10. setPassword
  11. } from '../base/conference';
  12. import { hideDialog, openDialog } from '../base/dialog';
  13. import { PasswordRequiredPrompt, RoomLockPrompt } from './components';
  14. declare var APP: Object;
  15. /**
  16. * Begins a (user) request to lock a specific conference/room.
  17. *
  18. * @param {JitsiConference|undefined} conference - The JitsiConference to lock
  19. * if specified or undefined if the current JitsiConference is to be locked.
  20. * @returns {Function}
  21. */
  22. export function beginRoomLockRequest(conference: ?Object) {
  23. return (dispatch: Function, getState: Function) => {
  24. if (typeof conference === 'undefined') {
  25. // eslint-disable-next-line no-param-reassign
  26. conference = getState()['features/base/conference'].conference;
  27. }
  28. if (conference) {
  29. const passwordNumberOfDigits = getState()['features/base/config'].roomPasswordNumberOfDigits;
  30. dispatch(openDialog(RoomLockPrompt, {
  31. conference,
  32. passwordNumberOfDigits }));
  33. }
  34. };
  35. }
  36. /**
  37. * Cancels a prompt for a password to join a specific conference/room.
  38. *
  39. * @param {JitsiConference} conference - The {@code JitsiConference} requesting
  40. * the password to join.
  41. * @protected
  42. * @returns {Function}
  43. */
  44. export function _cancelPasswordRequiredPrompt(conference: Object) {
  45. return (dispatch: Dispatch<any>, getState: Function) => {
  46. if (typeof APP !== 'undefined') {
  47. // when we are redirecting the library should handle any
  48. // unload and clean of the connection.
  49. APP.API.notifyReadyToClose();
  50. dispatch(maybeRedirectToWelcomePage());
  51. return;
  52. }
  53. // Canceling PasswordRequiredPrompt is to navigate the app/user to
  54. // WelcomePage. In other words, the canceling invalidates the
  55. // locationURL. Make sure that the canceling indeed has the intent to
  56. // invalidate the locationURL.
  57. const state = getState();
  58. if (conference === state['features/base/conference'].passwordRequired
  59. && conference[JITSI_CONFERENCE_URL_KEY]
  60. === state['features/base/connection'].locationURL) {
  61. // XXX The error associated with CONFERENCE_FAILED was marked as
  62. // recoverable by the feature room-lock and, consequently,
  63. // recoverable-aware features such as mobile's external-api did not
  64. // deliver the CONFERENCE_FAILED to the SDK clients/consumers. Since
  65. // the app/user is going to nativate to WelcomePage, the SDK
  66. // clients/consumers need an event.
  67. dispatch(conferenceLeft(conference));
  68. dispatch(appNavigate(undefined));
  69. }
  70. };
  71. }
  72. /**
  73. * Ends a (user) request to lock a specific conference/room.
  74. *
  75. * @param {JitsiConference} conference - The JitsiConference to lock.
  76. * @param {string|undefined} password - The password with which the specified
  77. * conference is to be locked or undefined to cancel the (user) request to lock
  78. * the specified conference.
  79. * @returns {Function}
  80. */
  81. export function endRoomLockRequest(
  82. conference: { lock: Function },
  83. password: ?string) {
  84. return (dispatch: Function) => {
  85. const setPassword_
  86. = password
  87. ? dispatch(setPassword(conference, conference.lock, password))
  88. : Promise.resolve();
  89. const endRoomLockRequest_ = () => dispatch(hideDialog(RoomLockPrompt));
  90. setPassword_.then(endRoomLockRequest_, endRoomLockRequest_);
  91. };
  92. }
  93. /**
  94. * Begins a prompt for a password to join a specific conference/room.
  95. *
  96. * @param {JitsiConference} conference - The {@code JitsiConference}
  97. * requesting the password to join.
  98. * @protected
  99. * @returns {{
  100. * type: OPEN_DIALOG,
  101. * component: Component,
  102. * props: PropTypes
  103. * }}
  104. */
  105. export function _openPasswordRequiredPrompt(conference: Object) {
  106. return openDialog(PasswordRequiredPrompt, { conference });
  107. }
  108. /**
  109. * Unlocks the current jitsi conference.
  110. *
  111. * @returns {Function}
  112. */
  113. export function unlockRoom() {
  114. return (dispatch: Dispatch<any>, getState: Function) => {
  115. const { conference } = getState()['features/base/conference'];
  116. return dispatch(setPassword(
  117. conference,
  118. conference.lock,
  119. ''
  120. ));
  121. };
  122. }