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.9KB

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