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.1KB

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