2020-04-15 13:13:43 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import { type Dispatch } from 'redux';
|
|
|
|
|
2020-06-04 14:09:13 +00:00
|
|
|
import { appNavigate, maybeRedirectToWelcomePage } from '../app/actions';
|
2020-05-20 08:25:31 +00:00
|
|
|
import { conferenceWillJoin, getCurrentConference, setPassword } from '../base/conference';
|
|
|
|
import { hideDialog, openDialog } from '../base/dialog';
|
2020-04-15 13:13:43 +00:00
|
|
|
import { getLocalParticipant } from '../base/participants';
|
|
|
|
|
|
|
|
import {
|
|
|
|
KNOCKING_PARTICIPANT_ARRIVED_OR_UPDATED,
|
|
|
|
KNOCKING_PARTICIPANT_LEFT,
|
|
|
|
SET_KNOCKING_STATE,
|
2020-05-20 08:25:31 +00:00
|
|
|
SET_LOBBY_MODE_ENABLED,
|
|
|
|
SET_PASSWORD_JOIN_FAILED
|
2020-04-15 13:13:43 +00:00
|
|
|
} from './actionTypes';
|
2020-05-20 08:25:31 +00:00
|
|
|
import { LobbyScreen } from './components';
|
2020-04-15 13:13:43 +00:00
|
|
|
|
|
|
|
declare var APP: Object;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cancels the ongoing knocking and abandones the join flow.
|
|
|
|
*
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function cancelKnocking() {
|
2020-05-20 08:25:31 +00:00
|
|
|
return async (dispatch: Dispatch<any>) => {
|
2020-04-15 13:13:43 +00:00
|
|
|
if (typeof APP !== 'undefined') {
|
|
|
|
// when we are redirecting the library should handle any
|
|
|
|
// unload and clean of the connection.
|
|
|
|
APP.API.notifyReadyToClose();
|
|
|
|
dispatch(maybeRedirectToWelcomePage());
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(appNavigate(undefined));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-05-20 08:25:31 +00:00
|
|
|
* Action to hide the lobby screen.
|
2020-04-15 13:13:43 +00:00
|
|
|
*
|
2020-05-20 08:25:31 +00:00
|
|
|
* @returns {hideDialog}
|
2020-04-15 13:13:43 +00:00
|
|
|
*/
|
2020-05-20 08:25:31 +00:00
|
|
|
export function hideLobbyScreen() {
|
|
|
|
return hideDialog(LobbyScreen);
|
2020-04-15 13:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-05-20 08:25:31 +00:00
|
|
|
* Tries to join with a preset password.
|
2020-04-15 13:13:43 +00:00
|
|
|
*
|
2020-05-20 08:25:31 +00:00
|
|
|
* @param {string} password - The password to join with.
|
|
|
|
* @returns {Function}
|
2020-04-15 13:13:43 +00:00
|
|
|
*/
|
2020-05-20 08:25:31 +00:00
|
|
|
export function joinWithPassword(password: string) {
|
|
|
|
return async (dispatch: Dispatch<any>, getState: Function) => {
|
|
|
|
const conference = getCurrentConference(getState);
|
|
|
|
|
|
|
|
dispatch(setPassword(conference, conference.join, password));
|
2020-04-15 13:13:43 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-05-20 08:25:31 +00:00
|
|
|
* Action to be dispatched when a knocking poarticipant leaves before any response.
|
2020-04-15 13:13:43 +00:00
|
|
|
*
|
2020-05-20 08:25:31 +00:00
|
|
|
* @param {string} id - The ID of the participant.
|
|
|
|
* @returns {{
|
|
|
|
* id: string,
|
|
|
|
* type: KNOCKING_PARTICIPANT_LEFT
|
|
|
|
* }}
|
2020-04-15 13:13:43 +00:00
|
|
|
*/
|
2020-05-20 08:25:31 +00:00
|
|
|
export function knockingParticipantLeft(id: string) {
|
|
|
|
return {
|
|
|
|
id,
|
|
|
|
type: KNOCKING_PARTICIPANT_LEFT
|
2020-04-15 13:13:43 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Action to open the lobby screen.
|
|
|
|
*
|
|
|
|
* @returns {openDialog}
|
|
|
|
*/
|
|
|
|
export function openLobbyScreen() {
|
2020-05-20 08:25:31 +00:00
|
|
|
return openDialog(LobbyScreen, {}, true);
|
2020-04-15 13:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Action to be executed when a participant starts knocking or an already knocking participant gets updated.
|
|
|
|
*
|
|
|
|
* @param {Object} participant - The knocking participant.
|
|
|
|
* @returns {{
|
|
|
|
* participant: Object,
|
|
|
|
* type: KNOCKING_PARTICIPANT_ARRIVED_OR_UPDATED
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function participantIsKnockingOrUpdated(participant: Object) {
|
|
|
|
return {
|
|
|
|
participant,
|
|
|
|
type: KNOCKING_PARTICIPANT_ARRIVED_OR_UPDATED
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Approves (lets in) or rejects a knocking participant.
|
|
|
|
*
|
|
|
|
* @param {string} id - The id of the knocking participant.
|
|
|
|
* @param {boolean} approved - True if the participant is approved, false otherwise.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function setKnockingParticipantApproval(id: string, approved: boolean) {
|
|
|
|
return async (dispatch: Dispatch<any>, getState: Function) => {
|
2020-05-20 08:25:31 +00:00
|
|
|
const conference = getCurrentConference(getState);
|
2020-04-15 13:13:43 +00:00
|
|
|
|
|
|
|
if (conference) {
|
|
|
|
if (approved) {
|
|
|
|
conference.lobbyApproveAccess(id);
|
|
|
|
} else {
|
|
|
|
conference.lobbyDenyAccess(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-05-20 08:25:31 +00:00
|
|
|
/**
|
|
|
|
* Action to set the knocking state of the participant.
|
|
|
|
*
|
|
|
|
* @param {boolean} knocking - The new state.
|
|
|
|
* @returns {{
|
|
|
|
* state: boolean,
|
|
|
|
* type: SET_KNOCKING_STATE
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function setKnockingState(knocking: boolean) {
|
|
|
|
return {
|
|
|
|
knocking,
|
|
|
|
type: SET_KNOCKING_STATE
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-04-15 13:13:43 +00:00
|
|
|
/**
|
|
|
|
* Action to set the new state of the lobby mode.
|
|
|
|
*
|
|
|
|
* @param {boolean} enabled - The new state to set.
|
|
|
|
* @returns {{
|
|
|
|
* enabled: boolean,
|
|
|
|
* type: SET_LOBBY_MODE_ENABLED
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function setLobbyModeEnabled(enabled: boolean) {
|
|
|
|
return {
|
|
|
|
enabled,
|
|
|
|
type: SET_LOBBY_MODE_ENABLED
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-05-20 08:25:31 +00:00
|
|
|
* Action to be dispatched when we failed to join with a password.
|
2020-04-15 13:13:43 +00:00
|
|
|
*
|
2020-05-20 08:25:31 +00:00
|
|
|
* @param {boolean} failed - True of recent password join failed.
|
|
|
|
* @returns {{
|
|
|
|
* failed: boolean,
|
|
|
|
* type: SET_PASSWORD_JOIN_FAILED
|
|
|
|
* }}
|
2020-04-15 13:13:43 +00:00
|
|
|
*/
|
2020-05-20 08:25:31 +00:00
|
|
|
export function setPasswordJoinFailed(failed: boolean) {
|
|
|
|
return {
|
|
|
|
failed,
|
|
|
|
type: SET_PASSWORD_JOIN_FAILED
|
|
|
|
};
|
2020-04-15 13:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-05-20 08:25:31 +00:00
|
|
|
* Starts knocking and waiting for approval.
|
2020-04-15 13:13:43 +00:00
|
|
|
*
|
2020-05-20 08:25:31 +00:00
|
|
|
* @returns {Function}
|
2020-04-15 13:13:43 +00:00
|
|
|
*/
|
2020-05-20 08:25:31 +00:00
|
|
|
export function startKnocking() {
|
|
|
|
return async (dispatch: Dispatch<any>, getState: Function) => {
|
|
|
|
const state = getState();
|
|
|
|
const { membersOnly } = state['features/base/conference'];
|
|
|
|
const localParticipant = getLocalParticipant(state);
|
|
|
|
|
|
|
|
dispatch(conferenceWillJoin(membersOnly));
|
|
|
|
membersOnly.joinLobby(localParticipant.name, localParticipant.email);
|
|
|
|
dispatch(setKnockingState(true));
|
|
|
|
};
|
2020-04-15 13:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Action to toggle lobby mode on or off.
|
|
|
|
*
|
|
|
|
* @param {boolean} enabled - The desired (new) state of the lobby mode.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2020-05-20 08:25:31 +00:00
|
|
|
export function toggleLobbyMode(enabled: boolean) {
|
2020-04-15 13:13:43 +00:00
|
|
|
return async (dispatch: Dispatch<any>, getState: Function) => {
|
2020-05-20 08:25:31 +00:00
|
|
|
const conference = getCurrentConference(getState);
|
2020-04-15 13:13:43 +00:00
|
|
|
|
|
|
|
if (enabled) {
|
2020-05-20 08:25:31 +00:00
|
|
|
conference.enableLobby();
|
2020-04-15 13:13:43 +00:00
|
|
|
} else {
|
|
|
|
conference.disableLobby();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|