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.

actions.web.js 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 used to admit multiple participants in the conference.
  118. *
  119. * @param {Array<Object>} participants - A list of knocking participants.
  120. * @returns {void}
  121. */
  122. export function admitMultiple(participants: Array<Object>) {
  123. return (dispatch: Function, getState: Function) => {
  124. const conference = getCurrentConference(getState);
  125. participants.forEach(p => {
  126. conference.lobbyApproveAccess(p.id);
  127. });
  128. };
  129. }
  130. /**
  131. * Approves the request of a knocking participant to join the meeting.
  132. *
  133. * @param {string} id - The id of the knocking participant.
  134. * @returns {Function}
  135. */
  136. export function approveKnockingParticipant(id: string) {
  137. return (dispatch: Dispatch<any>, getState: Function) => {
  138. const conference = getCurrentConference(getState);
  139. conference && conference.lobbyApproveAccess(id);
  140. };
  141. }
  142. /**
  143. * Denies the request of a knocking participant to join the meeting.
  144. *
  145. * @param {string} id - The id of the knocking participant.
  146. * @returns {Function}
  147. */
  148. export function rejectKnockingParticipant(id: string) {
  149. return (dispatch: Dispatch<any>, getState: Function) => {
  150. const conference = getCurrentConference(getState);
  151. conference && conference.lobbyDenyAccess(id);
  152. };
  153. }
  154. /**
  155. * Action to set the knocking state of the participant.
  156. *
  157. * @param {boolean} knocking - The new state.
  158. * @returns {{
  159. * state: boolean,
  160. * type: SET_KNOCKING_STATE
  161. * }}
  162. */
  163. export function setKnockingState(knocking: boolean) {
  164. return {
  165. knocking,
  166. type: SET_KNOCKING_STATE
  167. };
  168. }
  169. /**
  170. * Action to set the new state of the lobby mode.
  171. *
  172. * @param {boolean} enabled - The new state to set.
  173. * @returns {{
  174. * enabled: boolean,
  175. * type: SET_LOBBY_MODE_ENABLED
  176. * }}
  177. */
  178. export function setLobbyModeEnabled(enabled: boolean) {
  179. return {
  180. enabled,
  181. type: SET_LOBBY_MODE_ENABLED
  182. };
  183. }
  184. /**
  185. * Action to be dispatched when we failed to join with a password.
  186. *
  187. * @param {boolean} failed - True of recent password join failed.
  188. * @returns {{
  189. * failed: boolean,
  190. * type: SET_PASSWORD_JOIN_FAILED
  191. * }}
  192. */
  193. export function setPasswordJoinFailed(failed: boolean) {
  194. return {
  195. failed,
  196. type: SET_PASSWORD_JOIN_FAILED
  197. };
  198. }
  199. /**
  200. * Starts knocking and waiting for approval.
  201. *
  202. * @returns {Function}
  203. */
  204. export function startKnocking() {
  205. return async (dispatch: Dispatch<any>, getState: Function) => {
  206. const state = getState();
  207. const { membersOnly } = state['features/base/conference'];
  208. const localParticipant = getLocalParticipant(state);
  209. dispatch(conferenceWillJoin(membersOnly));
  210. // We need to update the conference object with the current display name, if approved
  211. // we want to send that display name, it was not updated in case when pre-join is disabled
  212. sendLocalParticipant(state, membersOnly);
  213. membersOnly.joinLobby(localParticipant.name, localParticipant.email);
  214. dispatch(setKnockingState(true));
  215. };
  216. }