Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Prejoin.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. // @flow
  2. import InlineDialog from '@atlaskit/inline-dialog';
  3. import React, { Component } from 'react';
  4. import { getRoomName } from '../../base/conference';
  5. import { translate } from '../../base/i18n';
  6. import { IconArrowDown, IconArrowUp, IconPhone, IconVolumeOff } from '../../base/icons';
  7. import { isVideoMutedByUser } from '../../base/media';
  8. import { ActionButton, InputField, PreMeetingScreen } from '../../base/premeeting';
  9. import { connect } from '../../base/redux';
  10. import { getDisplayName, updateSettings } from '../../base/settings';
  11. import { getLocalJitsiVideoTrack } from '../../base/tracks';
  12. import {
  13. joinConference as joinConferenceAction,
  14. joinConferenceWithoutAudio as joinConferenceWithoutAudioAction,
  15. setJoinByPhoneDialogVisiblity as setJoinByPhoneDialogVisiblityAction
  16. } from '../actions';
  17. import {
  18. isDeviceStatusVisible,
  19. isDisplayNameRequired,
  20. isJoinByPhoneButtonVisible,
  21. isJoinByPhoneDialogVisible,
  22. isPrejoinNameReadOnly
  23. } from '../functions';
  24. import DropdownButton from './DropdownButton';
  25. import JoinByPhoneDialog from './dialogs/JoinByPhoneDialog';
  26. type Props = {
  27. /**
  28. * Flag signaling if the device status is visible or not.
  29. */
  30. deviceStatusVisible: boolean,
  31. /**
  32. * If join by phone button should be visible.
  33. */
  34. hasJoinByPhoneButton: boolean,
  35. /**
  36. * Joins the current meeting.
  37. */
  38. joinConference: Function,
  39. /**
  40. * Joins the current meeting without audio.
  41. */
  42. joinConferenceWithoutAudio: Function,
  43. /**
  44. * The name of the user that is about to join.
  45. */
  46. name: string,
  47. /**
  48. * Updates settings.
  49. */
  50. updateSettings: Function,
  51. /**
  52. * Whether the name input should be read only or not.
  53. */
  54. readOnlyName: boolean,
  55. /**
  56. * The name of the meeting that is about to be joined.
  57. */
  58. roomName: string,
  59. /**
  60. * Sets visibility of the 'JoinByPhoneDialog'.
  61. */
  62. setJoinByPhoneDialogVisiblity: Function,
  63. /**
  64. * Flag signaling the visibility of camera preview.
  65. */
  66. showCameraPreview: boolean,
  67. /**
  68. * If should show an error when joining without a name.
  69. */
  70. showErrorOnJoin: boolean,
  71. /**
  72. * If 'JoinByPhoneDialog' is visible or not.
  73. */
  74. showDialog: boolean,
  75. /**
  76. * Used for translation.
  77. */
  78. t: Function,
  79. /**
  80. * The JitsiLocalTrack to display.
  81. */
  82. videoTrack: ?Object
  83. };
  84. type State = {
  85. /**
  86. * Flag controlling the visibility of the error label.
  87. */
  88. showError: boolean,
  89. /**
  90. * Flag controlling the visibility of the 'join by phone' buttons.
  91. */
  92. showJoinByPhoneButtons: boolean
  93. }
  94. /**
  95. * This component is displayed before joining a meeting.
  96. */
  97. class Prejoin extends Component<Props, State> {
  98. /**
  99. * Initializes a new {@code Prejoin} instance.
  100. *
  101. * @inheritdoc
  102. */
  103. constructor(props) {
  104. super(props);
  105. this.state = {
  106. showError: false,
  107. showJoinByPhoneButtons: false
  108. };
  109. this._closeDialog = this._closeDialog.bind(this);
  110. this._showDialog = this._showDialog.bind(this);
  111. this._onJoinButtonClick = this._onJoinButtonClick.bind(this);
  112. this._onDropdownClose = this._onDropdownClose.bind(this);
  113. this._onOptionsClick = this._onOptionsClick.bind(this);
  114. this._setName = this._setName.bind(this);
  115. this._onJoinConferenceWithoutAudioKeyPress = this._onJoinConferenceWithoutAudioKeyPress.bind(this);
  116. this._showDialogKeyPress = this._showDialogKeyPress.bind(this);
  117. this._onJoinKeyPress = this._onJoinKeyPress.bind(this);
  118. }
  119. _onJoinButtonClick: () => void;
  120. /**
  121. * Handler for the join button.
  122. *
  123. * @param {Object} e - The synthetic event.
  124. * @returns {void}
  125. */
  126. _onJoinButtonClick() {
  127. if (this.props.showErrorOnJoin) {
  128. this.setState({
  129. showError: true
  130. });
  131. return;
  132. }
  133. this.setState({ showError: false });
  134. this.props.joinConference();
  135. }
  136. _onJoinKeyPress: (Object) => void;
  137. /**
  138. * KeyPress handler for accessibility.
  139. *
  140. * @param {Object} e - The key event to handle.
  141. *
  142. * @returns {void}
  143. */
  144. _onJoinKeyPress(e) {
  145. if (e.key === ' ' || e.key === 'Enter') {
  146. e.preventDefault();
  147. this._onJoinButtonClick();
  148. }
  149. }
  150. _onDropdownClose: () => void;
  151. /**
  152. * Closes the dropdown.
  153. *
  154. * @returns {void}
  155. */
  156. _onDropdownClose() {
  157. this.setState({
  158. showJoinByPhoneButtons: false
  159. });
  160. }
  161. _onOptionsClick: () => void;
  162. /**
  163. * Displays the join by phone buttons dropdown.
  164. *
  165. * @param {Object} e - The synthetic event.
  166. * @returns {void}
  167. */
  168. _onOptionsClick(e) {
  169. e.stopPropagation();
  170. this.setState({
  171. showJoinByPhoneButtons: !this.state.showJoinByPhoneButtons
  172. });
  173. }
  174. _setName: () => void;
  175. /**
  176. * Sets the guest participant name.
  177. *
  178. * @param {string} displayName - Participant name.
  179. * @returns {void}
  180. */
  181. _setName(displayName) {
  182. this.props.updateSettings({
  183. displayName
  184. });
  185. }
  186. _closeDialog: () => void;
  187. /**
  188. * Closes the join by phone dialog.
  189. *
  190. * @returns {undefined}
  191. */
  192. _closeDialog() {
  193. this.props.setJoinByPhoneDialogVisiblity(false);
  194. }
  195. _showDialog: () => void;
  196. /**
  197. * Displays the dialog for joining a meeting by phone.
  198. *
  199. * @returns {undefined}
  200. */
  201. _showDialog() {
  202. this.props.setJoinByPhoneDialogVisiblity(true);
  203. this._onDropdownClose();
  204. }
  205. _showDialogKeyPress: (Object) => void;
  206. /**
  207. * KeyPress handler for accessibility.
  208. *
  209. * @param {Object} e - The key event to handle.
  210. *
  211. * @returns {void}
  212. */
  213. _showDialogKeyPress(e) {
  214. if (e.key === ' ' || e.key === 'Enter') {
  215. e.preventDefault();
  216. this._showDialog();
  217. }
  218. }
  219. _onJoinConferenceWithoutAudioKeyPress: (Object) => void;
  220. /**
  221. * KeyPress handler for accessibility.
  222. *
  223. * @param {Object} e - The key event to handle.
  224. *
  225. * @returns {void}
  226. */
  227. _onJoinConferenceWithoutAudioKeyPress(e) {
  228. if (this.props.joinConferenceWithoutAudio
  229. && (e.key === ' '
  230. || e.key === 'Enter')) {
  231. e.preventDefault();
  232. this.props.joinConferenceWithoutAudio();
  233. }
  234. }
  235. /**
  236. * Implements React's {@link Component#render()}.
  237. *
  238. * @inheritdoc
  239. * @returns {ReactElement}
  240. */
  241. render() {
  242. const {
  243. deviceStatusVisible,
  244. hasJoinByPhoneButton,
  245. joinConference,
  246. joinConferenceWithoutAudio,
  247. name,
  248. readOnlyName,
  249. showCameraPreview,
  250. showDialog,
  251. t,
  252. videoTrack
  253. } = this.props;
  254. const { _closeDialog, _onDropdownClose, _onJoinButtonClick, _onJoinKeyPress, _showDialogKeyPress,
  255. _onJoinConferenceWithoutAudioKeyPress, _onOptionsClick, _setName, _showDialog } = this;
  256. const { showJoinByPhoneButtons, showError } = this.state;
  257. return (
  258. <PreMeetingScreen
  259. showDeviceStatus = { deviceStatusVisible }
  260. title = { t('prejoin.joinMeeting') }
  261. videoMuted = { !showCameraPreview }
  262. videoTrack = { videoTrack }>
  263. <div
  264. className = 'prejoin-input-area'
  265. data-testid = 'prejoin.screen'>
  266. <InputField
  267. autoComplete = { 'name' }
  268. autoFocus = { true }
  269. className = { showError ? 'error' : '' }
  270. hasError = { showError }
  271. onChange = { _setName }
  272. onSubmit = { joinConference }
  273. placeHolder = { t('dialog.enterDisplayName') }
  274. readOnly = { readOnlyName }
  275. value = { name } />
  276. {showError && <div
  277. className = 'prejoin-error'
  278. data-testid = 'prejoin.errorMessage'>{t('prejoin.errorMissingName')}</div>}
  279. <div className = 'prejoin-preview-dropdown-container'>
  280. <InlineDialog
  281. content = { <div className = 'prejoin-preview-dropdown-btns'>
  282. <DropdownButton
  283. dataTestId = 'prejoin.joinWithoutAudio'
  284. icon = { IconVolumeOff }
  285. label = { t('prejoin.joinWithoutAudio') }
  286. onButtonClick = { joinConferenceWithoutAudio }
  287. onKeyPressed = { _onJoinConferenceWithoutAudioKeyPress } />
  288. {hasJoinByPhoneButton && <DropdownButton
  289. dataTestId = 'prejoin.joinByPhone'
  290. icon = { IconPhone }
  291. label = { t('prejoin.joinAudioByPhone') }
  292. onButtonClick = { _showDialog }
  293. onKeyPressed = { _showDialogKeyPress } />}
  294. </div> }
  295. isOpen = { showJoinByPhoneButtons }
  296. onClose = { _onDropdownClose }>
  297. <ActionButton
  298. OptionsIcon = { showJoinByPhoneButtons ? IconArrowUp : IconArrowDown }
  299. ariaDropDownLabel = { t('prejoin.joinWithoutAudio') }
  300. ariaLabel = { t('prejoin.joinMeeting') }
  301. ariaPressed = { showJoinByPhoneButtons }
  302. hasOptions = { true }
  303. onClick = { _onJoinButtonClick }
  304. onKeyPress = { _onJoinKeyPress }
  305. onOptionsClick = { _onOptionsClick }
  306. role = 'button'
  307. tabIndex = { 0 }
  308. testId = 'prejoin.joinMeeting'
  309. type = 'primary'>
  310. { t('prejoin.joinMeeting') }
  311. </ActionButton>
  312. </InlineDialog>
  313. </div>
  314. </div>
  315. { showDialog && (
  316. <JoinByPhoneDialog
  317. joinConferenceWithoutAudio = { joinConferenceWithoutAudio }
  318. onClose = { _closeDialog } />
  319. )}
  320. </PreMeetingScreen>
  321. );
  322. }
  323. }
  324. /**
  325. * Maps (parts of) the redux state to the React {@code Component} props.
  326. *
  327. * @param {Object} state - The redux state.
  328. * @returns {Object}
  329. */
  330. function mapStateToProps(state): Object {
  331. const name = getDisplayName(state);
  332. const showErrorOnJoin = isDisplayNameRequired(state) && !name;
  333. return {
  334. name,
  335. deviceStatusVisible: isDeviceStatusVisible(state),
  336. roomName: getRoomName(state),
  337. showDialog: isJoinByPhoneDialogVisible(state),
  338. showErrorOnJoin,
  339. hasJoinByPhoneButton: isJoinByPhoneButtonVisible(state),
  340. readOnlyName: isPrejoinNameReadOnly(state),
  341. showCameraPreview: !isVideoMutedByUser(state),
  342. videoTrack: getLocalJitsiVideoTrack(state)
  343. };
  344. }
  345. const mapDispatchToProps = {
  346. joinConferenceWithoutAudio: joinConferenceWithoutAudioAction,
  347. joinConference: joinConferenceAction,
  348. setJoinByPhoneDialogVisiblity: setJoinByPhoneDialogVisiblityAction,
  349. updateSettings
  350. };
  351. export default connect(mapStateToProps, mapDispatchToProps)(translate(Prejoin));