2017-10-03 19:24:00 +00:00
|
|
|
// @flow
|
|
|
|
|
2017-04-20 23:28:03 +00:00
|
|
|
import {
|
|
|
|
UPDATE_DIAL_IN_NUMBERS_FAILED,
|
|
|
|
UPDATE_DIAL_IN_NUMBERS_SUCCESS
|
|
|
|
} from './actionTypes';
|
2018-03-23 16:37:04 +00:00
|
|
|
import { getDialInConferenceID, getDialInNumbers } from './functions';
|
2017-05-16 19:19:30 +00:00
|
|
|
|
2017-04-20 23:28:03 +00:00
|
|
|
/**
|
2017-05-31 05:32:13 +00:00
|
|
|
* Sends AJAX requests for dial-in numbers and conference ID.
|
2017-04-20 23:28:03 +00:00
|
|
|
*
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2017-05-16 19:19:30 +00:00
|
|
|
export function updateDialInNumbers() {
|
2017-10-03 19:24:00 +00:00
|
|
|
return (dispatch: Dispatch<*>, getState: Function) => {
|
2017-05-31 05:32:13 +00:00
|
|
|
const state = getState();
|
2017-05-19 23:06:10 +00:00
|
|
|
const { dialInConfCodeUrl, dialInNumbersUrl, hosts }
|
2017-05-31 05:32:13 +00:00
|
|
|
= state['features/base/config'];
|
|
|
|
const mucURL = hosts && hosts.muc;
|
2017-05-16 19:19:30 +00:00
|
|
|
|
2017-05-31 05:32:13 +00:00
|
|
|
if (!dialInConfCodeUrl || !dialInNumbersUrl || !mucURL) {
|
2017-07-31 19:44:50 +00:00
|
|
|
// URLs for fetching dial in numbers not defined
|
2017-05-16 19:19:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-31 05:32:13 +00:00
|
|
|
const { room } = state['features/base/conference'];
|
2017-05-16 19:19:30 +00:00
|
|
|
|
|
|
|
Promise.all([
|
2018-03-23 16:37:04 +00:00
|
|
|
getDialInNumbers(dialInNumbersUrl),
|
|
|
|
getDialInConferenceID(dialInConfCodeUrl, room, mucURL)
|
2017-05-31 05:32:13 +00:00
|
|
|
])
|
|
|
|
.then(([ dialInNumbers, { conference, id, message } ]) => {
|
|
|
|
if (!conference || !id) {
|
|
|
|
return Promise.reject(message);
|
|
|
|
}
|
2017-05-16 19:19:30 +00:00
|
|
|
|
2017-05-31 05:32:13 +00:00
|
|
|
dispatch({
|
|
|
|
type: UPDATE_DIAL_IN_NUMBERS_SUCCESS,
|
|
|
|
conferenceID: id,
|
|
|
|
dialInNumbers
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
dispatch({
|
|
|
|
type: UPDATE_DIAL_IN_NUMBERS_FAILED,
|
|
|
|
error
|
|
|
|
});
|
2017-05-16 19:19:30 +00:00
|
|
|
});
|
2017-04-20 23:28:03 +00:00
|
|
|
};
|
|
|
|
}
|