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.any.js 6.1KB

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