element-web/src/components/views/voip/IncomingCallBox.tsx

139 lines
4.2 KiB
TypeScript
Raw Normal View History

2020-07-06 21:42:46 +00: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-06 21:42:46 +00:00
import React from 'react';
import {MatrixClientPeg} from '../../../MatrixClientPeg';
import dis from '../../../dispatcher/dispatcher';
import { _t } from '../../../languageHandler';
import { ActionPayload } from '../../../dispatcher/payloads';
import CallHandler from '../../../CallHandler';
import RoomAvatar from '../avatars/RoomAvatar';
import FormButton from '../elements/FormButton';
2020-12-17 17:16:00 +00:00
import { CallState } from 'matrix-js-sdk/src/webrtc/call';
2020-07-06 21:42:46 +00:00
interface IProps {
}
interface IState {
incomingCall: any;
}
2020-07-17 21:56:58 +00:00
export default class IncomingCallBox extends React.Component<IProps, IState> {
2020-07-06 21:42:46 +00:00
private dispatcherRef: string;
constructor(props: IProps) {
super(props);
2020-07-07 14:40:05 +00:00
this.dispatcherRef = dis.register(this.onAction);
2020-07-06 21:42:46 +00:00
this.state = {
incomingCall: null,
2020-07-07 14:40:05 +00:00
};
2020-07-06 21:42:46 +00:00
}
public componentWillUnmount() {
dis.unregister(this.dispatcherRef);
}
private onAction = (payload: ActionPayload) => {
switch (payload.action) {
case 'call_state': {
const call = CallHandler.sharedInstance().getCallForRoom(payload.room_id);
if (call && call.state === CallState.Ringing) {
2020-07-06 21:42:46 +00:00
this.setState({
incomingCall: call,
});
} else {
this.setState({
incomingCall: null,
});
}
}
2020-07-06 21:42:46 +00:00
}
2020-07-07 14:40:05 +00:00
};
2020-07-06 21:42:46 +00:00
private onAnswerClick: React.MouseEventHandler = (e) => {
e.stopPropagation();
dis.dispatch({
action: 'answer',
room_id: this.state.incomingCall.roomId,
});
2020-07-07 14:40:05 +00:00
};
2020-07-06 21:42:46 +00:00
private onRejectClick: React.MouseEventHandler = (e) => {
e.stopPropagation();
dis.dispatch({
action: 'reject',
2020-07-06 21:42:46 +00:00
room_id: this.state.incomingCall.roomId,
});
2020-07-07 14:40:05 +00:00
};
2020-07-06 21:42:46 +00:00
public render() {
if (!this.state.incomingCall) {
return null;
}
let room = null;
if (this.state.incomingCall) {
room = MatrixClientPeg.get().getRoom(this.state.incomingCall.roomId);
}
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");
}
}
2020-07-17 21:56:58 +00:00
return <div className="mx_IncomingCallBox">
<div className="mx_IncomingCallBox_CallerInfo">
<RoomAvatar
room={room}
height={32}
width={32}
/>
2020-07-06 21:42:46 +00:00
<div>
<h1>{caller}</h1>
<p>{incomingCallText}</p>
</div>
</div>
2020-07-17 21:56:58 +00:00
<div className="mx_IncomingCallBox_buttons">
2020-07-06 21:42:46 +00:00
<FormButton
2020-07-17 21:56:58 +00:00
className={"mx_IncomingCallBox_decline"}
2020-07-06 21:42:46 +00:00
onClick={this.onRejectClick}
kind="danger"
label={_t("Decline")}
/>
2020-07-17 21:56:58 +00:00
<div className="mx_IncomingCallBox_spacer" />
2020-07-06 21:42:46 +00:00
<FormButton
2020-07-17 21:56:58 +00:00
className={"mx_IncomingCallBox_accept"}
2020-07-06 21:42:46 +00:00
onClick={this.onAnswerClick}
kind="primary"
label={_t("Accept")}
/>
</div>
</div>;
}
}