This PR changes the logic for connecting / disconnecting conferences. Instead of doing it in mount / unmount events from the Conference component, it moves the logic to the appNavigatee action. This fixes a regression introduced in 774c5ecd when trying to make sure the conference terminated event is always sent. By moving the logic to appNavigate we no longer depend on side-effects for connecting / disconnecting, and the code should be more maintainable moving forward. An improvement to this is the concept of sessions, which, while not tackled here, was taken into consideration.
70 lines
1.8 KiB
JavaScript
70 lines
1.8 KiB
JavaScript
// @flow
|
|
|
|
import _ from 'lodash';
|
|
|
|
import { createToolbarEvent, sendAnalytics } from '../../analytics';
|
|
import { appNavigate } from '../../app';
|
|
import { disconnect } from '../../base/connection';
|
|
import { translate } from '../../base/i18n';
|
|
import { connect } from '../../base/redux';
|
|
import { AbstractHangupButton } from '../../base/toolbox';
|
|
import type { AbstractButtonProps } from '../../base/toolbox';
|
|
|
|
/**
|
|
* The type of the React {@code Component} props of {@link HangupButton}.
|
|
*/
|
|
type Props = AbstractButtonProps & {
|
|
|
|
/**
|
|
* The redux {@code dispatch} function.
|
|
*/
|
|
dispatch: Function
|
|
};
|
|
|
|
/**
|
|
* Component that renders a toolbar button for leaving the current conference.
|
|
*
|
|
* @extends AbstractHangupButton
|
|
*/
|
|
class HangupButton extends AbstractHangupButton<Props, *> {
|
|
_hangup: Function;
|
|
|
|
accessibilityLabel = 'toolbar.accessibilityLabel.hangup';
|
|
label = 'toolbar.hangup';
|
|
tooltip = 'toolbar.hangup';
|
|
|
|
/**
|
|
* Initializes a new HangupButton instance.
|
|
*
|
|
* @param {Props} props - The read-only properties with which the new
|
|
* instance is to be initialized.
|
|
*/
|
|
constructor(props: Props) {
|
|
super(props);
|
|
|
|
this._hangup = _.once(() => {
|
|
sendAnalytics(createToolbarEvent('hangup'));
|
|
|
|
// FIXME: these should be unified.
|
|
if (navigator.product === 'ReactNative') {
|
|
this.props.dispatch(appNavigate(undefined));
|
|
} else {
|
|
this.props.dispatch(disconnect(true));
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Helper function to perform the actual hangup action.
|
|
*
|
|
* @override
|
|
* @protected
|
|
* @returns {void}
|
|
*/
|
|
_doHangup() {
|
|
this._hangup();
|
|
}
|
|
}
|
|
|
|
export default translate(connect()(HangupButton));
|