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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. showHeaderWithNavigation = { true }
  51. style = { styles.backDrop }>
  52. <WebView
  53. onError = { this._onError }
  54. onShouldStartLoadWithRequest = { this._onNavigate }
  55. renderLoading = { this._renderLoading }
  56. source = {{ uri: getDialInfoPageURLForURIString(_summaryUrl) }}
  57. startInLoadingState = { true }
  58. style = { styles.webView } />
  59. </JitsiModal>
  60. );
  61. }
  62. _onError: () => void;
  63. /**
  64. * Callback to handle the error if the page fails to load.
  65. *
  66. * @returns {void}
  67. */
  68. _onError() {
  69. this.props.dispatch(setActiveModalId());
  70. this.props.dispatch(openDialog(DialInSummaryErrorDialog));
  71. }
  72. _onNavigate: Object => Boolean;
  73. /**
  74. * Callback to intercept navigation inside the webview and make the native app handle the dial requests.
  75. *
  76. * NOTE: We don't navigate to anywhere else form that view.
  77. *
  78. * @param {any} request - The request object.
  79. * @returns {boolean}
  80. */
  81. _onNavigate(request) {
  82. const { url } = request;
  83. if (url.startsWith('tel:')) {
  84. Linking.openURL(url);
  85. this.props.dispatch(setActiveModalId());
  86. }
  87. return url === getDialInfoPageURLForURIString(this.props._summaryUrl);
  88. }
  89. _renderLoading: () => React$Component<any>;
  90. /**
  91. * Renders the loading indicator.
  92. *
  93. * @returns {React$Component<any>}
  94. */
  95. _renderLoading() {
  96. return (
  97. <View style = { styles.indicatorWrapper }>
  98. <LoadingIndicator
  99. color = { INDICATOR_COLOR }
  100. size = 'large' />
  101. </View>
  102. );
  103. }
  104. }
  105. /**
  106. * Maps part of the Redux state to the props of this component.
  107. *
  108. * @param {Object} state - The Redux state.
  109. * @returns {{
  110. * _summaryUrl: ?string
  111. * }}
  112. */
  113. function _mapStateToProps(state) {
  114. return {
  115. _summaryUrl: (state['features/base/modal'].modalProps || {}).summaryUrl
  116. };
  117. }
  118. export default translate(connect(_mapStateToProps)(DialInSummary));