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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // @flow
  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 type of the React {@code Component} props of {@link WaitForOwnerDialog}.
  11. */
  12. type Props = {
  13. /**
  14. * The name of the conference room (without the domain part).
  15. */
  16. _room: string,
  17. /**
  18. * Redux store dispatch function.
  19. */
  20. dispatch: Dispatch<*>,
  21. /**
  22. * Invoked to obtain translated strings.
  23. */
  24. t: Function
  25. };
  26. /**
  27. * The dialog is display in XMPP password + guest access configuration, after
  28. * user connects from anonymous domain and the conference does not exist yet.
  29. *
  30. * See {@link LoginDialog} description for more details.
  31. */
  32. class WaitForOwnerDialog extends Component<Props> {
  33. /**
  34. * Initializes a new WaitForWonderDialog instance.
  35. *
  36. * @param {Object} props - The read-only properties with which the new
  37. * instance is to be initialized.
  38. */
  39. constructor(props) {
  40. super(props);
  41. // Bind event handlers so they are only bound once per instance.
  42. this._onCancel = this._onCancel.bind(this);
  43. this._onLogin = this._onLogin.bind(this);
  44. }
  45. /**
  46. * Implements React's {@link Component#render()}.
  47. *
  48. * @inheritdoc
  49. * @returns {ReactElement}
  50. */
  51. render() {
  52. const {
  53. _room: room,
  54. t
  55. } = this.props;
  56. return (
  57. <Dialog
  58. okTitleKey = { 'dialog.IamHost' }
  59. onCancel = { this._onCancel }
  60. onSubmit = { this._onLogin }
  61. titleKey = 'dialog.WaitingForHost'>
  62. <Text style = { styles.waitForOwnerDialog }>
  63. {
  64. this._renderHTML(t('dialog.WaitForHostMsg', { room }))
  65. }
  66. </Text>
  67. </Dialog>
  68. );
  69. }
  70. _onCancel: () => void;
  71. /**
  72. * Called when the cancel button is clicked.
  73. *
  74. * @private
  75. * @returns {void}
  76. */
  77. _onCancel() {
  78. this.props.dispatch(cancelWaitForOwner());
  79. }
  80. _onLogin: () => void;
  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|undefined} html - The {@code string} which may
  94. * contain HTML to render.
  95. * @returns {ReactElement[]|string}
  96. */
  97. _renderHTML(html: ?string) {
  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 { authRequired } = state['features/base/conference'];
  149. return {
  150. _room: authRequired && authRequired.getName()
  151. };
  152. }
  153. export default translate(connect(_mapStateToProps)(WaitForOwnerDialog));