Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

DialInSummary.tsx 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. import { Theme } from '@mui/material';
  2. import { withStyles } from '@mui/styles';
  3. import clsx from 'clsx';
  4. import React, { Component } from 'react';
  5. import { WithTranslation } from 'react-i18next';
  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: any;
  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 { classes, hideError, showTitle, room, clickableNumbers, scrollable, t } = this.props;
  150. if (loading) {
  151. contents = '';
  152. } else if (numbersEnabled === false) {
  153. contents = t('info.dialInNotSupported');
  154. } else if (error) {
  155. if (!hideError) {
  156. contents = error;
  157. }
  158. } else {
  159. className = clsx(classes.hasNumbers, scrollable && classes.scrollable);
  160. contents = [
  161. conferenceID
  162. ? <>
  163. { showTitle && <div className = { classes.roomName }>{ room }</div> }
  164. <ConferenceID
  165. conferenceID = { conferenceID }
  166. conferenceName = { room }
  167. key = 'conferenceID' />
  168. </> : null,
  169. <NumbersList
  170. clickableNumbers = { clickableNumbers }
  171. conferenceID = { conferenceID }
  172. key = 'numbers'
  173. numbers = { this.state.numbers } />
  174. ];
  175. }
  176. return (
  177. <div className = { className }>
  178. { contents }
  179. </div>
  180. );
  181. }
  182. /**
  183. * Creates an AJAX request for the conference ID.
  184. *
  185. * @private
  186. * @returns {Promise}
  187. */
  188. _getConferenceID() {
  189. const { room } = this.props;
  190. const { dialInConfCodeUrl, hosts } = config;
  191. const mucURL = hosts?.muc;
  192. if (!dialInConfCodeUrl || !mucURL || !room) {
  193. return Promise.resolve();
  194. }
  195. let url = this.props.url || {};
  196. if (typeof url === 'string' || url instanceof String) {
  197. // @ts-ignore
  198. url = new URL(url);
  199. }
  200. return getDialInConferenceID(dialInConfCodeUrl, room, mucURL, url)
  201. .catch(() => Promise.reject(this.props.t('info.genericError')));
  202. }
  203. /**
  204. * Creates an AJAX request for dial-in numbers.
  205. *
  206. * @private
  207. * @returns {Promise}
  208. */
  209. _getNumbers() {
  210. const { room } = this.props;
  211. const { dialInNumbersUrl, hosts } = config;
  212. const mucURL = hosts?.muc;
  213. if (!dialInNumbersUrl) {
  214. return Promise.reject(this.props.t('info.dialInNotSupported'));
  215. }
  216. return getDialInNumbers(dialInNumbersUrl, room, mucURL ?? '')
  217. .catch(() => Promise.reject(this.props.t('info.genericError')));
  218. }
  219. /**
  220. * Callback invoked when fetching the conference ID succeeds.
  221. *
  222. * @param {Object} response - The response from fetching the conference ID.
  223. * @private
  224. * @returns {void}
  225. */
  226. _onGetConferenceIDSuccess(response = { conference: undefined,
  227. id: undefined }) {
  228. const { conference, id } = response;
  229. if (!conference || !id) {
  230. return;
  231. }
  232. this.setState({ conferenceID: id });
  233. }
  234. /**
  235. * Callback invoked when fetching dial-in numbers succeeds. Sets the
  236. * internal to show the numbers.
  237. *
  238. * @param {Array|Object} response - The response from fetching
  239. * dial-in numbers.
  240. * @param {Array|Object} response.numbers - The dial-in numbers.
  241. * @param {boolean} response.numbersEnabled - Whether or not dial-in is
  242. * enabled, old syntax that is deprecated.
  243. * @private
  244. * @returns {void}
  245. */
  246. _onGetNumbersSuccess(
  247. response: Array<Object> | { numbersEnabled?: boolean; }) {
  248. this.setState({
  249. numbersEnabled:
  250. Boolean(Array.isArray(response)
  251. ? response.length > 0 : response.numbersEnabled),
  252. numbers: response
  253. });
  254. }
  255. /**
  256. * Sets an error message to display on the page instead of content.
  257. *
  258. * @param {string} error - The error message to display.
  259. * @private
  260. * @returns {void}
  261. */
  262. _setErrorMessage(error: string) {
  263. this.setState({
  264. error
  265. });
  266. }
  267. }
  268. export default translate(withStyles(styles)(DialInSummary));