You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.js 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. // @flow
  2. import { getActiveSession } from '../../features/recording/functions';
  3. import { getRoomName } from '../base/conference';
  4. import { getInviteURL } from '../base/connection';
  5. import { i18next } from '../base/i18n';
  6. import { JitsiRecordingConstants } from '../base/lib-jitsi-meet';
  7. import { getLocalParticipant, isLocalParticipantModerator } from '../base/participants';
  8. import { toState } from '../base/redux';
  9. import { doGetJSON, parseURIString } from '../base/util';
  10. import { isVpaasMeeting } from '../billing-counter/functions';
  11. import logger from './logger';
  12. declare var $: Function;
  13. declare var interfaceConfig: Object;
  14. /**
  15. * Sends an ajax request to check if the phone number can be called.
  16. *
  17. * @param {string} dialNumber - The dial number to check for validity.
  18. * @param {string} dialOutAuthUrl - The endpoint to use for checking validity.
  19. * @returns {Promise} - The promise created by the request.
  20. */
  21. export function checkDialNumber(
  22. dialNumber: string,
  23. dialOutAuthUrl: string
  24. ): Promise<Object> {
  25. const fullUrl = `${dialOutAuthUrl}?phone=${dialNumber}`;
  26. return new Promise((resolve, reject) => {
  27. $.getJSON(fullUrl)
  28. .then(resolve)
  29. .catch(reject);
  30. });
  31. }
  32. /**
  33. * Sends a GET request to obtain the conference ID necessary for identifying
  34. * which conference to join after diaing the dial-in service.
  35. *
  36. * @param {string} baseUrl - The url for obtaining the conference ID (pin) for
  37. * dialing into a conference.
  38. * @param {string} roomName - The conference name to find the associated
  39. * conference ID.
  40. * @param {string} mucURL - In which MUC the conference exists.
  41. * @returns {Promise} - The promise created by the request.
  42. */
  43. export function getDialInConferenceID(
  44. baseUrl: string,
  45. roomName: string,
  46. mucURL: string
  47. ): Promise<Object> {
  48. const conferenceIDURL = `${baseUrl}?conference=${roomName}@${mucURL}`;
  49. return doGetJSON(conferenceIDURL, true);
  50. }
  51. /**
  52. * Sends a GET request for phone numbers used to dial into a conference.
  53. *
  54. * @param {string} url - The service that returns conference dial-in numbers.
  55. * @param {string} roomName - The conference name to find the associated
  56. * conference ID.
  57. * @param {string} mucURL - In which MUC the conference exists.
  58. * @returns {Promise} - The promise created by the request. The returned numbers
  59. * may be an array of Objects containing numbers, with keys countryCode,
  60. * tollFree, formattedNumber or an object with countries as keys and arrays of
  61. * phone number strings, as the second one should not be used and is deprecated.
  62. */
  63. export function getDialInNumbers(
  64. url: string,
  65. roomName: string,
  66. mucURL: string
  67. ): Promise<*> {
  68. const fullUrl = `${url}?conference=${roomName}@${mucURL}`;
  69. return doGetJSON(fullUrl, true);
  70. }
  71. /**
  72. * Removes all non-numeric characters from a string.
  73. *
  74. * @param {string} text - The string from which to remove all characters except
  75. * numbers.
  76. * @returns {string} A string with only numbers.
  77. */
  78. export function getDigitsOnly(text: string = ''): string {
  79. return text.replace(/\D/g, '');
  80. }
  81. /**
  82. * Type of the options to use when sending a search query.
  83. */
  84. export type GetInviteResultsOptions = {
  85. /**
  86. * The endpoint to use for checking phone number validity.
  87. */
  88. dialOutAuthUrl: string,
  89. /**
  90. * Whether or not to search for people.
  91. */
  92. addPeopleEnabled: boolean,
  93. /**
  94. * Whether or not to check phone numbers.
  95. */
  96. dialOutEnabled: boolean,
  97. /**
  98. * Array with the query types that will be executed -
  99. * "conferenceRooms" | "user" | "room".
  100. */
  101. peopleSearchQueryTypes: Array<string>,
  102. /**
  103. * The url to query for people.
  104. */
  105. peopleSearchUrl: string,
  106. /**
  107. * The jwt token to pass to the search service.
  108. */
  109. jwt: string
  110. };
  111. /**
  112. * Combines directory search with phone number validation to produce a single
  113. * set of invite search results.
  114. *
  115. * @param {string} query - Text to search.
  116. * @param {GetInviteResultsOptions} options - Options to use when searching.
  117. * @returns {Promise<*>}
  118. */
  119. export function getInviteResultsForQuery(
  120. query: string,
  121. options: GetInviteResultsOptions
  122. ): Promise<*> {
  123. const text = query.trim();
  124. const {
  125. dialOutAuthUrl,
  126. addPeopleEnabled,
  127. dialOutEnabled,
  128. peopleSearchQueryTypes,
  129. peopleSearchUrl,
  130. jwt
  131. } = options;
  132. let peopleSearchPromise;
  133. if (addPeopleEnabled && text) {
  134. peopleSearchPromise = searchDirectory(
  135. peopleSearchUrl,
  136. jwt,
  137. text,
  138. peopleSearchQueryTypes);
  139. } else {
  140. peopleSearchPromise = Promise.resolve([]);
  141. }
  142. let hasCountryCode = text.startsWith('+');
  143. let phoneNumberPromise;
  144. // Phone numbers are handled a specially to enable both cases of restricting
  145. // numbers to telephone number-y numbers and accepting any arbitrary string,
  146. // which may be valid for SIP (jigasi) calls. If the dialOutAuthUrl is
  147. // defined, then it is assumed the call is to a telephone number and
  148. // some validation of the number is completed, with the + sign used as a way
  149. // for the UI to detect and enforce the usage of a country code. If the
  150. // dialOutAuthUrl is not defined, accept anything because this is assumed
  151. // to be the SIP (jigasi) case.
  152. if (dialOutEnabled && dialOutAuthUrl && isMaybeAPhoneNumber(text)) {
  153. let numberToVerify = text;
  154. // When the number to verify does not start with a +, we assume no
  155. // proper country code has been entered. In such a case, prepend 1 for
  156. // the country code. The service currently takes care of prepending the
  157. // +.
  158. if (!hasCountryCode && !text.startsWith('1')) {
  159. numberToVerify = `1${numberToVerify}`;
  160. }
  161. // The validation service works properly when the query is digits only
  162. // so ensure only digits get sent.
  163. numberToVerify = getDigitsOnly(numberToVerify);
  164. phoneNumberPromise = checkDialNumber(numberToVerify, dialOutAuthUrl);
  165. } else if (dialOutEnabled && !dialOutAuthUrl) {
  166. // fake having a country code to hide the country code reminder
  167. hasCountryCode = true;
  168. // With no auth url, let's say the text is a valid number
  169. phoneNumberPromise = Promise.resolve({
  170. allow: true,
  171. country: '',
  172. phone: text
  173. });
  174. } else {
  175. phoneNumberPromise = Promise.resolve({});
  176. }
  177. return Promise.all([ peopleSearchPromise, phoneNumberPromise ])
  178. .then(([ peopleResults, phoneResults ]) => {
  179. const results = [
  180. ...peopleResults
  181. ];
  182. /**
  183. * This check for phone results is for the day the call to searching
  184. * people might return phone results as well. When that day comes
  185. * this check will make it so the server checks are honored and the
  186. * local appending of the number is not done. The local appending of
  187. * the phone number can then be cleaned up when convenient.
  188. */
  189. const hasPhoneResult
  190. = peopleResults.find(result => result.type === 'phone');
  191. if (!hasPhoneResult && typeof phoneResults.allow === 'boolean') {
  192. results.push({
  193. allowed: phoneResults.allow,
  194. country: phoneResults.country,
  195. type: 'phone',
  196. number: phoneResults.phone,
  197. originalEntry: text,
  198. showCountryCodeReminder: !hasCountryCode
  199. });
  200. }
  201. return results;
  202. });
  203. }
  204. /**
  205. * Creates a message describing how to dial in to the conference.
  206. *
  207. * @returns {string}
  208. */
  209. export function getInviteText({
  210. state,
  211. phoneNumber,
  212. t
  213. }: Object) {
  214. const dialIn = state['features/invite'];
  215. const inviteUrl = getInviteURL(state);
  216. const currentLiveStreamingSession = getActiveSession(state, JitsiRecordingConstants.mode.STREAM);
  217. const liveStreamViewURL
  218. = currentLiveStreamingSession
  219. && currentLiveStreamingSession.liveStreamViewURL;
  220. const localParticipant = getLocalParticipant(state);
  221. const localParticipantName = localParticipant?.name;
  222. const inviteURL = _decodeRoomURI(inviteUrl);
  223. let invite = localParticipantName
  224. ? t('info.inviteURLFirstPartPersonal', { name: localParticipantName })
  225. : t('info.inviteURLFirstPartGeneral');
  226. invite += t('info.inviteURLSecondPart', {
  227. url: inviteURL
  228. });
  229. if (liveStreamViewURL) {
  230. const liveStream = t('info.inviteLiveStream', {
  231. url: liveStreamViewURL
  232. });
  233. invite = `${invite}\n${liveStream}`;
  234. }
  235. if (shouldDisplayDialIn(dialIn)) {
  236. const dial = t('info.invitePhone', {
  237. number: phoneNumber,
  238. conferenceID: dialIn.conferenceID
  239. });
  240. const moreNumbers = t('info.invitePhoneAlternatives', {
  241. url: getDialInfoPageURL(state),
  242. silentUrl: `${inviteURL}#config.startSilent=true`
  243. });
  244. invite = `${invite}\n${dial}\n${moreNumbers}`;
  245. }
  246. return invite;
  247. }
  248. /**
  249. * Helper for determining how many of each type of user is being invited. Used
  250. * for logging and sending analytics related to invites.
  251. *
  252. * @param {Array} inviteItems - An array with the invite items, as created in
  253. * {@link _parseQueryResults}.
  254. * @returns {Object} An object with keys as user types and values as the number
  255. * of invites for that type.
  256. */
  257. export function getInviteTypeCounts(inviteItems: Array<Object> = []) {
  258. const inviteTypeCounts = {};
  259. inviteItems.forEach(({ type }) => {
  260. if (!inviteTypeCounts[type]) {
  261. inviteTypeCounts[type] = 0;
  262. }
  263. inviteTypeCounts[type]++;
  264. });
  265. return inviteTypeCounts;
  266. }
  267. /**
  268. * Sends a post request to an invite service.
  269. *
  270. * @param {string} inviteServiceUrl - The invite service that generates the
  271. * invitation.
  272. * @param {string} inviteUrl - The url to the conference.
  273. * @param {string} jwt - The jwt token to pass to the search service.
  274. * @param {Immutable.List} inviteItems - The list of the "user" or "room" type
  275. * items to invite.
  276. * @returns {Promise} - The promise created by the request.
  277. */
  278. export function invitePeopleAndChatRooms( // eslint-disable-line max-params
  279. inviteServiceUrl: string,
  280. inviteUrl: string,
  281. jwt: string,
  282. inviteItems: Array<Object>
  283. ): Promise<void> {
  284. if (!inviteItems || inviteItems.length === 0) {
  285. return Promise.resolve();
  286. }
  287. return fetch(
  288. `${inviteServiceUrl}?token=${jwt}`,
  289. {
  290. body: JSON.stringify({
  291. 'invited': inviteItems,
  292. 'url': inviteUrl
  293. }),
  294. method: 'POST',
  295. headers: {
  296. 'Content-Type': 'application/json'
  297. }
  298. }
  299. );
  300. }
  301. /**
  302. * Determines if adding people is currently enabled.
  303. *
  304. * @param {boolean} state - Current state.
  305. * @returns {boolean} Indication of whether adding people is currently enabled.
  306. */
  307. export function isAddPeopleEnabled(state: Object): boolean {
  308. const { peopleSearchUrl } = state['features/base/config'];
  309. return state['features/base/jwt'].jwt && Boolean(peopleSearchUrl) && !isVpaasMeeting(state);
  310. }
  311. /**
  312. * Determines if dial out is currently enabled or not.
  313. *
  314. * @param {boolean} state - Current state.
  315. * @returns {boolean} Indication of whether dial out is currently enabled.
  316. */
  317. export function isDialOutEnabled(state: Object): boolean {
  318. const { conference } = state['features/base/conference'];
  319. return isLocalParticipantModerator(state)
  320. && conference && conference.isSIPCallingSupported();
  321. }
  322. /**
  323. * Checks whether a string looks like it could be for a phone number.
  324. *
  325. * @param {string} text - The text to check whether or not it could be a phone
  326. * number.
  327. * @private
  328. * @returns {boolean} True if the string looks like it could be a phone number.
  329. */
  330. function isMaybeAPhoneNumber(text: string): boolean {
  331. if (!isPhoneNumberRegex().test(text)) {
  332. return false;
  333. }
  334. const digits = getDigitsOnly(text);
  335. return Boolean(digits.length);
  336. }
  337. /**
  338. * RegExp to use to determine if some text might be a phone number.
  339. *
  340. * @returns {RegExp}
  341. */
  342. function isPhoneNumberRegex(): RegExp {
  343. let regexString = '^[0-9+()-\\s]*$';
  344. if (typeof interfaceConfig !== 'undefined') {
  345. regexString = interfaceConfig.PHONE_NUMBER_REGEX || regexString;
  346. }
  347. return new RegExp(regexString);
  348. }
  349. /**
  350. * Sends an ajax request to a directory service.
  351. *
  352. * @param {string} serviceUrl - The service to query.
  353. * @param {string} jwt - The jwt token to pass to the search service.
  354. * @param {string} text - Text to search.
  355. * @param {Array<string>} queryTypes - Array with the query types that will be
  356. * executed - "conferenceRooms" | "user" | "room".
  357. * @returns {Promise} - The promise created by the request.
  358. */
  359. export function searchDirectory( // eslint-disable-line max-params
  360. serviceUrl: string,
  361. jwt: string,
  362. text: string,
  363. queryTypes: Array<string> = [ 'conferenceRooms', 'user', 'room' ]
  364. ): Promise<Array<Object>> {
  365. const query = encodeURIComponent(text);
  366. const queryTypesString = encodeURIComponent(JSON.stringify(queryTypes));
  367. return fetch(`${serviceUrl}?query=${query}&queryTypes=${
  368. queryTypesString}&jwt=${jwt}`)
  369. .then(response => {
  370. const jsonify = response.json();
  371. if (response.ok) {
  372. return jsonify;
  373. }
  374. return jsonify
  375. .then(result => Promise.reject(result));
  376. })
  377. .catch(error => {
  378. logger.error(
  379. 'Error searching directory:', error);
  380. return Promise.reject(error);
  381. });
  382. }
  383. /**
  384. * Returns descriptive text that can be used to invite participants to a meeting
  385. * (share via mobile or use it for calendar event description).
  386. *
  387. * @param {Object} state - The current state.
  388. * @param {string} inviteUrl - The conference/location URL.
  389. * @param {boolean} useHtml - Whether to return html text.
  390. * @returns {Promise<string>} A {@code Promise} resolving with a
  391. * descriptive text that can be used to invite participants to a meeting.
  392. */
  393. export function getShareInfoText(
  394. state: Object, inviteUrl: string, useHtml: ?boolean): Promise<string> {
  395. let roomUrl = _decodeRoomURI(inviteUrl);
  396. const includeDialInfo = state['features/base/config'] !== undefined;
  397. if (useHtml) {
  398. roomUrl = `<a href="${roomUrl}">${roomUrl}</a>`;
  399. }
  400. let infoText = i18next.t('share.mainText', { roomUrl });
  401. if (includeDialInfo) {
  402. const { room } = parseURIString(inviteUrl);
  403. let numbersPromise;
  404. if (state['features/invite'].numbers
  405. && state['features/invite'].conferenceID) {
  406. numbersPromise = Promise.resolve(state['features/invite']);
  407. } else {
  408. // we are requesting numbers and conferenceId directly
  409. // not using updateDialInNumbers, because custom room
  410. // is specified and we do not want to store the data
  411. // in the state
  412. const { dialInConfCodeUrl, dialInNumbersUrl, hosts }
  413. = state['features/base/config'];
  414. const mucURL = hosts && hosts.muc;
  415. if (!dialInConfCodeUrl || !dialInNumbersUrl || !mucURL) {
  416. // URLs for fetching dial in numbers not defined
  417. return Promise.resolve(infoText);
  418. }
  419. numbersPromise = Promise.all([
  420. getDialInNumbers(dialInNumbersUrl, room, mucURL),
  421. getDialInConferenceID(dialInConfCodeUrl, room, mucURL)
  422. ]).then(([ numbers, {
  423. conference, id, message } ]) => {
  424. if (!conference || !id) {
  425. return Promise.reject(message);
  426. }
  427. return {
  428. numbers,
  429. conferenceID: id
  430. };
  431. });
  432. }
  433. return numbersPromise.then(
  434. ({ conferenceID, numbers }) => {
  435. const phoneNumber = _getDefaultPhoneNumber(numbers) || '';
  436. return `${
  437. i18next.t('info.dialInNumber')} ${
  438. phoneNumber} ${
  439. i18next.t('info.dialInConferenceID')} ${
  440. conferenceID}#\n\n`;
  441. })
  442. .catch(error =>
  443. logger.error('Error fetching numbers or conferenceID', error))
  444. .then(defaultDialInNumber => {
  445. let dialInfoPageUrl = getDialInfoPageURL(state);
  446. if (useHtml) {
  447. dialInfoPageUrl
  448. = `<a href="${dialInfoPageUrl}">${dialInfoPageUrl}</a>`;
  449. }
  450. infoText += i18next.t('share.dialInfoText', {
  451. defaultDialInNumber,
  452. dialInfoPageUrl });
  453. return infoText;
  454. });
  455. }
  456. return Promise.resolve(infoText);
  457. }
  458. /**
  459. * Generates the URL for the static dial in info page.
  460. *
  461. * @param {Object} state - The state from the Redux store.
  462. * @returns {string}
  463. */
  464. export function getDialInfoPageURL(state: Object) {
  465. const { didPageUrl } = state['features/dynamic-branding'];
  466. const conferenceName = getRoomName(state);
  467. const { locationURL } = state['features/base/connection'];
  468. const { href } = locationURL;
  469. const room = _decodeRoomURI(conferenceName);
  470. const url = didPageUrl || `${href.substring(0, href.lastIndexOf('/'))}/static/dialInInfo.html`;
  471. return `${url}?room=${room}`;
  472. }
  473. /**
  474. * Generates the URL for the static dial in info page.
  475. *
  476. * @param {string} uri - The conference URI string.
  477. * @returns {string}
  478. */
  479. export function getDialInfoPageURLForURIString(
  480. uri: ?string) {
  481. if (!uri) {
  482. return undefined;
  483. }
  484. const { protocol, host, contextRoot, room } = parseURIString(uri);
  485. return `${protocol}//${host}${contextRoot}static/dialInInfo.html?room=${room}`;
  486. }
  487. /**
  488. * Returns whether or not dial-in related UI should be displayed.
  489. *
  490. * @param {Object} dialIn - Dial in information.
  491. * @returns {boolean}
  492. */
  493. export function shouldDisplayDialIn(dialIn: Object) {
  494. const { conferenceID, numbers, numbersEnabled } = dialIn;
  495. const phoneNumber = _getDefaultPhoneNumber(numbers);
  496. return Boolean(
  497. conferenceID
  498. && numbers
  499. && numbersEnabled
  500. && phoneNumber);
  501. }
  502. /**
  503. * Returns if multiple dial-in numbers are available.
  504. *
  505. * @param {Array<string>|Object} dialInNumbers - The array or object of
  506. * numbers to check.
  507. * @private
  508. * @returns {boolean}
  509. */
  510. export function hasMultipleNumbers(dialInNumbers: ?Object) {
  511. if (!dialInNumbers) {
  512. return false;
  513. }
  514. if (Array.isArray(dialInNumbers)) {
  515. return dialInNumbers.length > 1;
  516. }
  517. // deprecated and will be removed
  518. const { numbers } = dialInNumbers;
  519. // eslint-disable-next-line no-confusing-arrow
  520. return Boolean(numbers && Object.values(numbers).map(a => Array.isArray(a) ? a.length : 0)
  521. .reduce((a, b) => a + b) > 1);
  522. }
  523. /**
  524. * Sets the internal state of which dial-in number to display.
  525. *
  526. * @param {Array<string>|Object} dialInNumbers - The array or object of
  527. * numbers to choose a number from.
  528. * @private
  529. * @returns {string|null}
  530. */
  531. export function _getDefaultPhoneNumber(
  532. dialInNumbers: ?Object): ?string {
  533. if (!dialInNumbers) {
  534. return null;
  535. }
  536. if (Array.isArray(dialInNumbers)) {
  537. // new syntax follows
  538. // find the default country inside dialInNumbers, US one
  539. // or return the first one
  540. const defaultNumber = dialInNumbers.find(number => number.default);
  541. if (defaultNumber) {
  542. return defaultNumber.formattedNumber;
  543. }
  544. return dialInNumbers.length > 0
  545. ? dialInNumbers[0].formattedNumber : null;
  546. }
  547. const { numbers } = dialInNumbers;
  548. if (numbers && Object.keys(numbers).length > 0) {
  549. // deprecated and will be removed
  550. const firstRegion = Object.keys(numbers)[0];
  551. return firstRegion && numbers[firstRegion][0];
  552. }
  553. return null;
  554. }
  555. /**
  556. * Decodes URI only if doesn't contain a space(' ').
  557. *
  558. * @param {string} url - The string to decode.
  559. * @returns {string} - It the string contains space, encoded value is '%20' returns
  560. * same string, otherwise decoded one.
  561. * @private
  562. */
  563. export function _decodeRoomURI(url: string) {
  564. let roomUrl = url;
  565. // we want to decode urls when the do not contain space, ' ', which url encoded is %20
  566. if (roomUrl && !roomUrl.includes('%20')) {
  567. roomUrl = decodeURI(roomUrl);
  568. }
  569. // Handles a special case where the room name has % encoded, the decoded will have
  570. // % followed by a char (non-digit) which is not a valid URL and room name ... so we do not
  571. // want to show this decoded
  572. if (roomUrl.match(/.*%[^\d].*/)) {
  573. return url;
  574. }
  575. return roomUrl;
  576. }
  577. /**
  578. * Returns the stored conference id.
  579. *
  580. * @param {Object | Function} stateful - The Object or Function that can be
  581. * resolved to a Redux state object with the toState function.
  582. * @returns {string}
  583. */
  584. export function getConferenceId(stateful: Object | Function) {
  585. return toState(stateful)['features/invite'].conferenceID;
  586. }
  587. /**
  588. * Returns the default dial in number from the store.
  589. *
  590. * @param {Object | Function} stateful - The Object or Function that can be
  591. * resolved to a Redux state object with the toState function.
  592. * @returns {string | null}
  593. */
  594. export function getDefaultDialInNumber(stateful: Object | Function) {
  595. return _getDefaultPhoneNumber(toState(stateful)['features/invite'].numbers);
  596. }
  597. /**
  598. * Executes the dial out request.
  599. *
  600. * @param {string} url - The url for dialing out.
  601. * @param {Object} body - The body of the request.
  602. * @param {string} reqId - The unique request id.
  603. * @returns {Object}
  604. */
  605. export async function executeDialOutRequest(url: string, body: Object, reqId: string) {
  606. const res = await fetch(url, {
  607. method: 'POST',
  608. headers: {
  609. 'Content-Type': 'application/json',
  610. 'request-id': reqId
  611. },
  612. body: JSON.stringify(body)
  613. });
  614. const json = await res.json();
  615. return res.ok ? json : Promise.reject(json);
  616. }
  617. /**
  618. * Executes the dial out status request.
  619. *
  620. * @param {string} url - The url for dialing out.
  621. * @param {string} reqId - The unique request id used on the dial out request.
  622. * @returns {Object}
  623. */
  624. export async function executeDialOutStatusRequest(url: string, reqId: string) {
  625. const res = await fetch(url, {
  626. method: 'GET',
  627. headers: {
  628. 'Content-Type': 'application/json',
  629. 'request-id': reqId
  630. }
  631. });
  632. const json = await res.json();
  633. return res.ok ? json : Promise.reject(json);
  634. }
  635. export const sharingFeatures = {
  636. email: 'email',
  637. url: 'url',
  638. dialIn: 'dial-in',
  639. embed: 'embed'
  640. };
  641. /**
  642. * Returns true if a specific sharing feature is enabled in interface configuration.
  643. *
  644. * @param {string} sharingFeature - The sharing feature to check.
  645. * @returns {boolean}
  646. */
  647. export function isSharingEnabled(sharingFeature: string) {
  648. return typeof interfaceConfig === 'undefined'
  649. || typeof interfaceConfig.SHARING_FEATURES === 'undefined'
  650. || (interfaceConfig.SHARING_FEATURES.length && interfaceConfig.SHARING_FEATURES.indexOf(sharingFeature) > -1);
  651. }