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 5.8KB

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