2020-07-07 00:42:46 +03:00
|
|
|
/*
|
|
|
|
Copyright 2017, 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
2020-07-18 00:55:30 +03:00
|
|
|
import CallView from "./CallView";
|
2020-07-07 00:42:46 +03:00
|
|
|
import RoomViewStore from '../../../stores/RoomViewStore';
|
|
|
|
import CallHandler from '../../../CallHandler';
|
|
|
|
import dis from '../../../dispatcher/dispatcher';
|
|
|
|
import { ActionPayload } from '../../../dispatcher/payloads';
|
|
|
|
import PersistentApp from "../elements/PersistentApp";
|
|
|
|
import SettingsStore from "../../../settings/SettingsStore";
|
2020-10-29 20:56:24 +03:00
|
|
|
import { CallState, MatrixCall } from 'matrix-js-sdk/src/webrtc/call';
|
2020-07-07 00:42:46 +03:00
|
|
|
|
|
|
|
interface IProps {
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IState {
|
|
|
|
roomId: string;
|
2020-10-09 20:56:07 +03:00
|
|
|
activeCall: MatrixCall;
|
2020-07-07 00:42:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export default class CallPreview extends React.Component<IProps, IState> {
|
|
|
|
private roomStoreToken: any;
|
|
|
|
private dispatcherRef: string;
|
2020-07-07 17:11:08 +03:00
|
|
|
private settingsWatcherRef: string;
|
2020-07-07 00:42:46 +03:00
|
|
|
|
|
|
|
constructor(props: IProps) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
roomId: RoomViewStore.getRoomId(),
|
2020-09-24 18:16:20 +03:00
|
|
|
activeCall: CallHandler.sharedInstance().getAnyActiveCall(),
|
2020-07-07 00:42:46 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public componentDidMount() {
|
|
|
|
this.roomStoreToken = RoomViewStore.addListener(this.onRoomViewStoreUpdate);
|
|
|
|
this.dispatcherRef = dis.register(this.onAction);
|
|
|
|
}
|
|
|
|
|
|
|
|
public componentWillUnmount() {
|
|
|
|
if (this.roomStoreToken) {
|
|
|
|
this.roomStoreToken.remove();
|
|
|
|
}
|
|
|
|
dis.unregister(this.dispatcherRef);
|
2020-07-07 17:40:05 +03:00
|
|
|
SettingsStore.unwatchSetting(this.settingsWatcherRef);
|
2020-07-07 00:42:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private onRoomViewStoreUpdate = (payload) => {
|
|
|
|
if (RoomViewStore.getRoomId() === this.state.roomId) return;
|
|
|
|
this.setState({
|
|
|
|
roomId: RoomViewStore.getRoomId(),
|
|
|
|
});
|
2020-07-07 17:40:05 +03:00
|
|
|
};
|
2020-07-07 00:42:46 +03:00
|
|
|
|
|
|
|
private onAction = (payload: ActionPayload) => {
|
|
|
|
switch (payload.action) {
|
|
|
|
// listen for call state changes to prod the render method, which
|
|
|
|
// may hide the global CallView if the call it is tracking is dead
|
|
|
|
case 'call_state':
|
|
|
|
this.setState({
|
2020-09-24 18:16:20 +03:00
|
|
|
activeCall: CallHandler.sharedInstance().getAnyActiveCall(),
|
2020-07-07 00:42:46 +03:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
2020-07-07 17:40:05 +03:00
|
|
|
};
|
2020-07-07 00:42:46 +03:00
|
|
|
|
|
|
|
private onCallViewClick = () => {
|
2020-09-24 18:16:20 +03:00
|
|
|
const call = CallHandler.sharedInstance().getAnyActiveCall();
|
2020-07-07 00:42:46 +03:00
|
|
|
if (call) {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room',
|
2020-10-09 20:56:07 +03:00
|
|
|
room_id: call.roomId,
|
2020-07-07 00:42:46 +03:00
|
|
|
});
|
|
|
|
}
|
2020-07-07 17:40:05 +03:00
|
|
|
};
|
2020-07-07 00:42:46 +03:00
|
|
|
|
|
|
|
public render() {
|
2020-09-24 18:16:20 +03:00
|
|
|
const callForRoom = CallHandler.sharedInstance().getCallForRoom(this.state.roomId);
|
2020-07-17 23:02:51 +03:00
|
|
|
const showCall = (
|
|
|
|
this.state.activeCall &&
|
2020-10-09 20:56:07 +03:00
|
|
|
this.state.activeCall.state === CallState.Connected &&
|
2020-07-17 23:02:51 +03:00
|
|
|
!callForRoom
|
|
|
|
);
|
|
|
|
|
|
|
|
if (showCall) {
|
|
|
|
return (
|
|
|
|
<CallView
|
2020-07-20 17:15:21 +03:00
|
|
|
className="mx_CallPreview"
|
|
|
|
onClick={this.onCallViewClick}
|
2020-07-17 23:02:51 +03:00
|
|
|
showHangup={true}
|
|
|
|
/>
|
2020-07-07 00:42:46 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-07-17 23:02:51 +03:00
|
|
|
return <PersistentApp />;
|
2020-07-07 00:42:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|