Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

AbstractLobbyScreen.js 12KB

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