2017-04-13 00:23:43 +00:00
|
|
|
import { openDialog } from '../../features/base/dialog';
|
|
|
|
|
2017-04-20 23:28:03 +00:00
|
|
|
import {
|
|
|
|
UPDATE_DIAL_IN_NUMBERS_FAILED,
|
|
|
|
UPDATE_DIAL_IN_NUMBERS_SUCCESS
|
|
|
|
} from './actionTypes';
|
2017-04-13 00:23:43 +00:00
|
|
|
import { InviteDialog } from './components';
|
|
|
|
|
2017-04-20 23:28:03 +00:00
|
|
|
declare var $: Function;
|
|
|
|
declare var APP: Object;
|
|
|
|
declare var config: Object;
|
|
|
|
|
2017-05-19 22:35:10 +00:00
|
|
|
/**
|
|
|
|
* The url for the api that matches a conference name and muc to an id.
|
|
|
|
*
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
const DIAL_IN_CONF_CODE_URL = config.dialInConfCodeUrl;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The url for the api that returns phone numbers to dial in to the conference
|
|
|
|
* and join using the conference id.
|
|
|
|
*
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
const DIAL_IN_NUMBERS_URLS = config.dialInNumbersUrl;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The url for the MUC component joined for the conference.
|
|
|
|
*
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
const MUC_URL = config.hosts && config.hosts.muc;
|
2017-05-16 19:19:30 +00:00
|
|
|
|
2017-04-13 00:23:43 +00:00
|
|
|
/**
|
|
|
|
* Opens the Invite Dialog.
|
|
|
|
*
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function openInviteDialog() {
|
2017-04-18 21:49:52 +00:00
|
|
|
return openDialog(InviteDialog, {
|
2017-05-16 19:19:30 +00:00
|
|
|
conferenceUrl: encodeURI(APP.ConferenceUrl.getInviteUrl())
|
2017-04-18 21:49:52 +00:00
|
|
|
});
|
2017-04-13 00:23:43 +00:00
|
|
|
}
|
2017-04-20 23:28:03 +00:00
|
|
|
|
|
|
|
/**
|
2017-05-16 19:19:30 +00:00
|
|
|
* Sends an 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() {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
|
2017-05-19 22:35:10 +00:00
|
|
|
if (!DIAL_IN_CONF_CODE_URL || !DIAL_IN_NUMBERS_URLS || !MUC_URL) {
|
|
|
|
dispatch({
|
|
|
|
type: UPDATE_DIAL_IN_NUMBERS_FAILED,
|
|
|
|
error: 'URLs for fetching dial in numbers not properly defined'
|
|
|
|
});
|
|
|
|
|
2017-05-16 19:19:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { room } = getState()['features/base/conference'];
|
|
|
|
const conferenceIdUrl
|
2017-05-19 22:35:10 +00:00
|
|
|
= `${DIAL_IN_CONF_CODE_URL}?conference=${room}@${MUC_URL}`;
|
2017-05-16 19:19:30 +00:00
|
|
|
|
|
|
|
Promise.all([
|
2017-05-19 22:35:10 +00:00
|
|
|
$.getJSON(DIAL_IN_NUMBERS_URLS),
|
2017-05-16 19:19:30 +00:00
|
|
|
$.getJSON(conferenceIdUrl)
|
|
|
|
]).then(([ numbersResponse, idResponse ]) => {
|
|
|
|
if (!idResponse.conference || !idResponse.id) {
|
|
|
|
return Promise.reject(idResponse.message);
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: UPDATE_DIAL_IN_NUMBERS_SUCCESS,
|
|
|
|
conferenceId: idResponse,
|
|
|
|
dialInNumbers: numbersResponse
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
dispatch({
|
|
|
|
type: UPDATE_DIAL_IN_NUMBERS_FAILED,
|
|
|
|
error
|
|
|
|
});
|
2017-04-20 23:28:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|