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.7KB

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