2017-10-03 19:24:00 +00:00
|
|
|
// @flow
|
|
|
|
|
2021-02-24 09:37:14 +00:00
|
|
|
import { getActiveSession } from '../../features/recording/functions';
|
|
|
|
import { getRoomName } from '../base/conference';
|
|
|
|
import { getInviteURL } from '../base/connection';
|
2018-08-17 19:34:41 +00:00
|
|
|
import { i18next } from '../base/i18n';
|
2021-02-24 09:37:14 +00:00
|
|
|
import { JitsiRecordingConstants } from '../base/lib-jitsi-meet';
|
|
|
|
import { getLocalParticipant, isLocalParticipantModerator } from '../base/participants';
|
2020-05-14 12:30:24 +00:00
|
|
|
import { toState } from '../base/redux';
|
2018-08-17 19:34:41 +00:00
|
|
|
import { doGetJSON, parseURIString } from '../base/util';
|
2021-01-13 09:12:41 +00:00
|
|
|
import { isVpaasMeeting } from '../billing-counter/functions';
|
2018-03-23 16:37:04 +00:00
|
|
|
|
2019-08-21 14:50:00 +00:00
|
|
|
import logger from './logger';
|
|
|
|
|
2017-06-14 18:41:22 +00:00
|
|
|
declare var $: Function;
|
2017-10-03 16:30:42 +00:00
|
|
|
declare var interfaceConfig: Object;
|
2017-06-14 18:41:22 +00:00
|
|
|
|
2018-05-01 04:43:47 +00:00
|
|
|
/**
|
|
|
|
* Sends an ajax request to check if the phone number can be called.
|
|
|
|
*
|
|
|
|
* @param {string} dialNumber - The dial number to check for validity.
|
|
|
|
* @param {string} dialOutAuthUrl - The endpoint to use for checking validity.
|
|
|
|
* @returns {Promise} - The promise created by the request.
|
|
|
|
*/
|
|
|
|
export function checkDialNumber(
|
|
|
|
dialNumber: string,
|
|
|
|
dialOutAuthUrl: string
|
|
|
|
): Promise<Object> {
|
|
|
|
const fullUrl = `${dialOutAuthUrl}?phone=${dialNumber}`;
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
$.getJSON(fullUrl)
|
|
|
|
.then(resolve)
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-03-23 16:37:04 +00:00
|
|
|
/**
|
|
|
|
* Sends a GET request to obtain the conference ID necessary for identifying
|
|
|
|
* which conference to join after diaing the dial-in service.
|
|
|
|
*
|
|
|
|
* @param {string} baseUrl - The url for obtaining the conference ID (pin) for
|
|
|
|
* dialing into a conference.
|
|
|
|
* @param {string} roomName - The conference name to find the associated
|
|
|
|
* conference ID.
|
|
|
|
* @param {string} mucURL - In which MUC the conference exists.
|
|
|
|
* @returns {Promise} - The promise created by the request.
|
|
|
|
*/
|
|
|
|
export function getDialInConferenceID(
|
|
|
|
baseUrl: string,
|
|
|
|
roomName: string,
|
2018-05-01 04:43:47 +00:00
|
|
|
mucURL: string
|
|
|
|
): Promise<Object> {
|
|
|
|
|
2018-03-23 16:37:04 +00:00
|
|
|
const conferenceIDURL = `${baseUrl}?conference=${roomName}@${mucURL}`;
|
|
|
|
|
2019-08-13 13:34:44 +00:00
|
|
|
return doGetJSON(conferenceIDURL, true);
|
2018-03-23 16:37:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a GET request for phone numbers used to dial into a conference.
|
|
|
|
*
|
2019-02-26 13:32:46 +00:00
|
|
|
* @param {string} url - The service that returns conference dial-in numbers.
|
2019-02-02 03:10:34 +00:00
|
|
|
* @param {string} roomName - The conference name to find the associated
|
|
|
|
* conference ID.
|
|
|
|
* @param {string} mucURL - In which MUC the conference exists.
|
2018-03-23 16:37:04 +00:00
|
|
|
* @returns {Promise} - The promise created by the request. The returned numbers
|
2019-02-26 13:32:46 +00:00
|
|
|
* may be an array of Objects containing numbers, with keys countryCode,
|
|
|
|
* tollFree, formattedNumber or an object with countries as keys and arrays of
|
|
|
|
* phone number strings, as the second one should not be used and is deprecated.
|
2018-03-23 16:37:04 +00:00
|
|
|
*/
|
2019-02-02 03:10:34 +00:00
|
|
|
export function getDialInNumbers(
|
|
|
|
url: string,
|
|
|
|
roomName: string,
|
|
|
|
mucURL: string
|
|
|
|
): Promise<*> {
|
|
|
|
|
|
|
|
const fullUrl = `${url}?conference=${roomName}@${mucURL}`;
|
|
|
|
|
2019-08-13 13:34:44 +00:00
|
|
|
return doGetJSON(fullUrl, true);
|
2018-03-23 16:37:04 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 00:49:22 +00:00
|
|
|
/**
|
|
|
|
* Removes all non-numeric characters from a string.
|
|
|
|
*
|
2018-05-03 01:20:31 +00:00
|
|
|
* @param {string} text - The string from which to remove all characters except
|
|
|
|
* numbers.
|
2018-03-28 00:49:22 +00:00
|
|
|
* @returns {string} A string with only numbers.
|
|
|
|
*/
|
2018-04-25 11:06:46 +00:00
|
|
|
export function getDigitsOnly(text: string = ''): string {
|
2018-03-28 00:49:22 +00:00
|
|
|
return text.replace(/\D/g, '');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Type of the options to use when sending a search query.
|
|
|
|
*/
|
|
|
|
export type GetInviteResultsOptions = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The endpoint to use for checking phone number validity.
|
|
|
|
*/
|
|
|
|
dialOutAuthUrl: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not to search for people.
|
|
|
|
*/
|
2018-05-01 04:43:47 +00:00
|
|
|
addPeopleEnabled: boolean,
|
2018-03-28 00:49:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not to check phone numbers.
|
|
|
|
*/
|
2018-05-01 04:43:47 +00:00
|
|
|
dialOutEnabled: boolean,
|
2018-03-28 00:49:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Array with the query types that will be executed -
|
|
|
|
* "conferenceRooms" | "user" | "room".
|
|
|
|
*/
|
|
|
|
peopleSearchQueryTypes: Array<string>,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The url to query for people.
|
|
|
|
*/
|
|
|
|
peopleSearchUrl: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The jwt token to pass to the search service.
|
|
|
|
*/
|
|
|
|
jwt: string
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Combines directory search with phone number validation to produce a single
|
|
|
|
* set of invite search results.
|
|
|
|
*
|
2018-05-03 01:20:31 +00:00
|
|
|
* @param {string} query - Text to search.
|
|
|
|
* @param {GetInviteResultsOptions} options - Options to use when searching.
|
2018-03-28 00:49:22 +00:00
|
|
|
* @returns {Promise<*>}
|
|
|
|
*/
|
|
|
|
export function getInviteResultsForQuery(
|
|
|
|
query: string,
|
2018-05-01 04:43:47 +00:00
|
|
|
options: GetInviteResultsOptions
|
|
|
|
): Promise<*> {
|
|
|
|
|
2018-03-28 00:49:22 +00:00
|
|
|
const text = query.trim();
|
|
|
|
|
|
|
|
const {
|
|
|
|
dialOutAuthUrl,
|
2018-05-01 04:43:47 +00:00
|
|
|
addPeopleEnabled,
|
|
|
|
dialOutEnabled,
|
2018-03-28 00:49:22 +00:00
|
|
|
peopleSearchQueryTypes,
|
|
|
|
peopleSearchUrl,
|
|
|
|
jwt
|
|
|
|
} = options;
|
|
|
|
|
|
|
|
let peopleSearchPromise;
|
|
|
|
|
2018-05-01 04:43:47 +00:00
|
|
|
if (addPeopleEnabled && text) {
|
2018-03-28 00:49:22 +00:00
|
|
|
peopleSearchPromise = searchDirectory(
|
|
|
|
peopleSearchUrl,
|
|
|
|
jwt,
|
|
|
|
text,
|
|
|
|
peopleSearchQueryTypes);
|
|
|
|
} else {
|
|
|
|
peopleSearchPromise = Promise.resolve([]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-13 17:04:58 +00:00
|
|
|
let hasCountryCode = text.startsWith('+');
|
2018-03-28 00:49:22 +00:00
|
|
|
let phoneNumberPromise;
|
|
|
|
|
2018-06-13 17:04:58 +00:00
|
|
|
// Phone numbers are handled a specially to enable both cases of restricting
|
|
|
|
// numbers to telephone number-y numbers and accepting any arbitrary string,
|
|
|
|
// which may be valid for SIP (jigasi) calls. If the dialOutAuthUrl is
|
|
|
|
// defined, then it is assumed the call is to a telephone number and
|
|
|
|
// some validation of the number is completed, with the + sign used as a way
|
|
|
|
// for the UI to detect and enforce the usage of a country code. If the
|
|
|
|
// dialOutAuthUrl is not defined, accept anything because this is assumed
|
|
|
|
// to be the SIP (jigasi) case.
|
|
|
|
if (dialOutEnabled && dialOutAuthUrl && isMaybeAPhoneNumber(text)) {
|
2018-03-28 00:49:22 +00:00
|
|
|
let numberToVerify = text;
|
|
|
|
|
|
|
|
// When the number to verify does not start with a +, we assume no
|
2018-05-03 01:20:31 +00:00
|
|
|
// proper country code has been entered. In such a case, prepend 1 for
|
|
|
|
// the country code. The service currently takes care of prepending the
|
|
|
|
// +.
|
2018-03-28 00:49:22 +00:00
|
|
|
if (!hasCountryCode && !text.startsWith('1')) {
|
|
|
|
numberToVerify = `1${numberToVerify}`;
|
|
|
|
}
|
|
|
|
|
2018-05-03 01:20:31 +00:00
|
|
|
// The validation service works properly when the query is digits only
|
|
|
|
// so ensure only digits get sent.
|
2018-03-28 00:49:22 +00:00
|
|
|
numberToVerify = getDigitsOnly(numberToVerify);
|
|
|
|
|
2018-05-03 01:20:31 +00:00
|
|
|
phoneNumberPromise = checkDialNumber(numberToVerify, dialOutAuthUrl);
|
2018-06-13 17:04:58 +00:00
|
|
|
} else if (dialOutEnabled && !dialOutAuthUrl) {
|
|
|
|
// fake having a country code to hide the country code reminder
|
|
|
|
hasCountryCode = true;
|
|
|
|
|
|
|
|
// With no auth url, let's say the text is a valid number
|
|
|
|
phoneNumberPromise = Promise.resolve({
|
|
|
|
allow: true,
|
|
|
|
country: '',
|
|
|
|
phone: text
|
|
|
|
});
|
2018-03-28 00:49:22 +00:00
|
|
|
} else {
|
|
|
|
phoneNumberPromise = Promise.resolve({});
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.all([ peopleSearchPromise, phoneNumberPromise ])
|
|
|
|
.then(([ peopleResults, phoneResults ]) => {
|
|
|
|
const results = [
|
|
|
|
...peopleResults
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
2018-05-03 01:20:31 +00:00
|
|
|
* This check for phone results is for the day the call to searching
|
|
|
|
* people might return phone results as well. When that day comes
|
|
|
|
* this check will make it so the server checks are honored and the
|
|
|
|
* local appending of the number is not done. The local appending of
|
|
|
|
* the phone number can then be cleaned up when convenient.
|
2018-03-28 00:49:22 +00:00
|
|
|
*/
|
2018-05-03 01:20:31 +00:00
|
|
|
const hasPhoneResult
|
|
|
|
= peopleResults.find(result => result.type === 'phone');
|
2018-03-28 00:49:22 +00:00
|
|
|
|
2018-05-03 01:20:31 +00:00
|
|
|
if (!hasPhoneResult && typeof phoneResults.allow === 'boolean') {
|
2018-03-28 00:49:22 +00:00
|
|
|
results.push({
|
|
|
|
allowed: phoneResults.allow,
|
|
|
|
country: phoneResults.country,
|
|
|
|
type: 'phone',
|
|
|
|
number: phoneResults.phone,
|
|
|
|
originalEntry: text,
|
|
|
|
showCountryCodeReminder: !hasCountryCode
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return results;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-04-01 07:47:51 +00:00
|
|
|
/**
|
|
|
|
* Creates a message describing how to dial in to the conference.
|
|
|
|
*
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
export function getInviteText({
|
2021-02-24 09:37:14 +00:00
|
|
|
state,
|
2020-04-01 07:47:51 +00:00
|
|
|
phoneNumber,
|
|
|
|
t
|
|
|
|
}: Object) {
|
2021-02-24 09:37:14 +00:00
|
|
|
const dialIn = state['features/invite'];
|
|
|
|
const inviteUrl = getInviteURL(state);
|
|
|
|
const currentLiveStreamingSession = getActiveSession(state, JitsiRecordingConstants.mode.STREAM);
|
|
|
|
const liveStreamViewURL
|
|
|
|
= currentLiveStreamingSession
|
|
|
|
&& currentLiveStreamingSession.liveStreamViewURL;
|
|
|
|
const localParticipant = getLocalParticipant(state);
|
|
|
|
const localParticipantName = localParticipant?.name;
|
|
|
|
|
|
|
|
const inviteURL = _decodeRoomURI(inviteUrl);
|
|
|
|
|
|
|
|
let invite = localParticipantName
|
|
|
|
? t('info.inviteURLFirstPartPersonal', { name: localParticipantName })
|
2020-04-01 07:47:51 +00:00
|
|
|
: t('info.inviteURLFirstPartGeneral');
|
|
|
|
|
|
|
|
invite += t('info.inviteURLSecondPart', {
|
|
|
|
url: inviteURL
|
|
|
|
});
|
|
|
|
|
2021-02-24 09:37:14 +00:00
|
|
|
if (liveStreamViewURL) {
|
2020-04-01 07:47:51 +00:00
|
|
|
const liveStream = t('info.inviteLiveStream', {
|
2021-02-24 09:37:14 +00:00
|
|
|
url: liveStreamViewURL
|
2020-04-01 07:47:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
invite = `${invite}\n${liveStream}`;
|
|
|
|
}
|
|
|
|
|
2021-02-24 09:37:14 +00:00
|
|
|
if (shouldDisplayDialIn(dialIn)) {
|
2020-04-01 07:47:51 +00:00
|
|
|
const dial = t('info.invitePhone', {
|
|
|
|
number: phoneNumber,
|
2021-02-24 09:37:14 +00:00
|
|
|
conferenceID: dialIn.conferenceID
|
2020-04-01 07:47:51 +00:00
|
|
|
});
|
|
|
|
const moreNumbers = t('info.invitePhoneAlternatives', {
|
2021-02-24 09:37:14 +00:00
|
|
|
url: getDialInfoPageURL(state),
|
2020-04-01 07:47:51 +00:00
|
|
|
silentUrl: `${inviteURL}#config.startSilent=true`
|
|
|
|
});
|
|
|
|
|
|
|
|
invite = `${invite}\n${dial}\n${moreNumbers}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return invite;
|
|
|
|
}
|
|
|
|
|
2018-05-03 01:20:31 +00:00
|
|
|
/**
|
|
|
|
* Helper for determining how many of each type of user is being invited. Used
|
|
|
|
* for logging and sending analytics related to invites.
|
|
|
|
*
|
|
|
|
* @param {Array} inviteItems - An array with the invite items, as created in
|
|
|
|
* {@link _parseQueryResults}.
|
|
|
|
* @returns {Object} An object with keys as user types and values as the number
|
|
|
|
* of invites for that type.
|
|
|
|
*/
|
|
|
|
export function getInviteTypeCounts(inviteItems: Array<Object> = []) {
|
|
|
|
const inviteTypeCounts = {};
|
|
|
|
|
|
|
|
inviteItems.forEach(({ type }) => {
|
|
|
|
if (!inviteTypeCounts[type]) {
|
|
|
|
inviteTypeCounts[type] = 0;
|
|
|
|
}
|
|
|
|
inviteTypeCounts[type]++;
|
|
|
|
});
|
|
|
|
|
|
|
|
return inviteTypeCounts;
|
|
|
|
}
|
|
|
|
|
2018-05-01 04:43:47 +00:00
|
|
|
/**
|
|
|
|
* Sends a post request to an invite service.
|
|
|
|
*
|
|
|
|
* @param {string} inviteServiceUrl - The invite service that generates the
|
|
|
|
* invitation.
|
|
|
|
* @param {string} inviteUrl - The url to the conference.
|
|
|
|
* @param {string} jwt - The jwt token to pass to the search service.
|
2018-05-03 01:20:31 +00:00
|
|
|
* @param {Immutable.List} inviteItems - The list of the "user" or "room" type
|
|
|
|
* items to invite.
|
2018-05-01 04:43:47 +00:00
|
|
|
* @returns {Promise} - The promise created by the request.
|
|
|
|
*/
|
2018-04-25 11:06:46 +00:00
|
|
|
export function invitePeopleAndChatRooms( // eslint-disable-line max-params
|
2018-05-01 04:43:47 +00:00
|
|
|
inviteServiceUrl: string,
|
|
|
|
inviteUrl: string,
|
|
|
|
jwt: string,
|
|
|
|
inviteItems: Array<Object>
|
|
|
|
): Promise<void> {
|
|
|
|
|
|
|
|
if (!inviteItems || inviteItems.length === 0) {
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
2019-02-13 22:23:26 +00:00
|
|
|
return fetch(
|
|
|
|
`${inviteServiceUrl}?token=${jwt}`,
|
|
|
|
{
|
|
|
|
body: JSON.stringify({
|
|
|
|
'invited': inviteItems,
|
|
|
|
'url': inviteUrl
|
|
|
|
}),
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2018-05-01 04:43:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if adding people is currently enabled.
|
|
|
|
*
|
|
|
|
* @param {boolean} state - Current state.
|
|
|
|
* @returns {boolean} Indication of whether adding people is currently enabled.
|
|
|
|
*/
|
|
|
|
export function isAddPeopleEnabled(state: Object): boolean {
|
2019-04-29 20:09:50 +00:00
|
|
|
const { peopleSearchUrl } = state['features/base/config'];
|
2018-05-01 04:43:47 +00:00
|
|
|
|
2021-01-13 09:12:41 +00:00
|
|
|
return state['features/base/jwt'].jwt && Boolean(peopleSearchUrl) && !isVpaasMeeting(state);
|
2018-05-01 04:43:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if dial out is currently enabled or not.
|
|
|
|
*
|
|
|
|
* @param {boolean} state - Current state.
|
|
|
|
* @returns {boolean} Indication of whether dial out is currently enabled.
|
|
|
|
*/
|
|
|
|
export function isDialOutEnabled(state: Object): boolean {
|
|
|
|
const { conference } = state['features/base/conference'];
|
|
|
|
|
2019-01-18 10:56:18 +00:00
|
|
|
return isLocalParticipantModerator(state)
|
|
|
|
&& conference && conference.isSIPCallingSupported();
|
2018-05-01 04:43:47 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 00:49:22 +00:00
|
|
|
/**
|
|
|
|
* Checks whether a string looks like it could be for a phone number.
|
|
|
|
*
|
2018-05-03 01:20:31 +00:00
|
|
|
* @param {string} text - The text to check whether or not it could be a phone
|
2018-03-28 00:49:22 +00:00
|
|
|
* number.
|
2018-05-03 01:20:31 +00:00
|
|
|
* @private
|
|
|
|
* @returns {boolean} True if the string looks like it could be a phone number.
|
2018-03-28 00:49:22 +00:00
|
|
|
*/
|
|
|
|
function isMaybeAPhoneNumber(text: string): boolean {
|
|
|
|
if (!isPhoneNumberRegex().test(text)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const digits = getDigitsOnly(text);
|
|
|
|
|
|
|
|
return Boolean(digits.length);
|
|
|
|
}
|
|
|
|
|
2018-05-01 04:43:47 +00:00
|
|
|
/**
|
|
|
|
* RegExp to use to determine if some text might be a phone number.
|
|
|
|
*
|
|
|
|
* @returns {RegExp}
|
|
|
|
*/
|
|
|
|
function isPhoneNumberRegex(): RegExp {
|
|
|
|
let regexString = '^[0-9+()-\\s]*$';
|
|
|
|
|
|
|
|
if (typeof interfaceConfig !== 'undefined') {
|
|
|
|
regexString = interfaceConfig.PHONE_NUMBER_REGEX || regexString;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new RegExp(regexString);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends an ajax request to a directory service.
|
|
|
|
*
|
|
|
|
* @param {string} serviceUrl - The service to query.
|
|
|
|
* @param {string} jwt - The jwt token to pass to the search service.
|
|
|
|
* @param {string} text - Text to search.
|
|
|
|
* @param {Array<string>} queryTypes - Array with the query types that will be
|
|
|
|
* executed - "conferenceRooms" | "user" | "room".
|
|
|
|
* @returns {Promise} - The promise created by the request.
|
|
|
|
*/
|
|
|
|
export function searchDirectory( // eslint-disable-line max-params
|
|
|
|
serviceUrl: string,
|
|
|
|
jwt: string,
|
|
|
|
text: string,
|
|
|
|
queryTypes: Array<string> = [ 'conferenceRooms', 'user', 'room' ]
|
|
|
|
): Promise<Array<Object>> {
|
|
|
|
|
|
|
|
const query = encodeURIComponent(text);
|
|
|
|
const queryTypesString = encodeURIComponent(JSON.stringify(queryTypes));
|
|
|
|
|
|
|
|
return fetch(`${serviceUrl}?query=${query}&queryTypes=${
|
|
|
|
queryTypesString}&jwt=${jwt}`)
|
|
|
|
.then(response => {
|
|
|
|
const jsonify = response.json();
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
return jsonify;
|
|
|
|
}
|
|
|
|
|
|
|
|
return jsonify
|
|
|
|
.then(result => Promise.reject(result));
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
logger.error(
|
|
|
|
'Error searching directory:', error);
|
|
|
|
|
|
|
|
return Promise.reject(error);
|
|
|
|
});
|
|
|
|
}
|
2018-08-17 19:34:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns descriptive text that can be used to invite participants to a meeting
|
|
|
|
* (share via mobile or use it for calendar event description).
|
|
|
|
*
|
2018-09-07 22:48:58 +00:00
|
|
|
* @param {Object} state - The current state.
|
2018-08-17 19:34:41 +00:00
|
|
|
* @param {string} inviteUrl - The conference/location URL.
|
|
|
|
* @param {boolean} useHtml - Whether to return html text.
|
2018-09-07 22:48:58 +00:00
|
|
|
* @returns {Promise<string>} A {@code Promise} resolving with a
|
|
|
|
* descriptive text that can be used to invite participants to a meeting.
|
2018-08-17 19:34:41 +00:00
|
|
|
*/
|
|
|
|
export function getShareInfoText(
|
2018-09-07 22:48:58 +00:00
|
|
|
state: Object, inviteUrl: string, useHtml: ?boolean): Promise<string> {
|
2019-07-10 17:27:11 +00:00
|
|
|
let roomUrl = _decodeRoomURI(inviteUrl);
|
2018-09-07 22:48:58 +00:00
|
|
|
const includeDialInfo = state['features/base/config'] !== undefined;
|
2018-08-17 19:34:41 +00:00
|
|
|
|
|
|
|
if (useHtml) {
|
|
|
|
roomUrl = `<a href="${roomUrl}">${roomUrl}</a>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
let infoText = i18next.t('share.mainText', { roomUrl });
|
|
|
|
|
|
|
|
if (includeDialInfo) {
|
|
|
|
const { room } = parseURIString(inviteUrl);
|
2018-09-07 22:48:58 +00:00
|
|
|
let numbersPromise;
|
|
|
|
|
|
|
|
if (state['features/invite'].numbers
|
|
|
|
&& state['features/invite'].conferenceID) {
|
|
|
|
numbersPromise = Promise.resolve(state['features/invite']);
|
|
|
|
} else {
|
|
|
|
// we are requesting numbers and conferenceId directly
|
|
|
|
// not using updateDialInNumbers, because custom room
|
|
|
|
// is specified and we do not want to store the data
|
|
|
|
// in the state
|
|
|
|
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
|
2018-09-04 07:29:48 +00:00
|
|
|
return Promise.resolve(infoText);
|
2018-09-07 22:48:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
numbersPromise = Promise.all([
|
2019-02-02 03:10:34 +00:00
|
|
|
getDialInNumbers(dialInNumbersUrl, room, mucURL),
|
2018-09-07 22:48:58 +00:00
|
|
|
getDialInConferenceID(dialInConfCodeUrl, room, mucURL)
|
2019-02-26 13:32:46 +00:00
|
|
|
]).then(([ numbers, {
|
2018-09-07 22:48:58 +00:00
|
|
|
conference, id, message } ]) => {
|
2018-08-17 19:34:41 +00:00
|
|
|
|
2018-09-07 22:48:58 +00:00
|
|
|
if (!conference || !id) {
|
|
|
|
return Promise.reject(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
numbers,
|
|
|
|
conferenceID: id
|
|
|
|
};
|
|
|
|
});
|
2018-08-17 19:34:41 +00:00
|
|
|
}
|
|
|
|
|
2018-09-07 22:48:58 +00:00
|
|
|
return numbersPromise.then(
|
2019-02-26 13:32:46 +00:00
|
|
|
({ conferenceID, numbers }) => {
|
|
|
|
const phoneNumber = _getDefaultPhoneNumber(numbers) || '';
|
2018-09-07 22:48:58 +00:00
|
|
|
|
|
|
|
return `${
|
|
|
|
i18next.t('info.dialInNumber')} ${
|
|
|
|
phoneNumber} ${
|
|
|
|
i18next.t('info.dialInConferenceID')} ${
|
|
|
|
conferenceID}#\n\n`;
|
|
|
|
})
|
|
|
|
.catch(error =>
|
|
|
|
logger.error('Error fetching numbers or conferenceID', error))
|
|
|
|
.then(defaultDialInNumber => {
|
2021-02-24 09:37:14 +00:00
|
|
|
let dialInfoPageUrl = getDialInfoPageURL(state);
|
2018-09-07 22:48:58 +00:00
|
|
|
|
|
|
|
if (useHtml) {
|
|
|
|
dialInfoPageUrl
|
|
|
|
= `<a href="${dialInfoPageUrl}">${dialInfoPageUrl}</a>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
infoText += i18next.t('share.dialInfoText', {
|
|
|
|
defaultDialInNumber,
|
|
|
|
dialInfoPageUrl });
|
|
|
|
|
|
|
|
return infoText;
|
|
|
|
});
|
2018-08-17 19:34:41 +00:00
|
|
|
}
|
|
|
|
|
2018-09-07 22:48:58 +00:00
|
|
|
return Promise.resolve(infoText);
|
2018-08-17 19:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the URL for the static dial in info page.
|
|
|
|
*
|
2021-02-24 09:37:14 +00:00
|
|
|
* @param {Object} state - The state from the Redux store.
|
2018-08-17 19:34:41 +00:00
|
|
|
* @returns {string}
|
|
|
|
*/
|
2021-02-24 09:37:14 +00:00
|
|
|
export function getDialInfoPageURL(state: Object) {
|
|
|
|
const { didPageUrl } = state['features/dynamic-branding'];
|
|
|
|
const conferenceName = getRoomName(state);
|
|
|
|
const { locationURL } = state['features/base/connection'];
|
|
|
|
const { href } = locationURL;
|
|
|
|
const room = _decodeRoomURI(conferenceName);
|
2018-08-17 19:34:41 +00:00
|
|
|
|
2021-02-24 09:37:14 +00:00
|
|
|
const url = didPageUrl || `${href.substring(0, href.lastIndexOf('/'))}/static/dialInInfo.html`;
|
2018-08-17 19:34:41 +00:00
|
|
|
|
2021-02-24 09:37:14 +00:00
|
|
|
return `${url}?room=${room}`;
|
2018-08-17 19:34:41 +00:00
|
|
|
}
|
2018-09-07 22:48:58 +00:00
|
|
|
|
2019-05-07 14:50:57 +00:00
|
|
|
/**
|
|
|
|
* Generates the URL for the static dial in info page.
|
|
|
|
*
|
|
|
|
* @param {string} uri - The conference URI string.
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
export function getDialInfoPageURLForURIString(
|
|
|
|
uri: ?string) {
|
|
|
|
if (!uri) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
const { protocol, host, contextRoot, room } = parseURIString(uri);
|
|
|
|
|
|
|
|
return `${protocol}//${host}${contextRoot}static/dialInInfo.html?room=${room}`;
|
|
|
|
}
|
|
|
|
|
2020-02-05 18:10:57 +00:00
|
|
|
/**
|
|
|
|
* Returns whether or not dial-in related UI should be displayed.
|
|
|
|
*
|
|
|
|
* @param {Object} dialIn - Dial in information.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
export function shouldDisplayDialIn(dialIn: Object) {
|
|
|
|
const { conferenceID, numbers, numbersEnabled } = dialIn;
|
|
|
|
const phoneNumber = _getDefaultPhoneNumber(numbers);
|
|
|
|
|
|
|
|
return Boolean(
|
|
|
|
conferenceID
|
|
|
|
&& numbers
|
|
|
|
&& numbersEnabled
|
|
|
|
&& phoneNumber);
|
|
|
|
}
|
|
|
|
|
2021-03-03 14:45:26 +00:00
|
|
|
/**
|
|
|
|
* Returns if multiple dial-in numbers are available.
|
|
|
|
*
|
|
|
|
* @param {Array<string>|Object} dialInNumbers - The array or object of
|
|
|
|
* numbers to check.
|
|
|
|
* @private
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
export function hasMultipleNumbers(dialInNumbers: ?Object) {
|
|
|
|
if (!dialInNumbers) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Array.isArray(dialInNumbers)) {
|
|
|
|
return dialInNumbers.length > 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// deprecated and will be removed
|
|
|
|
const { numbers } = dialInNumbers;
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-confusing-arrow
|
|
|
|
return Boolean(numbers && Object.values(numbers).map(a => Array.isArray(a) ? a.length : 0)
|
|
|
|
.reduce((a, b) => a + b) > 1);
|
|
|
|
}
|
|
|
|
|
2018-09-07 22:48:58 +00:00
|
|
|
/**
|
|
|
|
* Sets the internal state of which dial-in number to display.
|
|
|
|
*
|
|
|
|
* @param {Array<string>|Object} dialInNumbers - The array or object of
|
|
|
|
* numbers to choose a number from.
|
|
|
|
* @private
|
|
|
|
* @returns {string|null}
|
|
|
|
*/
|
|
|
|
export function _getDefaultPhoneNumber(
|
2020-02-05 18:10:57 +00:00
|
|
|
dialInNumbers: ?Object): ?string {
|
|
|
|
|
|
|
|
if (!dialInNumbers) {
|
|
|
|
return null;
|
|
|
|
}
|
2019-02-26 13:32:46 +00:00
|
|
|
|
2018-09-07 22:48:58 +00:00
|
|
|
if (Array.isArray(dialInNumbers)) {
|
2019-02-26 13:32:46 +00:00
|
|
|
// new syntax follows
|
|
|
|
// find the default country inside dialInNumbers, US one
|
|
|
|
// or return the first one
|
2019-05-03 09:50:58 +00:00
|
|
|
const defaultNumber = dialInNumbers.find(number => number.default);
|
2019-02-26 13:32:46 +00:00
|
|
|
|
|
|
|
if (defaultNumber) {
|
|
|
|
return defaultNumber.formattedNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dialInNumbers.length > 0
|
|
|
|
? dialInNumbers[0].formattedNumber : null;
|
|
|
|
}
|
|
|
|
|
2019-05-03 09:50:58 +00:00
|
|
|
const { numbers } = dialInNumbers;
|
2019-02-26 13:32:46 +00:00
|
|
|
|
|
|
|
if (numbers && Object.keys(numbers).length > 0) {
|
|
|
|
// deprecated and will be removed
|
|
|
|
const firstRegion = Object.keys(numbers)[0];
|
2018-09-07 22:48:58 +00:00
|
|
|
|
2019-02-26 13:32:46 +00:00
|
|
|
return firstRegion && numbers[firstRegion][0];
|
2018-09-07 22:48:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2019-07-10 17:27:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Decodes URI only if doesn't contain a space(' ').
|
|
|
|
*
|
|
|
|
* @param {string} url - The string to decode.
|
|
|
|
* @returns {string} - It the string contains space, encoded value is '%20' returns
|
|
|
|
* same string, otherwise decoded one.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
export function _decodeRoomURI(url: string) {
|
|
|
|
let roomUrl = url;
|
|
|
|
|
|
|
|
// we want to decode urls when the do not contain space, ' ', which url encoded is %20
|
|
|
|
if (roomUrl && !roomUrl.includes('%20')) {
|
|
|
|
roomUrl = decodeURI(roomUrl);
|
|
|
|
}
|
|
|
|
|
2019-10-14 15:16:10 +00:00
|
|
|
// Handles a special case where the room name has % encoded, the decoded will have
|
|
|
|
// % followed by a char (non-digit) which is not a valid URL and room name ... so we do not
|
|
|
|
// want to show this decoded
|
|
|
|
if (roomUrl.match(/.*%[^\d].*/)) {
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2019-07-10 17:27:11 +00:00
|
|
|
return roomUrl;
|
|
|
|
}
|
2020-05-14 12:30:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the stored conference id.
|
|
|
|
*
|
|
|
|
* @param {Object | Function} stateful - The Object or Function that can be
|
|
|
|
* resolved to a Redux state object with the toState function.
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
export function getConferenceId(stateful: Object | Function) {
|
|
|
|
return toState(stateful)['features/invite'].conferenceID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the default dial in number from the store.
|
|
|
|
*
|
|
|
|
* @param {Object | Function} stateful - The Object or Function that can be
|
|
|
|
* resolved to a Redux state object with the toState function.
|
|
|
|
* @returns {string | null}
|
|
|
|
*/
|
|
|
|
export function getDefaultDialInNumber(stateful: Object | Function) {
|
|
|
|
return _getDefaultPhoneNumber(toState(stateful)['features/invite'].numbers);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes the dial out request.
|
|
|
|
*
|
|
|
|
* @param {string} url - The url for dialing out.
|
|
|
|
* @param {Object} body - The body of the request.
|
|
|
|
* @param {string} reqId - The unique request id.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
export async function executeDialOutRequest(url: string, body: Object, reqId: string) {
|
|
|
|
const res = await fetch(url, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
'request-id': reqId
|
|
|
|
},
|
|
|
|
body: JSON.stringify(body)
|
|
|
|
});
|
|
|
|
|
|
|
|
const json = await res.json();
|
|
|
|
|
|
|
|
return res.ok ? json : Promise.reject(json);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes the dial out status request.
|
|
|
|
*
|
|
|
|
* @param {string} url - The url for dialing out.
|
|
|
|
* @param {string} reqId - The unique request id used on the dial out request.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
export async function executeDialOutStatusRequest(url: string, reqId: string) {
|
|
|
|
const res = await fetch(url, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
'request-id': reqId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const json = await res.json();
|
|
|
|
|
|
|
|
return res.ok ? json : Promise.reject(json);
|
|
|
|
}
|
2021-02-27 01:50:26 +00:00
|
|
|
|
|
|
|
export const sharingFeatures = {
|
|
|
|
email: 'email',
|
|
|
|
url: 'url',
|
|
|
|
dialIn: 'dial-in',
|
|
|
|
embed: 'embed'
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if a specific sharing feature is enabled in interface configuration.
|
|
|
|
*
|
|
|
|
* @param {string} sharingFeature - The sharing feature to check.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
export function isSharingEnabled(sharingFeature: string) {
|
|
|
|
return typeof interfaceConfig === 'undefined'
|
|
|
|
|| typeof interfaceConfig.SHARING_FEATURES === 'undefined'
|
|
|
|
|| (interfaceConfig.SHARING_FEATURES.length && interfaceConfig.SHARING_FEATURES.indexOf(sharingFeature) > -1);
|
|
|
|
}
|