2020-12-03 20:45:49 +03:00
|
|
|
/*
|
|
|
|
Copyright 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 { CallState, MatrixCall } from 'matrix-js-sdk/src/webrtc/call';
|
|
|
|
import React from 'react';
|
2021-04-28 12:56:26 +03:00
|
|
|
import CallHandler, { CallHandlerEvent } from '../../../CallHandler';
|
2020-12-03 20:45:49 +03:00
|
|
|
import CallView from './CallView';
|
|
|
|
import dis from '../../../dispatcher/dispatcher';
|
2021-03-02 22:33:19 +03:00
|
|
|
import {Resizable} from "re-resizable";
|
2021-03-02 16:09:11 +03:00
|
|
|
import ResizeNotifier from "../../../utils/ResizeNotifier";
|
2021-03-09 06:20:07 +03:00
|
|
|
import {replaceableComponent} from "../../../utils/replaceableComponent";
|
2020-12-03 20:45:49 +03:00
|
|
|
|
|
|
|
interface IProps {
|
|
|
|
// What room we should display the call for
|
|
|
|
roomId: string,
|
|
|
|
|
|
|
|
// maxHeight style attribute for the video panel
|
|
|
|
maxVideoHeight?: number;
|
|
|
|
|
2021-03-02 16:09:11 +03:00
|
|
|
resizeNotifier: ResizeNotifier,
|
2020-12-03 20:45:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
interface IState {
|
|
|
|
call: MatrixCall,
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wrapper for CallView that always display the call in a given room,
|
|
|
|
* or nothing if there is no call in that room.
|
|
|
|
*/
|
2021-03-09 06:20:07 +03:00
|
|
|
@replaceableComponent("views.voip.CallViewForRoom")
|
2020-12-03 20:45:49 +03:00
|
|
|
export default class CallViewForRoom extends React.Component<IProps, IState> {
|
|
|
|
private dispatcherRef: string;
|
|
|
|
|
|
|
|
constructor(props: IProps) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
call: this.getCall(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public componentDidMount() {
|
|
|
|
this.dispatcherRef = dis.register(this.onAction);
|
2021-04-28 12:56:26 +03:00
|
|
|
CallHandler.sharedInstance().addListener(CallHandlerEvent.CallChangeRoom, this.updateCall);
|
2020-12-03 20:45:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public componentWillUnmount() {
|
|
|
|
dis.unregister(this.dispatcherRef);
|
2021-04-28 12:56:26 +03:00
|
|
|
CallHandler.sharedInstance().removeListener(CallHandlerEvent.CallChangeRoom, this.updateCall);
|
2020-12-03 20:45:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private onAction = (payload) => {
|
|
|
|
switch (payload.action) {
|
|
|
|
case 'call_state': {
|
2021-04-28 12:56:26 +03:00
|
|
|
this.updateCall();
|
2020-12-03 20:45:49 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-04-28 12:56:26 +03:00
|
|
|
private updateCall = () => {
|
|
|
|
const newCall = this.getCall();
|
|
|
|
if (newCall !== this.state.call) {
|
|
|
|
this.setState({call: newCall});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-12-03 20:45:49 +03:00
|
|
|
private getCall(): MatrixCall {
|
|
|
|
const call = CallHandler.sharedInstance().getCallForRoom(this.props.roomId);
|
|
|
|
|
|
|
|
if (call && [CallState.Ended, CallState.Ringing].includes(call.state)) return null;
|
|
|
|
return call;
|
|
|
|
}
|
|
|
|
|
2021-03-22 09:40:36 +03:00
|
|
|
private onResizeStart = () => {
|
2021-03-02 22:33:19 +03:00
|
|
|
this.props.resizeNotifier.startResizing();
|
2021-03-22 09:44:37 +03:00
|
|
|
};
|
2021-03-02 22:33:19 +03:00
|
|
|
|
2021-03-22 09:40:36 +03:00
|
|
|
private onResize = () => {
|
2021-03-02 22:33:19 +03:00
|
|
|
this.props.resizeNotifier.notifyTimelineHeightChanged();
|
2021-03-22 09:44:37 +03:00
|
|
|
};
|
2021-03-02 22:33:19 +03:00
|
|
|
|
2021-03-22 09:40:36 +03:00
|
|
|
private onResizeStop = () => {
|
2021-03-02 22:33:19 +03:00
|
|
|
this.props.resizeNotifier.stopResizing();
|
2021-03-22 09:44:37 +03:00
|
|
|
};
|
2021-03-02 22:33:19 +03:00
|
|
|
|
2020-12-03 20:45:49 +03:00
|
|
|
public render() {
|
|
|
|
if (!this.state.call) return null;
|
2021-03-02 22:33:19 +03:00
|
|
|
// We subtract 8 as it the margin-bottom of the mx_CallViewForRoom_ResizeWrapper
|
|
|
|
const maxHeight = this.props.maxVideoHeight - 8;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="mx_CallViewForRoom">
|
|
|
|
<Resizable
|
2021-03-07 17:05:13 +03:00
|
|
|
minHeight={380}
|
2021-03-02 22:33:19 +03:00
|
|
|
maxHeight={maxHeight}
|
|
|
|
enable={{
|
|
|
|
top: false,
|
|
|
|
right: false,
|
|
|
|
bottom: true,
|
|
|
|
left: false,
|
|
|
|
topRight: false,
|
|
|
|
bottomRight: false,
|
|
|
|
bottomLeft: false,
|
|
|
|
topLeft: false,
|
|
|
|
}}
|
|
|
|
onResizeStart={this.onResizeStart}
|
|
|
|
onResize={this.onResize}
|
|
|
|
onResizeStop={this.onResizeStop}
|
|
|
|
className="mx_CallViewForRoom_ResizeWrapper"
|
|
|
|
handleClasses={{bottom: "mx_CallViewForRoom_ResizeHandle"}}
|
|
|
|
>
|
|
|
|
<CallView
|
|
|
|
call={this.state.call}
|
|
|
|
pipMode={false}
|
|
|
|
/>
|
|
|
|
</Resizable>
|
|
|
|
</div>
|
|
|
|
);
|
2020-12-03 20:45:49 +03:00
|
|
|
}
|
|
|
|
}
|