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.js 5.0KB

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