Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. // @flow
  2. import { type Dispatch } from 'redux';
  3. import { appNavigate, maybeRedirectToWelcomePage } from '../app/actions';
  4. import {
  5. conferenceWillJoin,
  6. getCurrentConference,
  7. sendLocalParticipant,
  8. setPassword
  9. } from '../base/conference';
  10. import { hideDialog, openDialog } from '../base/dialog';
  11. import { getLocalParticipant } from '../base/participants';
  12. import {
  13. KNOCKING_PARTICIPANT_ARRIVED_OR_UPDATED,
  14. KNOCKING_PARTICIPANT_LEFT,
  15. SET_KNOCKING_STATE,
  16. SET_LOBBY_MODE_ENABLED,
  17. SET_PASSWORD_JOIN_FAILED
  18. } from './actionTypes';
  19. import { LobbyScreen } from './components';
  20. declare var APP: Object;
  21. /**
  22. * Cancels the ongoing knocking and abandones the join flow.
  23. *
  24. * @returns {Function}
  25. */
  26. export function cancelKnocking() {
  27. return async (dispatch: Dispatch<any>) => {
  28. if (typeof APP !== 'undefined') {
  29. // when we are redirecting the library should handle any
  30. // unload and clean of the connection.
  31. APP.API.notifyReadyToClose();
  32. dispatch(maybeRedirectToWelcomePage());
  33. return;
  34. }
  35. dispatch(appNavigate(undefined));
  36. };
  37. }
  38. /**
  39. * Action to hide the lobby screen.
  40. *
  41. * @returns {hideDialog}
  42. */
  43. export function hideLobbyScreen() {
  44. return hideDialog(LobbyScreen);
  45. }
  46. /**
  47. * Tries to join with a preset password.
  48. *
  49. * @param {string} password - The password to join with.
  50. * @returns {Function}
  51. */
  52. export function joinWithPassword(password: string) {
  53. return async (dispatch: Dispatch<any>, getState: Function) => {
  54. const conference = getCurrentConference(getState);
  55. dispatch(setPassword(conference, conference.join, password));
  56. };
  57. }
  58. /**
  59. * Action to be dispatched when a knocking poarticipant leaves before any response.
  60. *
  61. * @param {string} id - The ID of the participant.
  62. * @returns {{
  63. * id: string,
  64. * type: KNOCKING_PARTICIPANT_LEFT
  65. * }}
  66. */
  67. export function knockingParticipantLeft(id: string) {
  68. return {
  69. id,
  70. type: KNOCKING_PARTICIPANT_LEFT
  71. };
  72. }
  73. /**
  74. * Action to open the lobby screen.
  75. *
  76. * @returns {openDialog}
  77. */
  78. export function openLobbyScreen() {
  79. return openDialog(LobbyScreen, {}, true);
  80. }
  81. /**
  82. * Action to be executed when a participant starts knocking or an already knocking participant gets updated.
  83. *
  84. * @param {Object} participant - The knocking participant.
  85. * @returns {{
  86. * participant: Object,
  87. * type: KNOCKING_PARTICIPANT_ARRIVED_OR_UPDATED
  88. * }}
  89. */
  90. export function participantIsKnockingOrUpdated(participant: Object) {
  91. return {
  92. participant,
  93. type: KNOCKING_PARTICIPANT_ARRIVED_OR_UPDATED
  94. };
  95. }
  96. /**
  97. * Approves (lets in) or rejects a knocking participant.
  98. *
  99. * @param {string} id - The id of the knocking participant.
  100. * @param {boolean} approved - True if the participant is approved, false otherwise.
  101. * @returns {Function}
  102. */
  103. export function setKnockingParticipantApproval(id: string, approved: boolean) {
  104. return async (dispatch: Dispatch<any>, getState: Function) => {
  105. const conference = getCurrentConference(getState);
  106. if (conference) {
  107. if (approved) {
  108. conference.lobbyApproveAccess(id);
  109. } else {
  110. conference.lobbyDenyAccess(id);
  111. }
  112. }
  113. };
  114. }
  115. /**
  116. * Action to set the knocking state of the participant.
  117. *
  118. * @param {boolean} knocking - The new state.
  119. * @returns {{
  120. * state: boolean,
  121. * type: SET_KNOCKING_STATE
  122. * }}
  123. */
  124. export function setKnockingState(knocking: boolean) {
  125. return {
  126. knocking,
  127. type: SET_KNOCKING_STATE
  128. };
  129. }
  130. /**
  131. * Action to set the new state of the lobby mode.
  132. *
  133. * @param {boolean} enabled - The new state to set.
  134. * @returns {{
  135. * enabled: boolean,
  136. * type: SET_LOBBY_MODE_ENABLED
  137. * }}
  138. */
  139. export function setLobbyModeEnabled(enabled: boolean) {
  140. return {
  141. enabled,
  142. type: SET_LOBBY_MODE_ENABLED
  143. };
  144. }
  145. /**
  146. * Action to be dispatched when we failed to join with a password.
  147. *
  148. * @param {boolean} failed - True of recent password join failed.
  149. * @returns {{
  150. * failed: boolean,
  151. * type: SET_PASSWORD_JOIN_FAILED
  152. * }}
  153. */
  154. export function setPasswordJoinFailed(failed: boolean) {
  155. return {
  156. failed,
  157. type: SET_PASSWORD_JOIN_FAILED
  158. };
  159. }
  160. /**
  161. * Starts knocking and waiting for approval.
  162. *
  163. * @returns {Function}
  164. */
  165. export function startKnocking() {
  166. return async (dispatch: Dispatch<any>, getState: Function) => {
  167. const state = getState();
  168. const { membersOnly } = state['features/base/conference'];
  169. const localParticipant = getLocalParticipant(state);
  170. dispatch(conferenceWillJoin(membersOnly));
  171. // We need to update the conference object with the current display name, if approved
  172. // we want to send that display name, it was not updated in case when pre-join is disabled
  173. sendLocalParticipant(state, membersOnly);
  174. membersOnly.joinLobby(localParticipant.name, localParticipant.email);
  175. dispatch(setKnockingState(true));
  176. };
  177. }
  178. /**
  179. * Action to toggle lobby mode on or off.
  180. *
  181. * @param {boolean} enabled - The desired (new) state of the lobby mode.
  182. * @returns {Function}
  183. */
  184. export function toggleLobbyMode(enabled: boolean) {
  185. return async (dispatch: Dispatch<any>, getState: Function) => {
  186. const conference = getCurrentConference(getState);
  187. if (enabled) {
  188. conference.enableLobby();
  189. } else {
  190. conference.disableLobby();
  191. }
  192. };
  193. }