Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

AbstractLobbyScreen.tsx 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. import React, { PureComponent } from 'react';
  2. import { IReduxState, IStore } from '../../app/types';
  3. import { conferenceWillJoin } from '../../base/conference/actions';
  4. import { getConferenceName } from '../../base/conference/functions';
  5. import { IJitsiConference } from '../../base/conference/reducer';
  6. import { getSecurityUiConfig } from '../../base/config/functions.any';
  7. import { INVITE_ENABLED } from '../../base/flags/constants';
  8. import { getFeatureFlag } from '../../base/flags/functions';
  9. import { getLocalParticipant } from '../../base/participants/functions';
  10. import { getFieldValue } from '../../base/react/functions';
  11. import { updateSettings } from '../../base/settings/actions';
  12. import { IMessage } from '../../chat/types';
  13. import { isDeviceStatusVisible } from '../../prejoin/functions';
  14. import { cancelKnocking, joinWithPassword, onSendMessage, setPasswordJoinFailed, startKnocking } from '../actions';
  15. export const SCREEN_STATES = {
  16. EDIT: 1,
  17. PASSWORD: 2,
  18. VIEW: 3
  19. };
  20. export interface IProps {
  21. /**
  22. * Indicates whether the device status should be visible.
  23. */
  24. _deviceStatusVisible: boolean;
  25. /**
  26. * Indicates whether the message that display name is required is shown.
  27. */
  28. _isDisplayNameRequiredActive: boolean;
  29. /**
  30. * True if moderator initiated a chat session with the participant.
  31. */
  32. _isLobbyChatActive: boolean;
  33. /**
  34. * True if knocking is already happening, so we're waiting for a response.
  35. */
  36. _knocking: boolean;
  37. /**
  38. * Lobby messages between moderator and the participant.
  39. */
  40. _lobbyChatMessages: IMessage[];
  41. /**
  42. * Name of the lobby chat recipient.
  43. */
  44. _lobbyMessageRecipient?: string;
  45. /**
  46. * The name of the meeting we're about to join.
  47. */
  48. _meetingName: string;
  49. /**
  50. * The members only conference if any,.
  51. */
  52. _membersOnlyConference?: IJitsiConference;
  53. /**
  54. * The email of the participant about to knock/join.
  55. */
  56. _participantEmail?: string;
  57. /**
  58. * The id of the participant about to knock/join. This is the participant ID in the lobby room, at this point.
  59. */
  60. _participantId?: string;
  61. /**
  62. * The name of the participant about to knock/join.
  63. */
  64. _participantName?: string;
  65. /**
  66. * True if a recent attempt to join with password failed.
  67. */
  68. _passwordJoinFailed: boolean;
  69. /**
  70. * True if the password field should be available for lobby participants.
  71. */
  72. _renderPassword: boolean;
  73. /**
  74. * The Redux dispatch function.
  75. */
  76. dispatch: IStore['dispatch'];
  77. /**
  78. * Indicates whether the copy url button should be shown.
  79. */
  80. showCopyUrlButton: boolean;
  81. /**
  82. * Function to be used to translate i18n labels.
  83. */
  84. t: Function;
  85. }
  86. interface IState {
  87. /**
  88. * The display name value entered into the field.
  89. */
  90. displayName: string;
  91. /**
  92. * The email value entered into the field.
  93. */
  94. email: string;
  95. /**
  96. * True if lobby chat widget is open.
  97. */
  98. isChatOpen: boolean;
  99. /**
  100. * The password value entered into the field.
  101. */
  102. password: string;
  103. /**
  104. * True if a recent attempt to join with password failed.
  105. */
  106. passwordJoinFailed: boolean;
  107. /**
  108. * The state of the screen. One of {@code SCREEN_STATES[*]}.
  109. */
  110. screenState: number;
  111. }
  112. /**
  113. * Abstract class to encapsulate the platform common code of the {@code LobbyScreen}.
  114. */
  115. export default class AbstractLobbyScreen<P extends IProps = IProps> extends PureComponent<P, IState> {
  116. /**
  117. * Instantiates a new component.
  118. *
  119. * @inheritdoc
  120. */
  121. constructor(props: P) {
  122. super(props);
  123. this.state = {
  124. displayName: props._participantName || '',
  125. email: props._participantEmail || '',
  126. isChatOpen: true,
  127. password: '',
  128. passwordJoinFailed: false,
  129. screenState: props._participantName ? SCREEN_STATES.VIEW : SCREEN_STATES.EDIT
  130. };
  131. this._onAskToJoin = this._onAskToJoin.bind(this);
  132. this._onCancel = this._onCancel.bind(this);
  133. this._onChangeDisplayName = this._onChangeDisplayName.bind(this);
  134. this._onChangeEmail = this._onChangeEmail.bind(this);
  135. this._onChangePassword = this._onChangePassword.bind(this);
  136. this._onEnableEdit = this._onEnableEdit.bind(this);
  137. this._onJoinWithPassword = this._onJoinWithPassword.bind(this);
  138. this._onSendMessage = this._onSendMessage.bind(this);
  139. this._onSwitchToKnockMode = this._onSwitchToKnockMode.bind(this);
  140. this._onSwitchToPasswordMode = this._onSwitchToPasswordMode.bind(this);
  141. this._onToggleChat = this._onToggleChat.bind(this);
  142. }
  143. /**
  144. * Implements {@code PureComponent.getDerivedStateFromProps}.
  145. *
  146. * @inheritdoc
  147. */
  148. static getDerivedStateFromProps(props: IProps, state: IState) {
  149. if (props._passwordJoinFailed && !state.passwordJoinFailed) {
  150. return {
  151. password: '',
  152. passwordJoinFailed: true
  153. };
  154. }
  155. return null;
  156. }
  157. /**
  158. * Returns the screen title.
  159. *
  160. * @returns {string}
  161. */
  162. _getScreenTitleKey() {
  163. const { screenState } = this.state;
  164. const passwordPrompt = screenState === SCREEN_STATES.PASSWORD;
  165. return !passwordPrompt && this.props._knocking
  166. ? this.props._isLobbyChatActive ? 'lobby.lobbyChatStartedTitle' : 'lobby.joiningTitle'
  167. : passwordPrompt ? 'lobby.enterPasswordTitle' : 'lobby.joinTitle';
  168. }
  169. /**
  170. * Callback to be invoked when the user submits the joining request.
  171. *
  172. * @returns {void}
  173. */
  174. _onAskToJoin() {
  175. this.setState({
  176. password: ''
  177. });
  178. this.props.dispatch(startKnocking());
  179. return false;
  180. }
  181. /**
  182. * Callback to be invoked when the user cancels the dialog.
  183. *
  184. * @private
  185. * @returns {boolean}
  186. */
  187. _onCancel() {
  188. this.props.dispatch(cancelKnocking());
  189. return true;
  190. }
  191. /**
  192. * Callback to be invoked when the user changes its display name.
  193. *
  194. * @param {SyntheticEvent} event - The SyntheticEvent instance of the change.
  195. * @returns {void}
  196. */
  197. _onChangeDisplayName(event: { target: { value: string; }; } | string) {
  198. const displayName = getFieldValue(event);
  199. this.setState({
  200. displayName
  201. }, () => {
  202. this.props.dispatch(updateSettings({
  203. displayName
  204. }));
  205. });
  206. }
  207. /**
  208. * Callback to be invoked when the user changes its email.
  209. *
  210. * @param {SyntheticEvent} event - The SyntheticEvent instance of the change.
  211. * @returns {void}
  212. */
  213. _onChangeEmail(event: { target: { value: string; }; } | string) {
  214. const email = getFieldValue(event);
  215. this.setState({
  216. email
  217. }, () => {
  218. this.props.dispatch(updateSettings({
  219. email
  220. }));
  221. });
  222. }
  223. /**
  224. * Callback to be invoked when the user changes the password.
  225. *
  226. * @param {SyntheticEvent} event - The SyntheticEvent instance of the change.
  227. * @returns {void}
  228. */
  229. _onChangePassword(event: { target: { value: string; }; } | string) {
  230. this.setState({
  231. password: getFieldValue(event)
  232. });
  233. }
  234. /**
  235. * Callback to be invoked for the edit button.
  236. *
  237. * @returns {void}
  238. */
  239. _onEnableEdit() {
  240. this.setState({
  241. screenState: SCREEN_STATES.EDIT
  242. });
  243. }
  244. /**
  245. * Callback to be invoked when the user tries to join using a preset password.
  246. *
  247. * @returns {void}
  248. */
  249. _onJoinWithPassword() {
  250. this.setState({
  251. passwordJoinFailed: false
  252. });
  253. this.props.dispatch(joinWithPassword(this.state.password));
  254. }
  255. /**
  256. * Callback to be invoked for sending lobby chat messages.
  257. *
  258. * @param {string} message - Message to be sent.
  259. * @returns {void}
  260. */
  261. _onSendMessage(message: string) {
  262. this.props.dispatch(onSendMessage(message));
  263. }
  264. /**
  265. * Callback to be invoked for the enter (go back to) knocking mode button.
  266. *
  267. * @returns {void}
  268. */
  269. _onSwitchToKnockMode() {
  270. this.setState({
  271. password: '',
  272. screenState: this.state.displayName ? SCREEN_STATES.VIEW : SCREEN_STATES.EDIT
  273. });
  274. this.props.dispatch(setPasswordJoinFailed(false));
  275. // let's return to the correct state after password failed
  276. this.props.dispatch(conferenceWillJoin(this.props._membersOnlyConference));
  277. }
  278. /**
  279. * Callback to be invoked for the enter password button.
  280. *
  281. * @returns {void}
  282. */
  283. _onSwitchToPasswordMode() {
  284. this.setState({
  285. screenState: SCREEN_STATES.PASSWORD
  286. });
  287. }
  288. /**
  289. * Callback to be invoked for toggling lobby chat visibility.
  290. *
  291. * @returns {void}
  292. */
  293. _onToggleChat() {
  294. this.setState(_prevState => {
  295. return {
  296. isChatOpen: !_prevState.isChatOpen
  297. };
  298. });
  299. }
  300. /**
  301. * Renders the content of the dialog.
  302. *
  303. * @returns {React$Element}
  304. */
  305. _renderContent() {
  306. const { _knocking } = this.props;
  307. const { screenState } = this.state;
  308. if (screenState !== SCREEN_STATES.PASSWORD && _knocking) {
  309. return this._renderJoining();
  310. }
  311. return (
  312. <>
  313. { screenState === SCREEN_STATES.VIEW && this._renderParticipantInfo() }
  314. { screenState === SCREEN_STATES.EDIT && this._renderParticipantForm() }
  315. { screenState === SCREEN_STATES.PASSWORD && this._renderPasswordForm() }
  316. { (screenState === SCREEN_STATES.VIEW || screenState === SCREEN_STATES.EDIT)
  317. && this._renderStandardButtons() }
  318. { screenState === SCREEN_STATES.PASSWORD && this._renderPasswordJoinButtons() }
  319. </>
  320. );
  321. }
  322. /**
  323. * Renders the joining (waiting) fragment of the screen.
  324. *
  325. * @returns {React$Element}
  326. */
  327. _renderJoining() {
  328. return <></>;
  329. }
  330. /**
  331. * Renders the participant form to let the knocking participant enter its details.
  332. *
  333. * @returns {React$Element}
  334. */
  335. _renderParticipantForm() {
  336. return <></>;
  337. }
  338. /**
  339. * Renders the participant info fragment when we have all the required details of the user.
  340. *
  341. * @returns {React$Element}
  342. */
  343. _renderParticipantInfo() {
  344. return <></>;
  345. }
  346. /**
  347. * Renders the password form to let the participant join by using a password instead of knocking.
  348. *
  349. * @returns {React$Element}
  350. */
  351. _renderPasswordForm() {
  352. return <></>;
  353. }
  354. /**
  355. * Renders the password join button (set).
  356. *
  357. * @returns {React$Element}
  358. */
  359. _renderPasswordJoinButtons() {
  360. return <></>;
  361. }
  362. /**
  363. * Renders the standard (pre-knocking) button set.
  364. *
  365. * @returns {React$Element}
  366. */
  367. _renderStandardButtons() {
  368. return <></>;
  369. }
  370. }
  371. /**
  372. * Maps part of the Redux state to the props of this component.
  373. *
  374. * @param {Object} state - The Redux state.
  375. * @returns {IProps}
  376. */
  377. export function _mapStateToProps(state: IReduxState) {
  378. const localParticipant = getLocalParticipant(state);
  379. const participantId = localParticipant?.id;
  380. const inviteEnabledFlag = getFeatureFlag(state, INVITE_ENABLED, true);
  381. const { disableInviteFunctions } = state['features/base/config'];
  382. const { isDisplayNameRequiredError, knocking, passwordJoinFailed } = state['features/lobby'];
  383. const { iAmSipGateway } = state['features/base/config'];
  384. const { disableLobbyPassword } = getSecurityUiConfig(state);
  385. const showCopyUrlButton = inviteEnabledFlag || !disableInviteFunctions;
  386. const deviceStatusVisible = isDeviceStatusVisible(state);
  387. const { membersOnly } = state['features/base/conference'];
  388. const { isLobbyChatActive, lobbyMessageRecipient, messages } = state['features/chat'];
  389. return {
  390. _deviceStatusVisible: deviceStatusVisible,
  391. _isDisplayNameRequiredActive: Boolean(isDisplayNameRequiredError),
  392. _knocking: knocking,
  393. _lobbyChatMessages: messages,
  394. _lobbyMessageRecipient: lobbyMessageRecipient?.name,
  395. _isLobbyChatActive: isLobbyChatActive,
  396. _meetingName: getConferenceName(state),
  397. _membersOnlyConference: membersOnly,
  398. _participantEmail: localParticipant?.email,
  399. _participantId: participantId,
  400. _participantName: localParticipant?.name,
  401. _passwordJoinFailed: passwordJoinFailed,
  402. _renderPassword: !iAmSipGateway && !disableLobbyPassword,
  403. showCopyUrlButton
  404. };
  405. }