jiti-meet/react/features/invite/actions.js

67 lines
1.8 KiB
JavaScript
Raw Normal View History

// @flow
import {
BEGIN_ADD_PEOPLE,
UPDATE_DIAL_IN_NUMBERS_FAILED,
UPDATE_DIAL_IN_NUMBERS_SUCCESS
} from './actionTypes';
import { getDialInConferenceID, getDialInNumbers } from './functions';
/**
* 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
};
}
/**
* Sends AJAX requests for dial-in numbers and conference ID.
*
* @returns {Function}
*/
export function updateDialInNumbers() {
return (dispatch: Dispatch<*>, getState: Function) => {
const state = getState();
2017-05-19 23:06:10 +00:00
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
});
});
};
}