2017-10-03 19:24:00 +00:00
|
|
|
// @flow
|
|
|
|
|
2018-04-25 11:06:46 +00:00
|
|
|
import { getInviteURL } from '../base/connection';
|
|
|
|
import { inviteVideoRooms } from '../videosipgw';
|
|
|
|
|
2017-04-20 23:28:03 +00:00
|
|
|
import {
|
2018-05-01 04:43:47 +00:00
|
|
|
BEGIN_ADD_PEOPLE,
|
2017-04-20 23:28:03 +00:00
|
|
|
UPDATE_DIAL_IN_NUMBERS_FAILED,
|
|
|
|
UPDATE_DIAL_IN_NUMBERS_SUCCESS
|
|
|
|
} from './actionTypes';
|
2018-04-25 11:06:46 +00:00
|
|
|
import {
|
|
|
|
getDialInConferenceID,
|
|
|
|
getDialInNumbers,
|
|
|
|
getDigitsOnly,
|
|
|
|
invitePeopleAndChatRooms
|
|
|
|
} from './functions';
|
|
|
|
|
|
|
|
const logger = require('jitsi-meet-logger').getLogger(__filename);
|
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
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-04-20 23:28:03 +00:00
|
|
|
/**
|
2018-05-03 01:20:31 +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
|
|
|
*
|
2018-05-03 01:20:31 +00:00
|
|
|
* @param {Array<Object>} invitees - The recepients to send invites to.
|
|
|
|
* @returns {Promise<Array<Object>>} A {@code Promise} resolving with an array
|
|
|
|
* of invitees who were not invited (i.e. invites were not sent to them).
|
2018-04-25 11:06:46 +00:00
|
|
|
*/
|
2018-05-03 01:20:31 +00:00
|
|
|
export function invite(invitees: Array<Object>) {
|
2018-04-25 11:06:46 +00:00
|
|
|
return (
|
|
|
|
dispatch: Dispatch<*>,
|
|
|
|
getState: Function): Promise<Array<Object>> => {
|
|
|
|
let allInvitePromises = [];
|
2018-05-03 01:20:31 +00:00
|
|
|
let invitesLeftToSend = [ ...invitees ];
|
|
|
|
|
2018-04-25 11:06:46 +00:00
|
|
|
const state = getState();
|
|
|
|
const { conference } = state['features/base/conference'];
|
|
|
|
const { inviteServiceUrl } = state['features/base/config'];
|
|
|
|
const inviteUrl = getInviteURL(state);
|
2018-05-03 01:20:31 +00:00
|
|
|
const { jwt } = state['features/base/jwt'];
|
2018-04-25 11:06:46 +00:00
|
|
|
|
|
|
|
// First create all promises for dialing out.
|
|
|
|
if (conference) {
|
|
|
|
const phoneNumbers
|
|
|
|
= invitesLeftToSend.filter(({ type }) => type === 'phone');
|
|
|
|
|
|
|
|
// For each number, dial out. On success, remove the number from
|
|
|
|
// {@link invitesLeftToSend}.
|
|
|
|
const phoneInvitePromises = phoneNumbers.map(item => {
|
|
|
|
const numberToInvite = getDigitsOnly(item.number);
|
|
|
|
|
|
|
|
return conference.dial(numberToInvite)
|
2018-05-03 01:20:31 +00:00
|
|
|
.then(() => {
|
|
|
|
invitesLeftToSend
|
|
|
|
= invitesLeftToSend.filter(
|
|
|
|
invitee => invitee !== item);
|
|
|
|
})
|
|
|
|
.catch(error =>
|
|
|
|
logger.error('Error inviting phone number:', error));
|
2018-04-25 11:06:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
allInvitePromises = allInvitePromises.concat(phoneInvitePromises);
|
|
|
|
}
|
|
|
|
|
2018-05-03 01:20:31 +00:00
|
|
|
const usersAndRooms
|
|
|
|
= invitesLeftToSend.filter(
|
|
|
|
({ type }) => type === 'user' || type === 'room');
|
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(
|
|
|
|
inviteServiceUrl,
|
|
|
|
inviteUrl,
|
|
|
|
jwt,
|
|
|
|
usersAndRooms)
|
2018-04-25 11:06:46 +00:00
|
|
|
.then(() => {
|
2018-05-03 01:20:31 +00:00
|
|
|
invitesLeftToSend
|
|
|
|
= invitesLeftToSend.filter(
|
|
|
|
({ type }) => type !== 'user' && type !== 'room');
|
2018-04-25 11:06:46 +00:00
|
|
|
})
|
2018-05-03 01:20:31 +00:00
|
|
|
.catch(error => 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
|
|
|
|
= invitesLeftToSend.filter(({ type }) => type === 'videosipgw');
|
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
|
|
|
|
= invitesLeftToSend.filter(({ type }) => type !== 'videosipgw');
|
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() {
|
|
|
|
return (dispatch: Dispatch<*>, getState: Function) => {
|
|
|
|
const state = getState();
|
|
|
|
const { dialInConfCodeUrl, dialInNumbersUrl, hosts }
|
|
|
|
= state['features/base/config'];
|
|
|
|
const mucURL = hosts && hosts.muc;
|
|
|
|
|
|
|
|
if (!dialInConfCodeUrl || !dialInNumbersUrl || !mucURL) {
|
|
|
|
// URLs for fetching dial in numbers not defined
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { room } = state['features/base/conference'];
|
|
|
|
|
|
|
|
Promise.all([
|
|
|
|
getDialInNumbers(dialInNumbersUrl),
|
|
|
|
getDialInConferenceID(dialInConfCodeUrl, room, mucURL)
|
|
|
|
])
|
|
|
|
.then(([ dialInNumbers, { conference, id, message } ]) => {
|
|
|
|
if (!conference || !id) {
|
|
|
|
return Promise.reject(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: UPDATE_DIAL_IN_NUMBERS_SUCCESS,
|
|
|
|
conferenceID: id,
|
|
|
|
dialInNumbers
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
dispatch({
|
|
|
|
type: UPDATE_DIAL_IN_NUMBERS_FAILED,
|
|
|
|
error
|
|
|
|
});
|
|
|
|
});
|
2018-04-25 11:06:46 +00:00
|
|
|
};
|
|
|
|
}
|