2019-01-13 19:34:38 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import { Component } from 'react';
|
2019-03-19 15:42:25 +00:00
|
|
|
import type { Dispatch } from 'redux';
|
2019-01-13 19:34:38 +00:00
|
|
|
|
|
|
|
import { getLocalParticipant } from '../../base/participants';
|
2021-02-12 11:18:16 +00:00
|
|
|
import { sendMessage } from '../actions';
|
2021-03-18 13:56:20 +00:00
|
|
|
import { SMALL_WIDTH_THRESHOLD } from '../constants';
|
2019-01-13 19:34:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of {@code AbstractChat}.
|
|
|
|
*/
|
|
|
|
export type Props = {
|
|
|
|
|
2021-01-12 13:24:55 +00:00
|
|
|
/**
|
|
|
|
* Whether the chat is opened in a modal or not (computed based on window width).
|
|
|
|
*/
|
|
|
|
_isModal: boolean,
|
|
|
|
|
2019-01-13 19:34:38 +00:00
|
|
|
/**
|
|
|
|
* True if the chat window should be rendered.
|
|
|
|
*/
|
|
|
|
_isOpen: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* All the chat messages in the conference.
|
|
|
|
*/
|
|
|
|
_messages: Array<Object>,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to send a text message.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
_onSendMessage: Function,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to toggle the chat window.
|
|
|
|
*/
|
|
|
|
_onToggleChat: Function,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not to block chat access with a nickname input form.
|
|
|
|
*/
|
|
|
|
_showNamePrompt: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Redux dispatch function.
|
|
|
|
*/
|
2019-03-19 15:42:25 +00:00
|
|
|
dispatch: Dispatch<any>,
|
2019-01-13 19:34:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to be used to translate i18n labels.
|
|
|
|
*/
|
|
|
|
t: Function
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements an abstract chat panel.
|
|
|
|
*/
|
2021-02-12 11:18:16 +00:00
|
|
|
export default class AbstractChat<P: Props> extends Component<P> {
|
2019-01-13 19:34:38 +00:00
|
|
|
|
2021-02-12 11:18:16 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new {@code AbstractChat} instance.
|
|
|
|
*
|
|
|
|
* @param {Props} props - The React {@code Component} props to initialize
|
|
|
|
* the new {@code AbstractChat} instance with.
|
|
|
|
*/
|
|
|
|
constructor(props: P) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
// Bind event handlers so they are only bound once per instance.
|
|
|
|
this._onSendMessage = this._onSendMessage.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
_onSendMessage: (string) => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a text message.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {string} text - The text message to be sent.
|
|
|
|
* @returns {void}
|
|
|
|
* @type {Function}
|
|
|
|
*/
|
|
|
|
_onSendMessage(text: string) {
|
|
|
|
this.props.dispatch(sendMessage(text));
|
|
|
|
}
|
2019-01-13 19:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the redux state to {@link Chat} React {@code Component}
|
|
|
|
* props.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The redux store/state.
|
|
|
|
* @private
|
|
|
|
* @returns {{
|
|
|
|
* _isOpen: boolean,
|
|
|
|
* _messages: Array<Object>,
|
|
|
|
* _showNamePrompt: boolean
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function _mapStateToProps(state: Object) {
|
|
|
|
const { isOpen, messages } = state['features/chat'];
|
|
|
|
const _localParticipant = getLocalParticipant(state);
|
|
|
|
|
|
|
|
return {
|
2021-03-18 13:56:20 +00:00
|
|
|
_isModal: window.innerWidth <= SMALL_WIDTH_THRESHOLD,
|
2019-01-13 19:34:38 +00:00
|
|
|
_isOpen: isOpen,
|
|
|
|
_messages: messages,
|
|
|
|
_showNamePrompt: !_localParticipant.name
|
|
|
|
};
|
|
|
|
}
|