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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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, toggleChat } 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. * Maps redux actions to the props of the component.
  53. *
  54. * @param {Function} dispatch - The redux action {@code dispatch} function.
  55. * @returns {{
  56. * _onSendMessage: Function,
  57. * _onToggleChat: Function
  58. * }}
  59. * @private
  60. */
  61. export function _mapDispatchToProps(dispatch: Dispatch<any>) {
  62. return {
  63. /**
  64. * Toggles the chat window.
  65. *
  66. * @returns {Function}
  67. */
  68. _onToggleChat() {
  69. dispatch(toggleChat());
  70. },
  71. /**
  72. * Sends a text message.
  73. *
  74. * @private
  75. * @param {string} text - The text message to be sent.
  76. * @returns {void}
  77. * @type {Function}
  78. */
  79. _onSendMessage(text: string) {
  80. dispatch(sendMessage(text));
  81. }
  82. };
  83. }
  84. /**
  85. * Maps (parts of) the redux state to {@link Chat} React {@code Component}
  86. * props.
  87. *
  88. * @param {Object} state - The redux store/state.
  89. * @private
  90. * @returns {{
  91. * _isOpen: boolean,
  92. * _messages: Array<Object>,
  93. * _showNamePrompt: boolean
  94. * }}
  95. */
  96. export function _mapStateToProps(state: Object) {
  97. const { isOpen, messages } = state['features/chat'];
  98. const _localParticipant = getLocalParticipant(state);
  99. return {
  100. _isModal: isMobileBrowser()
  101. ? window.innerWidth <= MOBILE_SMALL_WIDTH_THRESHOLD
  102. : window.innerWidth <= DESKTOP_SMALL_WIDTH_THRESHOLD,
  103. _isOpen: isOpen,
  104. _messages: messages,
  105. _showNamePrompt: !_localParticipant.name
  106. };
  107. }