2020-07-07 00:42:46 +03:00
|
|
|
/*
|
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
|
|
|
Copyright 2018 New Vector Ltd
|
|
|
|
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
2020-07-07 17:11:08 +03:00
|
|
|
|
2020-07-07 00:42:46 +03:00
|
|
|
import React from 'react';
|
2021-06-29 15:11:58 +03:00
|
|
|
import { MatrixClientPeg } from '../../../MatrixClientPeg';
|
2020-07-07 00:42:46 +03:00
|
|
|
import dis from '../../../dispatcher/dispatcher';
|
|
|
|
import { _t } from '../../../languageHandler';
|
|
|
|
import { ActionPayload } from '../../../dispatcher/payloads';
|
2021-06-19 20:30:19 +03:00
|
|
|
import CallHandler, { CallHandlerEvent } from '../../../CallHandler';
|
2020-07-07 00:42:46 +03:00
|
|
|
import RoomAvatar from '../avatars/RoomAvatar';
|
2021-06-21 17:44:09 +03:00
|
|
|
import AccessibleButton from '../elements/AccessibleButton';
|
2020-12-17 20:16:00 +03:00
|
|
|
import { CallState } from 'matrix-js-sdk/src/webrtc/call';
|
2021-06-29 15:11:58 +03:00
|
|
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
2021-05-22 21:24:36 +03:00
|
|
|
import AccessibleTooltipButton from '../elements/AccessibleTooltipButton';
|
|
|
|
import classNames from 'classnames';
|
2020-07-07 00:42:46 +03:00
|
|
|
|
|
|
|
interface IProps {
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IState {
|
|
|
|
incomingCall: any;
|
2021-05-22 21:24:36 +03:00
|
|
|
silenced: boolean;
|
2020-07-07 00:42:46 +03:00
|
|
|
}
|
|
|
|
|
2021-03-09 06:20:07 +03:00
|
|
|
@replaceableComponent("views.voip.IncomingCallBox")
|
2020-07-18 00:56:58 +03:00
|
|
|
export default class IncomingCallBox extends React.Component<IProps, IState> {
|
2020-07-07 00:42:46 +03:00
|
|
|
private dispatcherRef: string;
|
|
|
|
|
|
|
|
constructor(props: IProps) {
|
|
|
|
super(props);
|
|
|
|
|
2020-07-07 17:40:05 +03:00
|
|
|
this.dispatcherRef = dis.register(this.onAction);
|
2020-07-07 00:42:46 +03:00
|
|
|
this.state = {
|
|
|
|
incomingCall: null,
|
2021-05-22 21:24:36 +03:00
|
|
|
silenced: false,
|
2020-07-07 17:40:05 +03:00
|
|
|
};
|
2020-07-07 00:42:46 +03:00
|
|
|
}
|
|
|
|
|
2021-06-19 20:30:19 +03:00
|
|
|
componentDidMount = () => {
|
|
|
|
CallHandler.sharedInstance().addListener(CallHandlerEvent.SilencedCallsChanged, this.onSilencedCallsChanged);
|
2021-07-02 14:14:14 +03:00
|
|
|
};
|
2021-06-19 20:30:19 +03:00
|
|
|
|
2020-07-07 00:42:46 +03:00
|
|
|
public componentWillUnmount() {
|
|
|
|
dis.unregister(this.dispatcherRef);
|
2021-06-19 20:30:19 +03:00
|
|
|
CallHandler.sharedInstance().removeListener(CallHandlerEvent.SilencedCallsChanged, this.onSilencedCallsChanged);
|
2020-07-07 00:42:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private onAction = (payload: ActionPayload) => {
|
|
|
|
switch (payload.action) {
|
2020-08-29 03:11:08 +03:00
|
|
|
case 'call_state': {
|
2020-09-24 18:16:20 +03:00
|
|
|
const call = CallHandler.sharedInstance().getCallForRoom(payload.room_id);
|
2020-10-09 20:56:07 +03:00
|
|
|
if (call && call.state === CallState.Ringing) {
|
2020-07-07 00:42:46 +03:00
|
|
|
this.setState({
|
|
|
|
incomingCall: call,
|
2021-05-22 21:24:36 +03:00
|
|
|
silenced: false, // Reset silenced state for new call
|
2020-07-07 00:42:46 +03:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
incomingCall: null,
|
|
|
|
});
|
|
|
|
}
|
2020-08-29 03:11:08 +03:00
|
|
|
}
|
2020-07-07 00:42:46 +03:00
|
|
|
}
|
2020-07-07 17:40:05 +03:00
|
|
|
};
|
2020-07-07 00:42:46 +03:00
|
|
|
|
2021-06-19 20:30:19 +03:00
|
|
|
private onSilencedCallsChanged = () => {
|
|
|
|
const callId = this.state.incomingCall?.callId;
|
|
|
|
if (!callId) return;
|
|
|
|
this.setState({ silenced: CallHandler.sharedInstance().isCallSilenced(callId) });
|
2021-07-02 14:14:14 +03:00
|
|
|
};
|
2021-06-19 20:30:19 +03:00
|
|
|
|
2020-07-07 00:42:46 +03:00
|
|
|
private onAnswerClick: React.MouseEventHandler = (e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'answer',
|
2021-04-19 22:30:51 +03:00
|
|
|
room_id: CallHandler.sharedInstance().roomIdForCall(this.state.incomingCall),
|
2020-07-07 00:42:46 +03:00
|
|
|
});
|
2020-07-07 17:40:05 +03:00
|
|
|
};
|
2020-07-07 00:42:46 +03:00
|
|
|
|
|
|
|
private onRejectClick: React.MouseEventHandler = (e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
dis.dispatch({
|
2020-10-15 16:54:03 +03:00
|
|
|
action: 'reject',
|
2021-04-19 22:30:51 +03:00
|
|
|
room_id: CallHandler.sharedInstance().roomIdForCall(this.state.incomingCall),
|
2020-07-07 00:42:46 +03:00
|
|
|
});
|
2020-07-07 17:40:05 +03:00
|
|
|
};
|
2020-07-07 00:42:46 +03:00
|
|
|
|
2021-05-22 21:24:36 +03:00
|
|
|
private onSilenceClick: React.MouseEventHandler = (e) => {
|
|
|
|
e.stopPropagation();
|
2021-06-19 20:30:19 +03:00
|
|
|
const callId = this.state.incomingCall.callId;
|
|
|
|
this.state.silenced ?
|
|
|
|
CallHandler.sharedInstance().unSilenceCall(callId):
|
|
|
|
CallHandler.sharedInstance().silenceCall(callId);
|
2021-06-29 15:11:58 +03:00
|
|
|
};
|
2021-05-22 21:24:36 +03:00
|
|
|
|
2020-07-07 00:42:46 +03:00
|
|
|
public render() {
|
|
|
|
if (!this.state.incomingCall) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
let room = null;
|
|
|
|
if (this.state.incomingCall) {
|
2021-04-19 22:30:51 +03:00
|
|
|
room = MatrixClientPeg.get().getRoom(CallHandler.sharedInstance().roomIdForCall(this.state.incomingCall));
|
2020-07-07 00:42:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const caller = room ? room.name : _t("Unknown caller");
|
|
|
|
|
|
|
|
let incomingCallText = null;
|
|
|
|
if (this.state.incomingCall) {
|
|
|
|
if (this.state.incomingCall.type === "voice") {
|
|
|
|
incomingCallText = _t("Incoming voice call");
|
|
|
|
} else if (this.state.incomingCall.type === "video") {
|
|
|
|
incomingCallText = _t("Incoming video call");
|
|
|
|
} else {
|
|
|
|
incomingCallText = _t("Incoming call");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-22 21:24:36 +03:00
|
|
|
const silenceClass = classNames({
|
|
|
|
"mx_IncomingCallBox_iconButton": true,
|
|
|
|
"mx_IncomingCallBox_unSilence": this.state.silenced,
|
|
|
|
"mx_IncomingCallBox_silence": !this.state.silenced,
|
|
|
|
});
|
|
|
|
|
2020-07-18 00:56:58 +03:00
|
|
|
return <div className="mx_IncomingCallBox">
|
|
|
|
<div className="mx_IncomingCallBox_CallerInfo">
|
2020-11-12 21:09:56 +03:00
|
|
|
<RoomAvatar
|
|
|
|
room={room}
|
|
|
|
height={32}
|
|
|
|
width={32}
|
|
|
|
/>
|
2020-07-07 00:42:46 +03:00
|
|
|
<div>
|
2021-07-20 00:43:11 +03:00
|
|
|
<h1>{ caller }</h1>
|
|
|
|
<p>{ incomingCallText }</p>
|
2020-07-07 00:42:46 +03:00
|
|
|
</div>
|
2021-05-22 21:24:36 +03:00
|
|
|
<AccessibleTooltipButton
|
|
|
|
className={silenceClass}
|
|
|
|
onClick={this.onSilenceClick}
|
|
|
|
title={this.state.silenced ? _t("Sound on"): _t("Silence call")}
|
|
|
|
/>
|
2020-07-07 00:42:46 +03:00
|
|
|
</div>
|
2020-07-18 00:56:58 +03:00
|
|
|
<div className="mx_IncomingCallBox_buttons">
|
2021-06-21 17:44:09 +03:00
|
|
|
<AccessibleButton
|
2021-07-20 00:43:11 +03:00
|
|
|
className="mx_IncomingCallBox_decline"
|
2020-07-07 00:42:46 +03:00
|
|
|
onClick={this.onRejectClick}
|
|
|
|
kind="danger"
|
2021-06-21 16:16:37 +03:00
|
|
|
>
|
2021-06-22 12:06:31 +03:00
|
|
|
{ _t("Decline") }
|
2021-06-21 17:44:09 +03:00
|
|
|
</AccessibleButton>
|
2020-07-18 00:56:58 +03:00
|
|
|
<div className="mx_IncomingCallBox_spacer" />
|
2021-06-21 17:44:09 +03:00
|
|
|
<AccessibleButton
|
2021-07-20 00:43:11 +03:00
|
|
|
className="mx_IncomingCallBox_accept"
|
2020-07-07 00:42:46 +03:00
|
|
|
onClick={this.onAnswerClick}
|
|
|
|
kind="primary"
|
2021-06-21 16:16:37 +03:00
|
|
|
>
|
2021-06-22 12:06:31 +03:00
|
|
|
{ _t("Accept") }
|
2021-06-21 17:44:09 +03:00
|
|
|
</AccessibleButton>
|
2020-07-07 00:42:46 +03:00
|
|
|
</div>
|
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
}
|