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

DialInSummary.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // @flow
  2. import React, { Component } 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 { JitsiModal, setActiveModalId } from '../../../../base/modal';
  9. import { LoadingIndicator } from '../../../../base/react';
  10. import { connect } from '../../../../base/redux';
  11. import { DIAL_IN_SUMMARY_VIEW_ID } from '../../../constants';
  12. import { getDialInfoPageURLForURIString } from '../../../functions';
  13. import DialInSummaryErrorDialog from './DialInSummaryErrorDialog';
  14. import styles, { INDICATOR_COLOR } from './styles';
  15. type Props = {
  16. /**
  17. * The URL to display the summary for.
  18. */
  19. _summaryUrl: ?string,
  20. dispatch: Dispatch<any>
  21. };
  22. /**
  23. * Implements a React native component that displays the dial in info page for a specific room.
  24. */
  25. class DialInSummary extends Component<Props> {
  26. /**
  27. * Initializes a new instance.
  28. *
  29. * @inheritdoc
  30. */
  31. constructor(props: Props) {
  32. super(props);
  33. this._onError = this._onError.bind(this);
  34. this._onNavigate = this._onNavigate.bind(this);
  35. this._renderLoading = this._renderLoading.bind(this);
  36. }
  37. /**
  38. * Implements React's {@link Component#render()}.
  39. *
  40. * @inheritdoc
  41. */
  42. render() {
  43. const { _summaryUrl } = this.props;
  44. return (
  45. <JitsiModal
  46. headerProps = {{
  47. headerLabelKey: 'info.label'
  48. }}
  49. modalId = { DIAL_IN_SUMMARY_VIEW_ID }
  50. style = { styles.backDrop }>
  51. <WebView
  52. onError = { this._onError }
  53. onShouldStartLoadWithRequest = { this._onNavigate }
  54. renderLoading = { this._renderLoading }
  55. source = {{ uri: getDialInfoPageURLForURIString(_summaryUrl) }}
  56. startInLoadingState = { true }
  57. style = { styles.webView } />
  58. </JitsiModal>
  59. );
  60. }
  61. _onError: () => void;
  62. /**
  63. * Callback to handle the error if the page fails to load.
  64. *
  65. * @returns {void}
  66. */
  67. _onError() {
  68. this.props.dispatch(setActiveModalId());
  69. this.props.dispatch(openDialog(DialInSummaryErrorDialog));
  70. }
  71. _onNavigate: Object => Boolean;
  72. /**
  73. * Callback to intercept navigation inside the webview and make the native app handle the dial requests.
  74. *
  75. * NOTE: We don't navigate to anywhere else form that view.
  76. *
  77. * @param {any} request - The request object.
  78. * @returns {boolean}
  79. */
  80. _onNavigate(request) {
  81. const { url } = request;
  82. if (url.startsWith('tel:')) {
  83. Linking.openURL(url);
  84. this.props.dispatch(setActiveModalId());
  85. }
  86. return url === getDialInfoPageURLForURIString(this.props._summaryUrl);
  87. }
  88. _renderLoading: () => React$Component<any>;
  89. /**
  90. * Renders the loading indicator.
  91. *
  92. * @returns {React$Component<any>}
  93. */
  94. _renderLoading() {
  95. return (
  96. <View style = { styles.indicatorWrapper }>
  97. <LoadingIndicator
  98. color = { INDICATOR_COLOR }
  99. size = 'large' />
  100. </View>
  101. );
  102. }
  103. }
  104. /**
  105. * Maps part of the Redux state to the props of this component.
  106. *
  107. * @param {Object} state - The Redux state.
  108. * @returns {{
  109. * _summaryUrl: ?string
  110. * }}
  111. */
  112. function _mapStateToProps(state) {
  113. return {
  114. _summaryUrl: (state['features/base/modal'].modalProps || {}).summaryUrl
  115. };
  116. }
  117. export default translate(connect(_mapStateToProps)(DialInSummary));