Properly handle feed prop updates
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
parent
97b976b171
commit
1b2b4714e1
1 changed files with 19 additions and 3 deletions
|
@ -60,14 +60,30 @@ export default class VideoFeed extends React.Component<IProps, IState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.feed.addListener(CallFeedEvent.NewStream, this.onNewStream);
|
this.updateFeed(null, this.props.feed);
|
||||||
this.playMedia();
|
this.playMedia();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
this.props.feed.removeListener(CallFeedEvent.NewStream, this.onNewStream);
|
this.updateFeed(this.props.feed, null);
|
||||||
this.element.current?.removeEventListener('resize', this.onResize);
|
this.element.current?.removeEventListener('resize', this.onResize);
|
||||||
this.stopMedia();
|
}
|
||||||
|
|
||||||
|
componentDidUpdate(prevProps: IProps) {
|
||||||
|
this.updateFeed(prevProps.feed, this.props.feed);
|
||||||
|
}
|
||||||
|
|
||||||
|
private updateFeed(oldFeed: CallFeed, newFeed: CallFeed) {
|
||||||
|
if (oldFeed === newFeed) return;
|
||||||
|
|
||||||
|
if (oldFeed) {
|
||||||
|
this.props.feed.removeListener(CallFeedEvent.NewStream, this.onNewStream);
|
||||||
|
this.stopMedia();
|
||||||
|
}
|
||||||
|
if (newFeed) {
|
||||||
|
this.props.feed.addListener(CallFeedEvent.NewStream, this.onNewStream);
|
||||||
|
this.playMedia();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private playMedia() {
|
private playMedia() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue