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.

DialInSummary.web.js 6.4KB

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