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.

AbstractChat.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // @flow
  2. import { Component } from 'react';
  3. import type { Dispatch } from 'redux';
  4. import { getLocalParticipant } from '../../base/participants';
  5. import { sendMessage } from '../actions';
  6. import { SMALL_WIDTH_THRESHOLD } from '../constants';
  7. /**
  8. * The type of the React {@code Component} props of {@code AbstractChat}.
  9. */
  10. export type Props = {
  11. /**
  12. * Whether the chat is opened in a modal or not (computed based on window width).
  13. */
  14. _isModal: boolean,
  15. /**
  16. * True if the chat window should be rendered.
  17. */
  18. _isOpen: boolean,
  19. /**
  20. * All the chat messages in the conference.
  21. */
  22. _messages: Array<Object>,
  23. /**
  24. * Function to send a text message.
  25. *
  26. * @protected
  27. */
  28. _onSendMessage: Function,
  29. /**
  30. * Function to toggle the chat window.
  31. */
  32. _onToggleChat: Function,
  33. /**
  34. * Whether or not to block chat access with a nickname input form.
  35. */
  36. _showNamePrompt: boolean,
  37. /**
  38. * The Redux dispatch function.
  39. */
  40. dispatch: Dispatch<any>,
  41. /**
  42. * Function to be used to translate i18n labels.
  43. */
  44. t: Function
  45. };
  46. /**
  47. * Implements an abstract chat panel.
  48. */
  49. export default class AbstractChat<P: Props> extends Component<P> {
  50. /**
  51. * Initializes a new {@code AbstractChat} instance.
  52. *
  53. * @param {Props} props - The React {@code Component} props to initialize
  54. * the new {@code AbstractChat} instance with.
  55. */
  56. constructor(props: P) {
  57. super(props);
  58. // Bind event handlers so they are only bound once per instance.
  59. this._onSendMessage = this._onSendMessage.bind(this);
  60. }
  61. _onSendMessage: (string) => void;
  62. /**
  63. * Sends a text message.
  64. *
  65. * @private
  66. * @param {string} text - The text message to be sent.
  67. * @returns {void}
  68. * @type {Function}
  69. */
  70. _onSendMessage(text: string) {
  71. this.props.dispatch(sendMessage(text));
  72. }
  73. }
  74. /**
  75. * Maps (parts of) the redux state to {@link Chat} React {@code Component}
  76. * props.
  77. *
  78. * @param {Object} state - The redux store/state.
  79. * @private
  80. * @returns {{
  81. * _isOpen: boolean,
  82. * _messages: Array<Object>,
  83. * _showNamePrompt: boolean
  84. * }}
  85. */
  86. export function _mapStateToProps(state: Object) {
  87. const { isOpen, messages } = state['features/chat'];
  88. const _localParticipant = getLocalParticipant(state);
  89. return {
  90. _isModal: window.innerWidth <= SMALL_WIDTH_THRESHOLD,
  91. _isOpen: isOpen,
  92. _messages: messages,
  93. _showNamePrompt: !_localParticipant?.name
  94. };
  95. }