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.

WaitForOwnerDialog.native.js 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import PropTypes from 'prop-types';
  2. import React, { Component } from 'react';
  3. import { Text } from 'react-native';
  4. import { connect } from 'react-redux';
  5. import { Dialog } from '../../base/dialog';
  6. import { translate } from '../../base/i18n';
  7. import { cancelWaitForOwner, _openLoginDialog } from '../actions';
  8. import styles from './styles';
  9. /**
  10. * The dialog is display in XMPP password + guest access configuration, after
  11. * user connects from anonymous domain and the conference does not exist yet.
  12. *
  13. * See {@link LoginDialog} description for more details.
  14. */
  15. class WaitForOwnerDialog extends Component {
  16. /**
  17. * WaitForOwnerDialog component's property types.
  18. *
  19. * @static
  20. */
  21. static propTypes = {
  22. /**
  23. * The name of the conference room (without the domain part).
  24. */
  25. _room: PropTypes.string,
  26. /**
  27. * Redux store dispatch function.
  28. */
  29. dispatch: PropTypes.func,
  30. /**
  31. * Invoked to obtain translated strings.
  32. */
  33. t: PropTypes.func
  34. };
  35. /**
  36. * Initializes a new WaitForWonderDialog instance.
  37. *
  38. * @param {Object} props - The read-only properties with which the new
  39. * instance is to be initialized.
  40. */
  41. constructor(props) {
  42. super(props);
  43. // Bind event handlers so they are only bound once per instance.
  44. this._onCancel = this._onCancel.bind(this);
  45. this._onLogin = this._onLogin.bind(this);
  46. }
  47. /**
  48. * Implements React's {@link Component#render()}.
  49. *
  50. * @inheritdoc
  51. * @returns {ReactElement}
  52. */
  53. render() {
  54. const {
  55. _room: room,
  56. t
  57. } = this.props;
  58. return (
  59. <Dialog
  60. okTitleKey = { 'dialog.IamHost' }
  61. onCancel = { this._onCancel }
  62. onSubmit = { this._onLogin }
  63. titleKey = 'dialog.WaitingForHost'>
  64. <Text style = { styles.waitForOwnerDialog }>
  65. {
  66. this._renderHTML(t('dialog.WaitForHostMsg', { room }))
  67. }
  68. </Text>
  69. </Dialog>
  70. );
  71. }
  72. /**
  73. * Called when the cancel button is clicked.
  74. *
  75. * @private
  76. * @returns {void}
  77. */
  78. _onCancel() {
  79. this.props.dispatch(cancelWaitForOwner());
  80. }
  81. /**
  82. * Called when the OK button is clicked.
  83. *
  84. * @private
  85. * @returns {void}
  86. */
  87. _onLogin() {
  88. this.props.dispatch(_openLoginDialog());
  89. }
  90. /**
  91. * Renders a specific {@code string} which may contain HTML.
  92. *
  93. * @param {string} html - The {@code string} which may contain HTML to
  94. * render.
  95. * @returns {ReactElement[]|string}
  96. */
  97. _renderHTML(html) {
  98. if (typeof html === 'string') {
  99. // At the time of this writing, the specified HTML contains a couple
  100. // of spaces one after the other. They do not cause a visible
  101. // problem on Web, because the specified HTML is rendered as, well,
  102. // HTML. However, we're not rendering HTML here.
  103. // eslint-disable-next-line no-param-reassign
  104. html = html.replace(/\s{2,}/gi, ' ');
  105. // Render text in <b>text</b> in bold.
  106. const opening = /<\s*b\s*>/gi;
  107. const closing = /<\s*\/\s*b\s*>/gi;
  108. let o;
  109. let c;
  110. let prevClosingLastIndex = 0;
  111. const r = [];
  112. // eslint-disable-next-line no-cond-assign
  113. while (o = opening.exec(html)) {
  114. closing.lastIndex = opening.lastIndex;
  115. // eslint-disable-next-line no-cond-assign
  116. if (c = closing.exec(html)) {
  117. r.push(html.substring(prevClosingLastIndex, o.index));
  118. r.push(
  119. <Text style = { styles.boldDialogText }>
  120. { html.substring(opening.lastIndex, c.index) }
  121. </Text>);
  122. opening.lastIndex
  123. = prevClosingLastIndex
  124. = closing.lastIndex;
  125. } else {
  126. break;
  127. }
  128. }
  129. if (prevClosingLastIndex < html.length) {
  130. r.push(html.substring(prevClosingLastIndex));
  131. }
  132. return r;
  133. }
  134. return html;
  135. }
  136. }
  137. /**
  138. * Maps (parts of) the Redux state to the associated props for the
  139. * {@code WaitForOwnerDialog} component.
  140. *
  141. * @param {Object} state - The Redux state.
  142. * @private
  143. * @returns {{
  144. * _room: string
  145. * }}
  146. */
  147. function _mapStateToProps(state) {
  148. const {
  149. authRequired
  150. } = state['features/base/conference'];
  151. return {
  152. _room: authRequired && authRequired.getName()
  153. };
  154. }
  155. export default translate(connect(_mapStateToProps)(WaitForOwnerDialog));