您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

DialInSummary.tsx 4.0KB

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