Move call controls into a separate method

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
Šimon Brandner 2021-06-12 16:32:01 +02:00
parent 9a67851479
commit 6d29c19804
No known key found for this signature in database
GPG key ID: 9760693FDD98A790

View file

@ -421,40 +421,14 @@ export default class CallView extends React.Component<IProps, IState> {
this.props.call.transferToCall(transfereeCall); this.props.call.transferToCall(transfereeCall);
} }
public render() { private onHangupClick = () => {
const client = MatrixClientPeg.get(); dis.dispatch({
const callRoomId = CallHandler.sharedInstance().roomIdForCall(this.props.call); action: 'hangup',
const secondaryCallRoomId = CallHandler.sharedInstance().roomIdForCall(this.props.secondaryCall); room_id: CallHandler.sharedInstance().roomIdForCall(this.props.call),
const callRoom = client.getRoom(callRoomId); });
const secCallRoom = this.props.secondaryCall ? client.getRoom(secondaryCallRoomId) : null;
let dialPad;
let contextMenu;
if (this.state.showDialpad) {
dialPad = <DialpadContextMenu
{...alwaysAboveRightOf(
this.dialpadButton.current.getBoundingClientRect(),
ChevronFace.None,
CONTEXT_MENU_VPADDING,
)}
onFinished={this.closeDialpad}
call={this.props.call}
/>;
}
if (this.state.showMoreMenu) {
contextMenu = <CallContextMenu
{...alwaysAboveLeftOf(
this.contextMenuButton.current.getBoundingClientRect(),
ChevronFace.None,
CONTEXT_MENU_VPADDING,
)}
onFinished={this.closeContextMenu}
call={this.props.call}
/>;
} }
private renderCallControls(): JSX.Element {
const micClasses = classNames({ const micClasses = classNames({
mx_CallView_callControls_button: true, mx_CallView_callControls_button: true,
mx_CallView_callControls_button_micOn: !this.state.micMuted, mx_CallView_callControls_button_micOn: !this.state.micMuted,
@ -494,16 +468,22 @@ export default class CallView extends React.Component<IProps, IState> {
mx_CallView_callControls_hidden: !this.state.controlsVisible, mx_CallView_callControls_hidden: !this.state.controlsVisible,
}); });
const vidMuteButton = this.props.call.type === CallType.Video ? <AccessibleButton // We don't support call upgrades (yet) so hide the video mute button in voice calls
let vidMuteButton;
if (this.props.call.type === CallType.Video) {
vidMuteButton = (
<AccessibleButton
className={vidClasses} className={vidClasses}
onClick={this.onVidMuteClick} onClick={this.onVidMuteClick}
/> : null; />
);
}
let screensharingButton;
// Screensharing is possible, if we can send a second stream and // Screensharing is possible, if we can send a second stream and
// identify it using SDPStreamMetadata or if we can replace the already // identify it using SDPStreamMetadata or if we can replace the already
// existing usermedia track by a screensharing track. We also need to be // existing usermedia track by a screensharing track. We also need to be
// connected to know the state of the other side // connected to know the state of the other side
let screensharingButton;
if ( if (
(this.props.call.opponentSupportsSDPStreamMetadata() || this.props.call.type === CallType.Video) && (this.props.call.opponentSupportsSDPStreamMetadata() || this.props.call.type === CallType.Video) &&
this.props.call.state === CallState.Connected this.props.call.state === CallState.Connected
@ -532,9 +512,8 @@ export default class CallView extends React.Component<IProps, IState> {
isExpanded={this.state.showMoreMenu} isExpanded={this.state.showMoreMenu}
/> : <div className="mx_CallView_callControls_button mx_CallView_callControls_button_more_hidden" />; /> : <div className="mx_CallView_callControls_button mx_CallView_callControls_button_more_hidden" />;
// in the near future, the dial pad button will go on the left. For now, it's the nothing button return (
// because something needs to have margin-right: auto to make the alignment correct. <div className={callControlsClasses}>
const callControls = <div className={callControlsClasses}>
{ dialpadButton } { dialpadButton }
<AccessibleButton <AccessibleButton
className={micClasses} className={micClasses}
@ -542,29 +521,30 @@ export default class CallView extends React.Component<IProps, IState> {
/> />
<AccessibleButton <AccessibleButton
className="mx_CallView_callControls_button mx_CallView_callControls_button_hangup" className="mx_CallView_callControls_button mx_CallView_callControls_button_hangup"
onClick={() => { onClick={this.onHangupClick}
dis.dispatch({
action: 'hangup',
room_id: callRoomId,
});
}}
/> />
{ vidMuteButton } { vidMuteButton }
{ screensharingButton } { screensharingButton }
<div className={micCacheClasses} /> <div className={micCacheClasses} />
<div className={vidCacheClasses} /> <div className={vidCacheClasses} />
{ contextMenuButton } { contextMenuButton }
</div>; </div>
);
}
public render() {
const client = MatrixClientPeg.get();
const callRoomId = CallHandler.sharedInstance().roomIdForCall(this.props.call);
const secondaryCallRoomId = CallHandler.sharedInstance().roomIdForCall(this.props.secondaryCall);
const callRoom = client.getRoom(callRoomId);
const secCallRoom = this.props.secondaryCall ? client.getRoom(secondaryCallRoomId) : null;
const avatarSize = this.props.pipMode ? 76 : 160; const avatarSize = this.props.pipMode ? 76 : 160;
// The 'content' for the call, ie. the videos for a video call and profile picture
// for voice calls (fills the bg)
let contentView: React.ReactNode;
const transfereeCall = CallHandler.sharedInstance().getTransfereeForCallId(this.props.call.callId); const transfereeCall = CallHandler.sharedInstance().getTransfereeForCallId(this.props.call.callId);
const isOnHold = this.state.isLocalOnHold || this.state.isRemoteOnHold; const isOnHold = this.state.isLocalOnHold || this.state.isRemoteOnHold;
let contentView: React.ReactNode;
let holdTransferContent; let holdTransferContent;
if (transfereeCall) { if (transfereeCall) {
const transferTargetRoom = MatrixClientPeg.get().getRoom( const transferTargetRoom = MatrixClientPeg.get().getRoom(
CallHandler.sharedInstance().roomIdForCall(this.props.call), CallHandler.sharedInstance().roomIdForCall(this.props.call),
@ -640,7 +620,7 @@ export default class CallView extends React.Component<IProps, IState> {
<div className={containerClasses} ref={this.contentRef} onMouseMove={this.onMouseMove}> <div className={containerClasses} ref={this.contentRef} onMouseMove={this.onMouseMove}>
{ onHoldBackground } { onHoldBackground }
{ holdTransferContent } { holdTransferContent }
{callControls} { this.renderCallControls() }
</div> </div>
); );
} else { } else {
@ -665,7 +645,7 @@ export default class CallView extends React.Component<IProps, IState> {
</div> </div>
</div> </div>
{ holdTransferContent } { holdTransferContent }
{callControls} { this.renderCallControls() }
</div> </div>
); );
} }
@ -700,7 +680,7 @@ export default class CallView extends React.Component<IProps, IState> {
</div> </div>
</div> </div>
<div className="mx_CallView_holdTransferContent">{_t("Connecting")}</div> <div className="mx_CallView_holdTransferContent">{_t("Connecting")}</div>
{callControls} { this.renderCallControls() }
</div> </div>
); );
} else { } else {
@ -739,7 +719,7 @@ export default class CallView extends React.Component<IProps, IState> {
onResize={this.props.onResize} onResize={this.props.onResize}
primary={true} primary={true}
/> />
{ callControls } { this.renderCallControls() }
</div> </div>
); );
} }
@ -803,6 +783,32 @@ export default class CallView extends React.Component<IProps, IState> {
myClassName = 'mx_CallView_pip'; myClassName = 'mx_CallView_pip';
} }
let dialPad;
if (this.state.showDialpad) {
dialPad = <DialpadContextMenu
{...alwaysAboveRightOf(
this.dialpadButton.current.getBoundingClientRect(),
ChevronFace.None,
CONTEXT_MENU_VPADDING,
)}
onFinished={this.closeDialpad}
call={this.props.call}
/>;
}
let contextMenu;
if (this.state.showMoreMenu) {
contextMenu = <CallContextMenu
{...alwaysAboveLeftOf(
this.contextMenuButton.current.getBoundingClientRect(),
ChevronFace.None,
CONTEXT_MENU_VPADDING,
)}
onFinished={this.closeContextMenu}
call={this.props.call}
/>;
}
return <div className={"mx_CallView " + myClassName}> return <div className={"mx_CallView " + myClassName}>
{ header } { header }
{ contentView } { contentView }