2021-07-24 19:05:14 +08:00
|
|
|
/*
|
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
|
|
|
Copyright 2018 New Vector Ltd
|
|
|
|
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
|
|
|
|
Copyright 2021 Šimon Brandner <simon.bra.ag@gmail.com>
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from "react";
|
|
|
|
import { CallType, MatrixCall } from "matrix-js-sdk/src/webrtc/call";
|
|
|
|
import classNames from "classnames";
|
2021-10-23 06:23:32 +08:00
|
|
|
|
2022-08-31 03:13:39 +08:00
|
|
|
import LegacyCallHandler, { LegacyCallHandlerEvent } from "../LegacyCallHandler";
|
2021-07-24 19:05:14 +08:00
|
|
|
import { MatrixClientPeg } from "../MatrixClientPeg";
|
|
|
|
import { _t } from "../languageHandler";
|
|
|
|
import RoomAvatar from "../components/views/avatars/RoomAvatar";
|
|
|
|
import AccessibleTooltipButton from "../components/views/elements/AccessibleTooltipButton";
|
|
|
|
import AccessibleButton from "../components/views/elements/AccessibleButton";
|
|
|
|
|
2022-08-31 03:13:39 +08:00
|
|
|
export const getIncomingLegacyCallToastKey = (callId: string) => `call_${callId}`;
|
2021-07-24 19:05:14 +08:00
|
|
|
|
|
|
|
interface IProps {
|
|
|
|
call: MatrixCall;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IState {
|
|
|
|
silenced: boolean;
|
|
|
|
}
|
|
|
|
|
2022-08-31 03:13:39 +08:00
|
|
|
export default class IncomingLegacyCallToast extends React.Component<IProps, IState> {
|
2021-07-24 19:05:14 +08:00
|
|
|
constructor(props: IProps) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2022-08-31 03:13:39 +08:00
|
|
|
silenced: LegacyCallHandler.instance.isCallSilenced(this.props.call.callId),
|
2021-07-24 19:05:14 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-07-26 16:34:59 +08:00
|
|
|
public componentDidMount = (): void => {
|
2022-08-31 03:13:39 +08:00
|
|
|
LegacyCallHandler.instance.addListener(
|
|
|
|
LegacyCallHandlerEvent.SilencedCallsChanged,
|
|
|
|
this.onSilencedCallsChanged,
|
|
|
|
);
|
2021-07-24 19:05:14 +08:00
|
|
|
};
|
|
|
|
|
2021-07-25 14:06:11 +08:00
|
|
|
public componentWillUnmount(): void {
|
2022-08-31 03:13:39 +08:00
|
|
|
LegacyCallHandler.instance.removeListener(
|
|
|
|
LegacyCallHandlerEvent.SilencedCallsChanged,
|
|
|
|
this.onSilencedCallsChanged,
|
|
|
|
);
|
2021-07-24 19:05:14 +08:00
|
|
|
}
|
|
|
|
|
2021-07-25 14:06:11 +08:00
|
|
|
private onSilencedCallsChanged = (): void => {
|
2022-08-31 03:13:39 +08:00
|
|
|
this.setState({ silenced: LegacyCallHandler.instance.isCallSilenced(this.props.call.callId) });
|
2021-07-24 19:05:14 +08:00
|
|
|
};
|
|
|
|
|
2021-08-04 22:30:03 +08:00
|
|
|
private onAnswerClick = (e: React.MouseEvent): void => {
|
2021-07-24 19:05:14 +08:00
|
|
|
e.stopPropagation();
|
2022-08-31 03:13:39 +08:00
|
|
|
LegacyCallHandler.instance.answerCall(LegacyCallHandler.instance.roomIdForCall(this.props.call));
|
2021-07-24 19:05:14 +08:00
|
|
|
};
|
|
|
|
|
2021-07-25 14:06:11 +08:00
|
|
|
private onRejectClick = (e: React.MouseEvent): void => {
|
2021-07-24 19:05:14 +08:00
|
|
|
e.stopPropagation();
|
2022-08-31 03:13:39 +08:00
|
|
|
LegacyCallHandler.instance.hangupOrReject(LegacyCallHandler.instance.roomIdForCall(this.props.call), true);
|
2021-07-24 19:05:14 +08:00
|
|
|
};
|
|
|
|
|
2021-07-25 14:06:11 +08:00
|
|
|
private onSilenceClick = (e: React.MouseEvent): void => {
|
2021-07-24 19:05:14 +08:00
|
|
|
e.stopPropagation();
|
|
|
|
const callId = this.props.call.callId;
|
|
|
|
this.state.silenced
|
2022-08-31 03:13:39 +08:00
|
|
|
? LegacyCallHandler.instance.unSilenceCall(callId)
|
|
|
|
: LegacyCallHandler.instance.silenceCall(callId);
|
2021-07-24 19:05:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
public render() {
|
|
|
|
const call = this.props.call;
|
2022-08-31 03:13:39 +08:00
|
|
|
const room = MatrixClientPeg.get().getRoom(LegacyCallHandler.instance.roomIdForCall(call));
|
2021-07-25 01:12:12 +08:00
|
|
|
const isVoice = call.type === CallType.Voice;
|
2022-10-17 17:16:04 +08:00
|
|
|
const callForcedSilent = LegacyCallHandler.instance.isForcedSilent();
|
|
|
|
|
|
|
|
let silenceButtonTooltip = this.state.silenced ? _t("Sound on") : _t("Silence call");
|
|
|
|
if (callForcedSilent) {
|
|
|
|
silenceButtonTooltip = _t("Notifications silenced");
|
|
|
|
}
|
2021-07-24 19:05:14 +08:00
|
|
|
|
2022-08-31 03:13:39 +08:00
|
|
|
const contentClass = classNames("mx_IncomingLegacyCallToast_content", {
|
|
|
|
mx_IncomingLegacyCallToast_content_voice: isVoice,
|
|
|
|
mx_IncomingLegacyCallToast_content_video: !isVoice,
|
2021-07-25 01:12:12 +08:00
|
|
|
});
|
2022-08-31 03:13:39 +08:00
|
|
|
const silenceClass = classNames("mx_IncomingLegacyCallToast_iconButton", {
|
|
|
|
mx_IncomingLegacyCallToast_unSilence: this.state.silenced,
|
|
|
|
mx_IncomingLegacyCallToast_silence: !this.state.silenced,
|
2021-07-24 19:05:14 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
2022-08-31 03:13:39 +08:00
|
|
|
<RoomAvatar room={room ?? undefined} height={32} width={32} />
|
2021-07-25 01:12:12 +08:00
|
|
|
<div className={contentClass}>
|
2022-08-31 03:13:39 +08:00
|
|
|
<span className="mx_LegacyCallEvent_caller">{room ? room.name : _t("Unknown caller")}</span>
|
|
|
|
<div className="mx_LegacyCallEvent_type">
|
|
|
|
<div className="mx_LegacyCallEvent_type_icon" />
|
2021-07-25 01:30:37 +08:00
|
|
|
{isVoice ? _t("Voice call") : _t("Video call")}
|
2022-12-12 19:24:14 +08:00
|
|
|
</div>
|
2022-08-31 03:13:39 +08:00
|
|
|
<div className="mx_IncomingLegacyCallToast_buttons">
|
2021-07-24 20:04:22 +08:00
|
|
|
<AccessibleButton
|
2022-08-31 03:13:39 +08:00
|
|
|
className="mx_IncomingLegacyCallToast_button mx_IncomingLegacyCallToast_button_decline"
|
2021-07-24 20:04:22 +08:00
|
|
|
onClick={this.onRejectClick}
|
|
|
|
kind="danger"
|
2022-12-12 19:24:14 +08:00
|
|
|
>
|
2021-07-25 01:12:12 +08:00
|
|
|
<span> {_t("Decline")} </span>
|
2021-07-24 20:04:22 +08:00
|
|
|
</AccessibleButton>
|
|
|
|
<AccessibleButton
|
2022-08-31 03:13:39 +08:00
|
|
|
className="mx_IncomingLegacyCallToast_button mx_IncomingLegacyCallToast_button_accept"
|
2021-07-24 20:04:22 +08:00
|
|
|
onClick={this.onAnswerClick}
|
|
|
|
kind="primary"
|
2022-12-12 19:24:14 +08:00
|
|
|
>
|
2021-07-25 01:12:12 +08:00
|
|
|
<span> {_t("Accept")} </span>
|
2021-07-24 20:04:22 +08:00
|
|
|
</AccessibleButton>
|
2022-12-12 19:24:14 +08:00
|
|
|
</div>
|
2021-07-25 01:30:37 +08:00
|
|
|
</div>
|
2021-07-24 20:04:22 +08:00
|
|
|
<AccessibleTooltipButton
|
2022-08-31 03:13:39 +08:00
|
|
|
className={silenceClass}
|
|
|
|
disabled={callForcedSilent}
|
2021-07-25 02:39:44 +08:00
|
|
|
onClick={this.onSilenceClick}
|
2022-10-17 17:16:04 +08:00
|
|
|
title={silenceButtonTooltip}
|
2021-07-25 02:39:44 +08:00
|
|
|
/>
|
2021-07-24 19:05:14 +08:00
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|