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.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // @flow
  2. import React, { PureComponent } from 'react';
  3. import { Linking, View } from 'react-native';
  4. import { WebView } from 'react-native-webview';
  5. import { type Dispatch } from 'redux';
  6. import { openDialog } from '../../../../base/dialog';
  7. import { translate } from '../../../../base/i18n';
  8. import JitsiScreen from '../../../../base/modal/components/JitsiScreen';
  9. import { LoadingIndicator } from '../../../../base/react';
  10. import { connect } from '../../../../base/redux';
  11. import { getDialInfoPageURLForURIString } from '../../../functions';
  12. import DialInSummaryErrorDialog from './DialInSummaryErrorDialog';
  13. import styles, { INDICATOR_COLOR } from './styles';
  14. type Props = {
  15. dispatch: Dispatch<any>,
  16. /**
  17. * Default prop for navigating between screen components(React Navigation).
  18. */
  19. navigation: Object,
  20. /**
  21. * Default prop for navigating between screen components(React Navigation).
  22. */
  23. route: Object,
  24. /**
  25. * Translation function.
  26. */
  27. t: Function
  28. };
  29. /**
  30. * Implements a React native component that displays the dial in info page for a specific room.
  31. */
  32. class DialInSummary extends PureComponent<Props> {
  33. /**
  34. * Initializes a new instance.
  35. *
  36. * @inheritdoc
  37. */
  38. constructor(props: Props) {
  39. super(props);
  40. this._onError = this._onError.bind(this);
  41. this._onNavigate = this._onNavigate.bind(this);
  42. this._renderLoading = this._renderLoading.bind(this);
  43. }
  44. /**
  45. * Implements React's {@link Component#componentDidMount()}. Invoked
  46. * immediately after mounting occurs.
  47. *
  48. * @inheritdoc
  49. * @returns {void}
  50. */
  51. componentDidMount() {
  52. const { navigation, t } = this.props;
  53. navigation.setOptions({
  54. headerTitle: t('dialIn.screenTitle')
  55. });
  56. }
  57. /**
  58. * Implements React's {@link Component#render()}.
  59. *
  60. * @inheritdoc
  61. */
  62. render() {
  63. const { route } = this.props;
  64. const summaryUrl = route.params?.summaryUrl;
  65. return (
  66. <JitsiScreen
  67. style = { styles.backDrop }>
  68. <WebView
  69. onError = { this._onError }
  70. onShouldStartLoadWithRequest = { this._onNavigate }
  71. renderLoading = { this._renderLoading }
  72. setSupportMultipleWindows = { false }
  73. source = {{ uri: getDialInfoPageURLForURIString(summaryUrl) }}
  74. startInLoadingState = { true }
  75. style = { styles.webView } />
  76. </JitsiScreen>
  77. );
  78. }
  79. _onError: () => void;
  80. /**
  81. * Callback to handle the error if the page fails to load.
  82. *
  83. * @returns {void}
  84. */
  85. _onError() {
  86. this.props.dispatch(openDialog(DialInSummaryErrorDialog));
  87. }
  88. _onNavigate: Object => Boolean;
  89. /**
  90. * Callback to intercept navigation inside the webview and make the native app handle the dial requests.
  91. *
  92. * NOTE: We don't navigate to anywhere else form that view.
  93. *
  94. * @param {any} request - The request object.
  95. * @returns {boolean}
  96. */
  97. _onNavigate(request) {
  98. const { url } = request;
  99. const { route } = this.props;
  100. const summaryUrl = route.params?.summaryUrl;
  101. if (url.startsWith('tel:')) {
  102. Linking.openURL(url);
  103. }
  104. return url === getDialInfoPageURLForURIString(summaryUrl);
  105. }
  106. _renderLoading: () => React$Component<any>;
  107. /**
  108. * Renders the loading indicator.
  109. *
  110. * @returns {React$Component<any>}
  111. */
  112. _renderLoading() {
  113. return (
  114. <View style = { styles.indicatorWrapper }>
  115. <LoadingIndicator
  116. color = { INDICATOR_COLOR }
  117. size = 'large' />
  118. </View>
  119. );
  120. }
  121. }
  122. export default translate(connect()(DialInSummary));