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.tsx 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. import { Theme } from '@mui/material';
  2. import clsx from 'clsx';
  3. import React, { Component } from 'react';
  4. import { WithTranslation } from 'react-i18next';
  5. import { withStyles } from 'tss-react/mui';
  6. import { translate } from '../../../../base/i18n/functions';
  7. import { withPixelLineHeight } from '../../../../base/styles/functions.web';
  8. import { getDialInConferenceID, getDialInNumbers } from '../../../_utils';
  9. import ConferenceID from './ConferenceID';
  10. import NumbersList from './NumbersList';
  11. /**
  12. * The type of the React {@code Component} props of {@link DialInSummary}.
  13. */
  14. interface IProps extends WithTranslation {
  15. /**
  16. * Additional CSS classnames to append to the root of the component.
  17. */
  18. className: string;
  19. /**
  20. * An object containing the CSS classes.
  21. */
  22. classes?: Partial<Record<keyof ReturnType<typeof styles>, string>>;
  23. /**
  24. * Whether or not numbers should include links with the telephone protocol.
  25. */
  26. clickableNumbers: boolean;
  27. /**
  28. * Whether to hide the error.
  29. */
  30. hideError?: boolean;
  31. /**
  32. * The name of the conference to show a conferenceID for.
  33. */
  34. room: string;
  35. /**
  36. * Whether the dial in summary container is scrollable.
  37. */
  38. scrollable?: boolean;
  39. /**
  40. * Whether the room name should show as title.
  41. */
  42. showTitle?: boolean;
  43. /**
  44. * The url where we were loaded.
  45. */
  46. url: any;
  47. }
  48. /**
  49. * The type of the React {@code Component} state of {@link DialInSummary}.
  50. */
  51. type State = {
  52. /**
  53. * The numeric ID of the conference, used as a pin when dialing in.
  54. */
  55. conferenceID: string | null;
  56. /**
  57. * An error message to display.
  58. */
  59. error: string;
  60. /**
  61. * Whether or not the app is fetching data.
  62. */
  63. loading: boolean;
  64. /**
  65. * The dial-in numbers to be displayed.
  66. */
  67. numbers: Array<Object> | Object | null;
  68. /**
  69. * Whether or not dial-in is allowed.
  70. */
  71. numbersEnabled: boolean | null;
  72. };
  73. const styles = (theme: Theme) => {
  74. return {
  75. hasNumbers: {
  76. alignItems: 'center',
  77. display: 'flex',
  78. flexDirection: 'column' as const,
  79. background: '#1E1E1E',
  80. color: theme.palette.text01
  81. },
  82. scrollable: {
  83. height: '100dvh',
  84. overflowY: 'scroll' as const
  85. },
  86. roomName: {
  87. margin: '40px auto 8px',
  88. ...withPixelLineHeight(theme.typography.heading5)
  89. }
  90. };
  91. };
  92. /**
  93. * Displays a page listing numbers for dialing into a conference and pin to
  94. * the a specific conference.
  95. *
  96. * @augments Component
  97. */
  98. class DialInSummary extends Component<IProps, State> {
  99. state = {
  100. conferenceID: null,
  101. error: '',
  102. loading: true,
  103. numbers: null,
  104. numbersEnabled: null
  105. };
  106. /**
  107. * Initializes a new {@code DialInSummary} instance.
  108. *
  109. * @param {Object} props - The read-only properties with which the new
  110. * instance is to be initialized.
  111. */
  112. constructor(props: IProps) {
  113. super(props);
  114. // Bind event handlers so they are only bound once for every instance.
  115. this._onGetNumbersSuccess = this._onGetNumbersSuccess.bind(this);
  116. this._onGetConferenceIDSuccess
  117. = this._onGetConferenceIDSuccess.bind(this);
  118. this._setErrorMessage = this._setErrorMessage.bind(this);
  119. }
  120. /**
  121. * Implements {@link Component#componentDidMount()}. Invoked immediately
  122. * after this component is mounted.
  123. *
  124. * @inheritdoc
  125. * @returns {void}
  126. */
  127. componentDidMount() {
  128. const getNumbers = this._getNumbers()
  129. .then(this._onGetNumbersSuccess)
  130. .catch(this._setErrorMessage);
  131. const getID = this._getConferenceID()
  132. .then(this._onGetConferenceIDSuccess)
  133. .catch(this._setErrorMessage);
  134. Promise.all([ getNumbers, getID ])
  135. .then(() => {
  136. this.setState({ loading: false });
  137. });
  138. }
  139. /**
  140. * Implements React's {@link Component#render()}.
  141. *
  142. * @inheritdoc
  143. * @returns {ReactElement}
  144. */
  145. render() {
  146. let className = '';
  147. let contents;
  148. const { conferenceID, error, loading, numbersEnabled } = this.state;
  149. const { hideError, showTitle, room, clickableNumbers, scrollable, t } = this.props;
  150. const classes = withStyles.getClasses(this.props);
  151. if (loading) {
  152. contents = '';
  153. } else if (numbersEnabled === false) {
  154. contents = t('info.dialInNotSupported');
  155. } else if (error) {
  156. if (!hideError) {
  157. contents = error;
  158. }
  159. } else {
  160. className = clsx(classes.hasNumbers, scrollable && classes.scrollable);
  161. contents = [
  162. conferenceID
  163. ? <>
  164. { showTitle && <div className = { classes.roomName }>{ room }</div> }
  165. <ConferenceID
  166. conferenceID = { conferenceID }
  167. conferenceName = { room }
  168. key = 'conferenceID' />
  169. </> : null,
  170. <NumbersList
  171. clickableNumbers = { clickableNumbers }
  172. conferenceID = { conferenceID }
  173. key = 'numbers'
  174. numbers = { this.state.numbers } />
  175. ];
  176. }
  177. return (
  178. <div className = { className }>
  179. { contents }
  180. </div>
  181. );
  182. }
  183. /**
  184. * Creates an AJAX request for the conference ID.
  185. *
  186. * @private
  187. * @returns {Promise}
  188. */
  189. _getConferenceID() {
  190. const { room } = this.props;
  191. const { dialInConfCodeUrl, hosts } = config;
  192. const mucURL = hosts?.muc;
  193. if (!dialInConfCodeUrl || !mucURL || !room) {
  194. return Promise.resolve();
  195. }
  196. let url = this.props.url || {};
  197. if (typeof url === 'string' || url instanceof String) {
  198. // @ts-ignore
  199. url = new URL(url);
  200. }
  201. return getDialInConferenceID(dialInConfCodeUrl, room, mucURL, url)
  202. .catch(() => Promise.reject(this.props.t('info.genericError')));
  203. }
  204. /**
  205. * Creates an AJAX request for dial-in numbers.
  206. *
  207. * @private
  208. * @returns {Promise}
  209. */
  210. _getNumbers() {
  211. const { room } = this.props;
  212. const { dialInNumbersUrl, hosts } = config;
  213. const mucURL = hosts?.muc;
  214. if (!dialInNumbersUrl) {
  215. return Promise.reject(this.props.t('info.dialInNotSupported'));
  216. }
  217. return getDialInNumbers(dialInNumbersUrl, room, mucURL ?? '')
  218. .catch(() => Promise.reject(this.props.t('info.genericError')));
  219. }
  220. /**
  221. * Callback invoked when fetching the conference ID succeeds.
  222. *
  223. * @param {Object} response - The response from fetching the conference ID.
  224. * @private
  225. * @returns {void}
  226. */
  227. _onGetConferenceIDSuccess(response = { conference: undefined,
  228. id: undefined }) {
  229. const { conference, id } = response;
  230. if (!conference || !id) {
  231. return;
  232. }
  233. this.setState({ conferenceID: id });
  234. }
  235. /**
  236. * Callback invoked when fetching dial-in numbers succeeds. Sets the
  237. * internal to show the numbers.
  238. *
  239. * @param {Array|Object} response - The response from fetching
  240. * dial-in numbers.
  241. * @param {Array|Object} response.numbers - The dial-in numbers.
  242. * @param {boolean} response.numbersEnabled - Whether or not dial-in is
  243. * enabled, old syntax that is deprecated.
  244. * @private
  245. * @returns {void}
  246. */
  247. _onGetNumbersSuccess(
  248. response: Array<Object> | { numbersEnabled?: boolean; }) {
  249. this.setState({
  250. numbersEnabled:
  251. Boolean(Array.isArray(response)
  252. ? response.length > 0 : response.numbersEnabled),
  253. numbers: response
  254. });
  255. }
  256. /**
  257. * Sets an error message to display on the page instead of content.
  258. *
  259. * @param {string} error - The error message to display.
  260. * @private
  261. * @returns {void}
  262. */
  263. _setErrorMessage(error: string) {
  264. this.setState({
  265. error
  266. });
  267. }
  268. }
  269. export default translate(withStyles(DialInSummary, styles));