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.

DialInInfoPage.web.js 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /* global config */
  2. import PropTypes from 'prop-types';
  3. import React, { Component } from 'react';
  4. import { translate } from '../../../base/i18n';
  5. import ConferenceID from './ConferenceID';
  6. import NumbersList from './NumbersList';
  7. /**
  8. * Displays a page listing numbers for dialing into a conference and pin to
  9. * the a specific conference.
  10. *
  11. * @extends Component
  12. */
  13. class DialInInfoPage extends Component {
  14. /**
  15. * {@code DialInInfoPage} component's property types.
  16. *
  17. * @static
  18. */
  19. static propTypes = {
  20. /**
  21. * The name of the conference to show a conferenceID for.
  22. */
  23. room: PropTypes.string,
  24. /**
  25. * Invoked to obtain translated strings.
  26. */
  27. t: PropTypes.func
  28. };
  29. /**
  30. * {@code DialInInfoPage} component's local state.
  31. *
  32. * @type {Object}
  33. * @property {number} conferenceID - The numeric ID of the conference, used
  34. * as a pin when dialing in.
  35. * @property {string} error - An error message to display.
  36. * @property {boolean} loading - Whether or not the app is fetching data.
  37. * @property {Array|Object} numbers - The dial-in numbers.
  38. * entered by the local participant.
  39. * @property {boolean} numbersEnabled - Whether or not dial-in is allowed.
  40. */
  41. state = {
  42. conferenceID: null,
  43. error: '',
  44. loading: true,
  45. numbers: null,
  46. numbersEnabled: null
  47. };
  48. /**
  49. * Initializes a new {@code DialInInfoPage} instance.
  50. *
  51. * @param {Object} props - The read-only properties with which the new
  52. * instance is to be initialized.
  53. */
  54. constructor(props) {
  55. super(props);
  56. // Bind event handlers so they are only bound once for every instance.
  57. this._onGetNumbersSuccess = this._onGetNumbersSuccess.bind(this);
  58. this._onGetConferenceIDSuccess
  59. = this._onGetConferenceIDSuccess.bind(this);
  60. this._setErrorMessage = this._setErrorMessage.bind(this);
  61. }
  62. /**
  63. * Implements {@link Component#componentDidMount()}. Invoked immediately
  64. * after this component is mounted.
  65. *
  66. * @inheritdoc
  67. * @returns {void}
  68. */
  69. componentDidMount() {
  70. const getNumbers = this._getNumbers()
  71. .then(this._onGetNumbersSuccess)
  72. .catch(this._setErrorMessage);
  73. const getID = this._getConferenceID()
  74. .then(this._onGetConferenceIDSuccess)
  75. .catch(this._setErrorMessage);
  76. Promise.all([ getNumbers, getID ])
  77. .then(() => {
  78. this.setState({ loading: false });
  79. });
  80. }
  81. /**
  82. * Implements React's {@link Component#render()}.
  83. *
  84. * @inheritdoc
  85. * @returns {ReactElement}
  86. */
  87. render() {
  88. let contents;
  89. const { conferenceID, error, loading, numbersEnabled } = this.state;
  90. if (loading) {
  91. contents = '';
  92. } else if (numbersEnabled === false) {
  93. contents = this.props.t('info.dialInNotSupported');
  94. } else if (error) {
  95. contents = error;
  96. } else {
  97. contents = [
  98. conferenceID
  99. ? <ConferenceID
  100. conferenceID = { conferenceID }
  101. key = 'conferenceID' />
  102. : null,
  103. <NumbersList
  104. key = 'numbers'
  105. numbers = { this.state.numbers } />
  106. ];
  107. }
  108. return (
  109. <div className = 'dial-in-page'>
  110. { contents }
  111. </div>
  112. );
  113. }
  114. /**
  115. * Creates an AJAX request for the conference ID.
  116. *
  117. * @private
  118. * @returns {Promise}
  119. */
  120. _getConferenceID() {
  121. const { room } = this.props;
  122. const { dialInConfCodeUrl, hosts } = config;
  123. const mucURL = hosts && hosts.muc;
  124. if (!dialInConfCodeUrl || !mucURL || !room) {
  125. return Promise.resolve();
  126. }
  127. const conferenceIDURL
  128. = `${dialInConfCodeUrl}?conference=${room}@${mucURL}`;
  129. return fetch(conferenceIDURL)
  130. .then(response => response.json())
  131. .catch(() => Promise.reject(this.props.t('info.genericError')));
  132. }
  133. /**
  134. * Creates an AJAX request for dial-in numbers.
  135. *
  136. * @private
  137. * @returns {Promise}
  138. */
  139. _getNumbers() {
  140. const { dialInNumbersUrl } = config;
  141. if (!dialInNumbersUrl) {
  142. return Promise.reject(this.props.t('info.dialInNotSupported'));
  143. }
  144. return fetch(dialInNumbersUrl)
  145. .then(response => response.json())
  146. .catch(() => Promise.reject(this.props.t('info.genericError')));
  147. }
  148. /**
  149. * Callback invoked when fetching the conference ID succeeds.
  150. *
  151. * @param {Object} response - The response from fetching the conference ID.
  152. * @private
  153. * @returns {void}
  154. */
  155. _onGetConferenceIDSuccess(response = {}) {
  156. const { conference, id } = response;
  157. if (!conference || !id) {
  158. return;
  159. }
  160. this.setState({ conferenceID: id });
  161. }
  162. /**
  163. * Callback invoked when fetching dial-in numbers succeeds. Sets the
  164. * internal to show the numbers.
  165. *
  166. * @param {Object} response - The response from fetching dial-in numbers.
  167. * @param {Array|Object} response.numbers - The dial-in numbers.
  168. * @param {boolean} reponse.numbersEnabled - Whether or not dial-in is
  169. * enabled.
  170. * @private
  171. * @returns {void}
  172. */
  173. _onGetNumbersSuccess({ numbers, numbersEnabled }) {
  174. this.setState({
  175. numbersEnabled,
  176. numbers
  177. });
  178. }
  179. /**
  180. * Sets an error message to display on the page instead of content.
  181. *
  182. * @param {string} error - The error message to display.
  183. * @private
  184. * @returns {void}
  185. */
  186. _setErrorMessage(error) {
  187. this.setState({
  188. error
  189. });
  190. }
  191. }
  192. export default translate(DialInInfoPage);