in react/features/invite/actions.any.js [67:192]
export function invite(
invitees: Array<Object>,
showCalleeInfo: boolean = false) {
return (
dispatch: Dispatch<any>,
getState: Function): Promise<Array<Object>> => {
const state = getState();
const participantsCount = getParticipantCount(state);
const { calleeInfoVisible } = state['features/invite'];
if (showCalleeInfo
&& !calleeInfoVisible
&& invitees.length === 1
&& invitees[0].type === INVITE_TYPES.USER
&& participantsCount === 1) {
dispatch(setCalleeInfoVisible(true, invitees[0]));
}
const { conference, password } = state['features/base/conference'];
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,
callback: failedInvitees => resolve(failedInvitees)
}));
});
}
let allInvitePromises = [];
let invitesLeftToSend = [ ...invitees ];
const {
callFlowsEnabled,
inviteServiceUrl,
inviteServiceCallFlowsUrl
} = state['features/base/config'];
const inviteUrl = getInviteURL(state);
const { sipInviteUrl } = state['features/base/config'];
const { locationURL } = state['features/base/connection'];
const { jwt } = state['features/base/jwt'];
const { name: displayName } = getLocalParticipant(state);
// First create all promises for dialing out.
const phoneNumbers
= invitesLeftToSend.filter(({ type }) => type === INVITE_TYPES.PHONE);
// 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);
})
.catch(error =>
logger.error('Error inviting phone number:', error));
});
allInvitePromises = allInvitePromises.concat(phoneInvitePromises);
const usersAndRooms
= invitesLeftToSend.filter(
({ type }) => [ INVITE_TYPES.USER, INVITE_TYPES.ROOM ].includes(type));
if (usersAndRooms.length) {
// Send a request to invite all the rooms and users. On success,
// filter all rooms and users from {@link invitesLeftToSend}.
const peopleInvitePromise
= invitePeopleAndChatRooms(
callFlowsEnabled
? inviteServiceCallFlowsUrl : inviteServiceUrl,
inviteUrl,
jwt,
usersAndRooms)
.then(() => {
invitesLeftToSend
= invitesLeftToSend.filter(
({ type }) => ![ INVITE_TYPES.USER, INVITE_TYPES.ROOM ].includes(type));
})
.catch(error => {
dispatch(setCalleeInfoVisible(false));
logger.error('Error inviting people:', error);
});
allInvitePromises.push(peopleInvitePromise);
}
// Sipgw calls are fire and forget. Invite them to the conference, then
// immediately remove them from invitesLeftToSend.
const vrooms
= invitesLeftToSend.filter(({ type }) => type === INVITE_TYPES.VIDEO_ROOM);
conference
&& vrooms.length > 0
&& dispatch(inviteVideoRooms(conference, vrooms));
invitesLeftToSend
= invitesLeftToSend.filter(({ type }) => type !== INVITE_TYPES.VIDEO_ROOM);
const sipEndpoints
= invitesLeftToSend.filter(({ type }) => type === INVITE_TYPES.SIP);
conference && inviteSipEndpoints(
sipEndpoints,
locationURL,
sipInviteUrl,
jwt,
conference.options.name,
password,
displayName
);
invitesLeftToSend
= invitesLeftToSend.filter(({ type }) => type !== INVITE_TYPES.SIP);
return (
Promise.all(allInvitePromises)
.then(() => invitesLeftToSend));
};
}