Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

actions.web.js 5.0KB

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