您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Prejoin.js 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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 { Icon, 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. setSkipPrejoin as setSkipPrejoinAction,
  16. setJoinByPhoneDialogVisiblity as setJoinByPhoneDialogVisiblityAction
  17. } from '../actions';
  18. import {
  19. isDeviceStatusVisible,
  20. isDisplayNameRequired,
  21. isJoinByPhoneButtonVisible,
  22. isJoinByPhoneDialogVisible
  23. } from '../functions';
  24. import JoinByPhoneDialog from './dialogs/JoinByPhoneDialog';
  25. import DeviceStatus from './preview/DeviceStatus';
  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. * If join button is disabled or not.
  37. */
  38. joinButtonDisabled: boolean,
  39. /**
  40. * Joins the current meeting.
  41. */
  42. joinConference: Function,
  43. /**
  44. * Joins the current meeting without audio.
  45. */
  46. joinConferenceWithoutAudio: Function,
  47. /**
  48. * The name of the user that is about to join.
  49. */
  50. name: string,
  51. /**
  52. * Updates settings.
  53. */
  54. updateSettings: Function,
  55. /**
  56. * The name of the meeting that is about to be joined.
  57. */
  58. roomName: string,
  59. /**
  60. * Sets visibility of the prejoin page for the next sessions.
  61. */
  62. setSkipPrejoin: Function,
  63. /**
  64. * Sets visibility of the 'JoinByPhoneDialog'.
  65. */
  66. setJoinByPhoneDialogVisiblity: Function,
  67. /**
  68. * Flag signaling the visibility of camera preview.
  69. */
  70. showCameraPreview: 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 'join by phone' buttons.
  87. */
  88. showJoinByPhoneButtons: boolean
  89. }
  90. /**
  91. * This component is displayed before joining a meeting.
  92. */
  93. class Prejoin extends Component<Props, State> {
  94. /**
  95. * Initializes a new {@code Prejoin} instance.
  96. *
  97. * @inheritdoc
  98. */
  99. constructor(props) {
  100. super(props);
  101. this.state = {
  102. showJoinByPhoneButtons: false
  103. };
  104. this._closeDialog = this._closeDialog.bind(this);
  105. this._showDialog = this._showDialog.bind(this);
  106. this._onCheckboxChange = this._onCheckboxChange.bind(this);
  107. this._onDropdownClose = this._onDropdownClose.bind(this);
  108. this._onOptionsClick = this._onOptionsClick.bind(this);
  109. this._setName = this._setName.bind(this);
  110. }
  111. _onCheckboxChange: () => void;
  112. /**
  113. * Handler for the checkbox.
  114. *
  115. * @param {Object} e - The synthetic event.
  116. * @returns {void}
  117. */
  118. _onCheckboxChange(e) {
  119. this.props.setSkipPrejoin(e.target.checked);
  120. }
  121. _onDropdownClose: () => void;
  122. /**
  123. * Closes the dropdown.
  124. *
  125. * @returns {void}
  126. */
  127. _onDropdownClose() {
  128. this.setState({
  129. showJoinByPhoneButtons: false
  130. });
  131. }
  132. _onOptionsClick: () => void;
  133. /**
  134. * Displays the join by phone buttons dropdown.
  135. *
  136. * @param {Object} e - The synthetic event.
  137. * @returns {void}
  138. */
  139. _onOptionsClick(e) {
  140. e.stopPropagation();
  141. this.setState({
  142. showJoinByPhoneButtons: !this.state.showJoinByPhoneButtons
  143. });
  144. }
  145. _setName: () => void;
  146. /**
  147. * Sets the guest participant name.
  148. *
  149. * @param {string} displayName - Participant name.
  150. * @returns {void}
  151. */
  152. _setName(displayName) {
  153. this.props.updateSettings({
  154. displayName
  155. });
  156. }
  157. _closeDialog: () => void;
  158. /**
  159. * Closes the join by phone dialog.
  160. *
  161. * @returns {undefined}
  162. */
  163. _closeDialog() {
  164. this.props.setJoinByPhoneDialogVisiblity(false);
  165. }
  166. _showDialog: () => void;
  167. /**
  168. * Displays the dialog for joining a meeting by phone.
  169. *
  170. * @returns {undefined}
  171. */
  172. _showDialog() {
  173. this.props.setJoinByPhoneDialogVisiblity(true);
  174. this._onDropdownClose();
  175. }
  176. /**
  177. * Implements React's {@link Component#render()}.
  178. *
  179. * @inheritdoc
  180. * @returns {ReactElement}
  181. */
  182. render() {
  183. const {
  184. joinButtonDisabled,
  185. hasJoinByPhoneButton,
  186. joinConference,
  187. joinConferenceWithoutAudio,
  188. name,
  189. showCameraPreview,
  190. showDialog,
  191. t,
  192. videoTrack
  193. } = this.props;
  194. const { _closeDialog, _onCheckboxChange, _onDropdownClose, _onOptionsClick, _setName, _showDialog } = this;
  195. const { showJoinByPhoneButtons } = this.state;
  196. return (
  197. <PreMeetingScreen
  198. footer = { this._renderFooter() }
  199. name = { name }
  200. title = { t('prejoin.joinMeeting') }
  201. videoMuted = { !showCameraPreview }
  202. videoTrack = { videoTrack }>
  203. <div className = 'prejoin-input-area-container'>
  204. <div className = 'prejoin-input-area'>
  205. <InputField
  206. onChange = { _setName }
  207. onSubmit = { joinConference }
  208. placeHolder = { t('dialog.enterDisplayName') }
  209. value = { name } />
  210. <div className = 'prejoin-preview-dropdown-container'>
  211. <InlineDialog
  212. content = { <div className = 'prejoin-preview-dropdown-btns'>
  213. <div
  214. className = 'prejoin-preview-dropdown-btn'
  215. onClick = { joinConferenceWithoutAudio }>
  216. <Icon
  217. className = 'prejoin-preview-dropdown-icon'
  218. size = { 24 }
  219. src = { IconVolumeOff } />
  220. { t('prejoin.joinWithoutAudio') }
  221. </div>
  222. {hasJoinByPhoneButton && <div
  223. className = 'prejoin-preview-dropdown-btn'
  224. onClick = { _showDialog }>
  225. <Icon
  226. className = 'prejoin-preview-dropdown-icon'
  227. size = { 24 }
  228. src = { IconPhone } />
  229. { t('prejoin.joinAudioByPhone') }
  230. </div>}
  231. </div> }
  232. isOpen = { showJoinByPhoneButtons }
  233. onClose = { _onDropdownClose }>
  234. <ActionButton
  235. disabled = { joinButtonDisabled }
  236. hasOptions = { true }
  237. onClick = { joinConference }
  238. onOptionsClick = { _onOptionsClick }
  239. type = 'primary'>
  240. { t('prejoin.joinMeeting') }
  241. </ActionButton>
  242. </InlineDialog>
  243. </div>
  244. </div>
  245. <div className = 'prejoin-checkbox-container'>
  246. <input
  247. className = 'prejoin-checkbox'
  248. onChange = { _onCheckboxChange }
  249. type = 'checkbox' />
  250. <span>{t('prejoin.doNotShow')}</span>
  251. </div>
  252. </div>
  253. { showDialog && (
  254. <JoinByPhoneDialog
  255. joinConferenceWithoutAudio = { joinConferenceWithoutAudio }
  256. onClose = { _closeDialog } />
  257. )}
  258. </PreMeetingScreen>
  259. );
  260. }
  261. /**
  262. * Renders the screen footer if any.
  263. *
  264. * @returns {React$Element}
  265. */
  266. _renderFooter() {
  267. return this.props.deviceStatusVisible && <DeviceStatus />;
  268. }
  269. }
  270. /**
  271. * Maps (parts of) the redux state to the React {@code Component} props.
  272. *
  273. * @param {Object} state - The redux state.
  274. * @returns {Object}
  275. */
  276. function mapStateToProps(state): Object {
  277. const name = getDisplayName(state);
  278. const joinButtonDisabled = isDisplayNameRequired(state) && !name;
  279. return {
  280. joinButtonDisabled,
  281. name,
  282. deviceStatusVisible: isDeviceStatusVisible(state),
  283. roomName: getRoomName(state),
  284. showDialog: isJoinByPhoneDialogVisible(state),
  285. hasJoinByPhoneButton: isJoinByPhoneButtonVisible(state),
  286. showCameraPreview: !isVideoMutedByUser(state),
  287. videoTrack: getLocalJitsiVideoTrack(state)
  288. };
  289. }
  290. const mapDispatchToProps = {
  291. joinConferenceWithoutAudio: joinConferenceWithoutAudioAction,
  292. joinConference: joinConferenceAction,
  293. setJoinByPhoneDialogVisiblity: setJoinByPhoneDialogVisiblityAction,
  294. setSkipPrejoin: setSkipPrejoinAction,
  295. updateSettings
  296. };
  297. export default connect(mapStateToProps, mapDispatchToProps)(translate(Prejoin));