1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-11-11 20:22:36 +03:00

playMedia only if necessary

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
Šimon Brandner
2021-07-29 08:45:32 +02:00
parent 537ce40f42
commit ae64765870

View File

@@ -22,6 +22,7 @@ import { CallFeed, CallFeedEvent } from 'matrix-js-sdk/src/webrtc/callFeed';
import { logger } from 'matrix-js-sdk/src/logger';
import MemberAvatar from "../avatars/MemberAvatar";
import { replaceableComponent } from "../../../utils/replaceableComponent";
import { objectHasDiff } from '../../../utils/objects';
interface IProps {
call: MatrixCall;
@@ -46,7 +47,6 @@ interface IState {
videoMuted: boolean;
}
// TODO: We shouldn't be calling playMedia() all the time
@replaceableComponent("views.voip.VideoFeed")
export default class VideoFeed extends React.PureComponent<IProps, IState> {
private element: HTMLVideoElement;
@@ -69,8 +69,10 @@ export default class VideoFeed extends React.PureComponent<IProps, IState> {
this.updateFeed(this.props.feed, null);
}
componentDidUpdate(prevProps: IProps) {
componentDidUpdate(prevProps: IProps, prevState: IState) {
this.updateFeed(prevProps.feed, this.props.feed);
// If the mutes state has changed, we try to playMedia()
if (prevState.videoMuted !== this.state.videoMuted) this.playMedia();
}
static getDerivedStateFromProps(props: IProps) {
@@ -142,7 +144,7 @@ export default class VideoFeed extends React.PureComponent<IProps, IState> {
}
private onNewStream = async () => {
await this.setState({
this.setState({
audioMuted: this.props.feed.isAudioMuted(),
videoMuted: this.props.feed.isVideoMuted(),
});
@@ -150,11 +152,10 @@ export default class VideoFeed extends React.PureComponent<IProps, IState> {
};
private onMuteStateChanged = async () => {
await this.setState({
this.setState({
audioMuted: this.props.feed.isAudioMuted(),
videoMuted: this.props.feed.isVideoMuted(),
});
this.playMedia();
};
private onResize = (e) => {