2022-12-14 12:23:07 +00:00
|
|
|
import { IStore } from '../app/types';
|
|
|
|
import { getInviteURL } from '../base/connection/functions';
|
|
|
|
import { getLocalParticipant, getParticipantCount } from '../base/participants/functions';
|
|
|
|
import { inviteVideoRooms } from '../videosipgw/actions';
|
2018-04-25 11:06:46 +00:00
|
|
|
|
2022-02-28 20:03:42 +00:00
|
|
|
import { getDialInConferenceID, getDialInNumbers } from './_utils';
|
2017-04-20 23:28:03 +00:00
|
|
|
import {
|
2018-06-26 22:56:22 +00:00
|
|
|
ADD_PENDING_INVITE_REQUEST,
|
2018-05-01 04:43:47 +00:00
|
|
|
BEGIN_ADD_PEOPLE,
|
2020-06-24 12:12:23 +00:00
|
|
|
HIDE_ADD_PEOPLE_DIALOG,
|
2018-06-26 22:56:22 +00:00
|
|
|
REMOVE_PENDING_INVITE_REQUESTS,
|
|
|
|
SET_CALLEE_INFO_VISIBLE,
|
2017-04-20 23:28:03 +00:00
|
|
|
UPDATE_DIAL_IN_NUMBERS_FAILED,
|
|
|
|
UPDATE_DIAL_IN_NUMBERS_SUCCESS
|
|
|
|
} from './actionTypes';
|
2021-05-11 08:51:02 +00:00
|
|
|
import { INVITE_TYPES } from './constants';
|
2018-04-25 11:06:46 +00:00
|
|
|
import {
|
2021-03-18 13:32:14 +00:00
|
|
|
invitePeopleAndChatRooms,
|
|
|
|
inviteSipEndpoints
|
2018-04-25 11:06:46 +00:00
|
|
|
} from './functions';
|
2019-08-21 14:50:00 +00:00
|
|
|
import logger from './logger';
|
2022-12-14 12:23:07 +00:00
|
|
|
import { IInvitee } from './types';
|
2017-05-16 19:19:30 +00:00
|
|
|
|
2018-05-01 04:43:47 +00:00
|
|
|
/**
|
|
|
|
* Creates a (redux) action to signal that a click/tap has been performed on
|
|
|
|
* {@link InviteButton} and that the execution flow for adding/inviting people
|
|
|
|
* to the current conference/meeting is to begin.
|
|
|
|
*
|
|
|
|
* @returns {{
|
|
|
|
* type: BEGIN_ADD_PEOPLE
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function beginAddPeople() {
|
|
|
|
return {
|
|
|
|
type: BEGIN_ADD_PEOPLE
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-06-24 12:12:23 +00:00
|
|
|
/**
|
|
|
|
* Creates a (redux) action to signal that the {@code AddPeopleDialog}
|
|
|
|
* should close.
|
|
|
|
*
|
|
|
|
* @returns {{
|
|
|
|
* type: HIDE_ADD_PEOPLE_DIALOG
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function hideAddPeopleDialog() {
|
|
|
|
return {
|
|
|
|
type: HIDE_ADD_PEOPLE_DIALOG
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-06-26 22:56:22 +00:00
|
|
|
|
2017-04-20 23:28:03 +00:00
|
|
|
/**
|
2018-11-08 12:25:02 +00:00
|
|
|
* Invites (i.e. Sends invites to) an array of invitees (which may be a
|
|
|
|
* combination of users, rooms, phone numbers, and video rooms.
|
2018-04-25 11:06:46 +00:00
|
|
|
*
|
2021-03-16 15:59:33 +00:00
|
|
|
* @param {Array<Object>} invitees - The recipients to send invites to.
|
2018-06-26 22:56:22 +00:00
|
|
|
* @param {Array<Object>} showCalleeInfo - Indicates whether the
|
|
|
|
* {@code CalleeInfo} should be displayed or not.
|
2018-05-03 01:20:31 +00:00
|
|
|
* @returns {Promise<Array<Object>>} A {@code Promise} resolving with an array
|
2018-11-08 12:25:02 +00:00
|
|
|
* of invitees who were not invited (i.e. Invites were not sent to them).
|
2018-04-25 11:06:46 +00:00
|
|
|
*/
|
2018-06-26 22:56:22 +00:00
|
|
|
export function invite(
|
2022-12-14 12:23:07 +00:00
|
|
|
invitees: IInvitee[],
|
|
|
|
showCalleeInfo = false) {
|
2018-04-25 11:06:46 +00:00
|
|
|
return (
|
2022-12-14 12:23:07 +00:00
|
|
|
dispatch: IStore['dispatch'],
|
|
|
|
getState: IStore['getState']): Promise<Array<Object>> => {
|
2018-06-26 22:56:22 +00:00
|
|
|
const state = getState();
|
2021-07-09 12:36:19 +00:00
|
|
|
const participantsCount = getParticipantCount(state);
|
2018-06-26 22:56:22 +00:00
|
|
|
const { calleeInfoVisible } = state['features/invite'];
|
|
|
|
|
|
|
|
if (showCalleeInfo
|
|
|
|
&& !calleeInfoVisible
|
|
|
|
&& invitees.length === 1
|
2021-05-11 08:51:02 +00:00
|
|
|
&& invitees[0].type === INVITE_TYPES.USER
|
2021-07-09 12:36:19 +00:00
|
|
|
&& participantsCount === 1) {
|
2018-06-26 22:56:22 +00:00
|
|
|
dispatch(setCalleeInfoVisible(true, invitees[0]));
|
|
|
|
}
|
|
|
|
|
2021-04-20 13:05:49 +00:00
|
|
|
const { conference, password } = state['features/base/conference'];
|
2018-06-26 22:56:22 +00:00
|
|
|
|
|
|
|
if (typeof conference === 'undefined') {
|
|
|
|
// Invite will fail before CONFERENCE_JOIN. The request will be
|
|
|
|
// cached in order to be executed on CONFERENCE_JOIN.
|
|
|
|
return new Promise(resolve => {
|
|
|
|
dispatch(addPendingInviteRequest({
|
|
|
|
invitees,
|
2022-12-14 12:23:07 +00:00
|
|
|
callback: (failedInvitees: any) => resolve(failedInvitees)
|
2018-06-26 22:56:22 +00:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-14 12:23:07 +00:00
|
|
|
let allInvitePromises: Promise<any>[] = [];
|
2018-05-03 01:20:31 +00:00
|
|
|
let invitesLeftToSend = [ ...invitees ];
|
|
|
|
|
2018-05-23 21:52:44 +00:00
|
|
|
const {
|
|
|
|
callFlowsEnabled,
|
|
|
|
inviteServiceUrl,
|
|
|
|
inviteServiceCallFlowsUrl
|
|
|
|
} = state['features/base/config'];
|
2018-04-25 11:06:46 +00:00
|
|
|
const inviteUrl = getInviteURL(state);
|
2021-03-18 13:32:14 +00:00
|
|
|
const { sipInviteUrl } = state['features/base/config'];
|
2021-04-07 12:46:01 +00:00
|
|
|
const { locationURL } = state['features/base/connection'];
|
2022-12-14 12:23:07 +00:00
|
|
|
const { jwt = '' } = state['features/base/jwt'];
|
|
|
|
const { name: displayName } = getLocalParticipant(state) ?? {};
|
2018-04-25 11:06:46 +00:00
|
|
|
|
|
|
|
// First create all promises for dialing out.
|
2018-06-26 22:56:22 +00:00
|
|
|
const phoneNumbers
|
2021-05-11 08:51:02 +00:00
|
|
|
= invitesLeftToSend.filter(({ type }) => type === INVITE_TYPES.PHONE);
|
2018-04-25 11:06:46 +00:00
|
|
|
|
2018-06-26 22:56:22 +00:00
|
|
|
// For each number, dial out. On success, remove the number from
|
|
|
|
// {@link invitesLeftToSend}.
|
|
|
|
const phoneInvitePromises = phoneNumbers.map(item => {
|
|
|
|
const numberToInvite = item.number;
|
|
|
|
|
|
|
|
return conference.dial(numberToInvite)
|
|
|
|
.then(() => {
|
|
|
|
invitesLeftToSend
|
|
|
|
= invitesLeftToSend.filter(
|
|
|
|
invitee => invitee !== item);
|
|
|
|
})
|
2022-12-14 12:23:07 +00:00
|
|
|
.catch((error: Error) =>
|
2018-06-26 22:56:22 +00:00
|
|
|
logger.error('Error inviting phone number:', error));
|
|
|
|
});
|
|
|
|
|
|
|
|
allInvitePromises = allInvitePromises.concat(phoneInvitePromises);
|
2018-04-25 11:06:46 +00:00
|
|
|
|
2018-05-03 01:20:31 +00:00
|
|
|
const usersAndRooms
|
|
|
|
= invitesLeftToSend.filter(
|
2021-05-11 08:51:02 +00:00
|
|
|
({ type }) => [ INVITE_TYPES.USER, INVITE_TYPES.ROOM ].includes(type));
|
2018-04-25 11:06:46 +00:00
|
|
|
|
|
|
|
if (usersAndRooms.length) {
|
|
|
|
// Send a request to invite all the rooms and users. On success,
|
|
|
|
// filter all rooms and users from {@link invitesLeftToSend}.
|
2018-05-03 01:20:31 +00:00
|
|
|
const peopleInvitePromise
|
|
|
|
= invitePeopleAndChatRooms(
|
2022-12-14 12:23:07 +00:00
|
|
|
(callFlowsEnabled
|
|
|
|
? inviteServiceCallFlowsUrl : inviteServiceUrl) ?? '',
|
2018-05-03 01:20:31 +00:00
|
|
|
inviteUrl,
|
|
|
|
jwt,
|
|
|
|
usersAndRooms)
|
2018-04-25 11:06:46 +00:00
|
|
|
.then(() => {
|
2018-05-03 01:20:31 +00:00
|
|
|
invitesLeftToSend
|
|
|
|
= invitesLeftToSend.filter(
|
2021-05-11 08:51:02 +00:00
|
|
|
({ type }) => ![ INVITE_TYPES.USER, INVITE_TYPES.ROOM ].includes(type));
|
2018-04-25 11:06:46 +00:00
|
|
|
})
|
2018-06-26 22:56:22 +00:00
|
|
|
.catch(error => {
|
|
|
|
dispatch(setCalleeInfoVisible(false));
|
|
|
|
logger.error('Error inviting people:', error);
|
|
|
|
});
|
2018-04-25 11:06:46 +00:00
|
|
|
|
|
|
|
allInvitePromises.push(peopleInvitePromise);
|
|
|
|
}
|
|
|
|
|
2018-05-03 01:20:31 +00:00
|
|
|
// Sipgw calls are fire and forget. Invite them to the conference, then
|
|
|
|
// immediately remove them from invitesLeftToSend.
|
|
|
|
const vrooms
|
2021-05-11 08:51:02 +00:00
|
|
|
= invitesLeftToSend.filter(({ type }) => type === INVITE_TYPES.VIDEO_ROOM);
|
2018-04-25 11:06:46 +00:00
|
|
|
|
|
|
|
conference
|
|
|
|
&& vrooms.length > 0
|
|
|
|
&& dispatch(inviteVideoRooms(conference, vrooms));
|
|
|
|
|
2018-05-03 01:20:31 +00:00
|
|
|
invitesLeftToSend
|
2021-05-11 08:51:02 +00:00
|
|
|
= invitesLeftToSend.filter(({ type }) => type !== INVITE_TYPES.VIDEO_ROOM);
|
2018-04-25 11:06:46 +00:00
|
|
|
|
2021-03-18 13:32:14 +00:00
|
|
|
const sipEndpoints
|
2021-05-11 08:51:02 +00:00
|
|
|
= invitesLeftToSend.filter(({ type }) => type === INVITE_TYPES.SIP);
|
2021-03-18 13:32:14 +00:00
|
|
|
|
|
|
|
conference && inviteSipEndpoints(
|
|
|
|
sipEndpoints,
|
2022-12-14 12:23:07 +00:00
|
|
|
|
|
|
|
// @ts-ignore
|
2021-04-07 12:46:01 +00:00
|
|
|
locationURL,
|
2021-03-18 13:32:14 +00:00
|
|
|
sipInviteUrl,
|
|
|
|
jwt,
|
|
|
|
conference.options.name,
|
2021-04-20 13:05:49 +00:00
|
|
|
password,
|
2021-03-18 13:32:14 +00:00
|
|
|
displayName
|
|
|
|
);
|
|
|
|
|
|
|
|
invitesLeftToSend
|
2021-05-11 08:51:02 +00:00
|
|
|
= invitesLeftToSend.filter(({ type }) => type !== INVITE_TYPES.SIP);
|
2021-03-18 13:32:14 +00:00
|
|
|
|
2018-04-25 11:06:46 +00:00
|
|
|
return (
|
|
|
|
Promise.all(allInvitePromises)
|
2018-05-03 01:20:31 +00:00
|
|
|
.then(() => invitesLeftToSend));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends AJAX requests for dial-in numbers and conference ID.
|
|
|
|
*
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function updateDialInNumbers() {
|
2022-12-14 12:23:07 +00:00
|
|
|
return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
|
2018-05-03 01:20:31 +00:00
|
|
|
const state = getState();
|
|
|
|
const { dialInConfCodeUrl, dialInNumbersUrl, hosts }
|
|
|
|
= state['features/base/config'];
|
2020-05-14 12:30:24 +00:00
|
|
|
const { numbersFetched } = state['features/invite'];
|
2022-12-14 12:23:07 +00:00
|
|
|
const mucURL = hosts?.muc;
|
2018-05-03 01:20:31 +00:00
|
|
|
|
2020-05-14 12:30:24 +00:00
|
|
|
if (numbersFetched || !dialInConfCodeUrl || !dialInNumbersUrl || !mucURL) {
|
2018-05-03 01:20:31 +00:00
|
|
|
// URLs for fetching dial in numbers not defined
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-28 20:03:42 +00:00
|
|
|
const { locationURL = {} } = state['features/base/connection'];
|
2022-12-14 12:23:07 +00:00
|
|
|
const { room = '' } = state['features/base/conference'];
|
2018-05-03 01:20:31 +00:00
|
|
|
|
|
|
|
Promise.all([
|
2022-12-14 12:23:07 +00:00
|
|
|
getDialInNumbers(dialInNumbersUrl, room, mucURL), // @ts-ignore
|
2022-02-28 20:03:42 +00:00
|
|
|
getDialInConferenceID(dialInConfCodeUrl, room, mucURL, locationURL)
|
2018-05-03 01:20:31 +00:00
|
|
|
])
|
2021-05-12 13:21:22 +00:00
|
|
|
.then(([ dialInNumbers, { conference, id, message, sipUri } ]) => {
|
2018-05-03 01:20:31 +00:00
|
|
|
if (!conference || !id) {
|
|
|
|
return Promise.reject(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: UPDATE_DIAL_IN_NUMBERS_SUCCESS,
|
|
|
|
conferenceID: id,
|
2021-05-12 13:21:22 +00:00
|
|
|
dialInNumbers,
|
|
|
|
sipUri
|
2018-05-03 01:20:31 +00:00
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
dispatch({
|
|
|
|
type: UPDATE_DIAL_IN_NUMBERS_FAILED,
|
|
|
|
error
|
|
|
|
});
|
|
|
|
});
|
2018-04-25 11:06:46 +00:00
|
|
|
};
|
|
|
|
}
|
2018-06-26 22:56:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the visibility of {@code CalleeInfo}.
|
|
|
|
*
|
|
|
|
* @param {boolean|undefined} [calleeInfoVisible] - If {@code CalleeInfo} is
|
|
|
|
* to be displayed/visible, then {@code true}; otherwise, {@code false} or
|
|
|
|
* {@code undefined}.
|
|
|
|
* @param {Object|undefined} [initialCalleeInfo] - Callee information.
|
|
|
|
* @returns {{
|
|
|
|
* type: SET_CALLEE_INFO_VISIBLE,
|
|
|
|
* calleeInfoVisible: (boolean|undefined),
|
|
|
|
* initialCalleeInfo
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function setCalleeInfoVisible(
|
|
|
|
calleeInfoVisible: boolean,
|
2022-12-14 12:23:07 +00:00
|
|
|
initialCalleeInfo?: Object) {
|
2018-06-26 22:56:22 +00:00
|
|
|
return {
|
|
|
|
type: SET_CALLEE_INFO_VISIBLE,
|
|
|
|
calleeInfoVisible,
|
|
|
|
initialCalleeInfo
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds pending invite request.
|
|
|
|
*
|
|
|
|
* @param {Object} request - The request.
|
|
|
|
* @returns {{
|
|
|
|
* type: ADD_PENDING_INVITE_REQUEST,
|
|
|
|
* request: Object
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function addPendingInviteRequest(
|
2022-12-14 12:23:07 +00:00
|
|
|
request: { callback: Function; invitees: Array<Object>; }) {
|
2018-06-26 22:56:22 +00:00
|
|
|
return {
|
|
|
|
type: ADD_PENDING_INVITE_REQUEST,
|
|
|
|
request
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes all pending invite requests.
|
|
|
|
*
|
|
|
|
* @returns {{
|
|
|
|
* type: REMOVE_PENDING_INVITE_REQUEST
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function removePendingInviteRequests() {
|
|
|
|
return {
|
|
|
|
type: REMOVE_PENDING_INVITE_REQUESTS
|
|
|
|
};
|
|
|
|
}
|