Do not render the audio element if there is no audio track
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
parent
adddb0f0d2
commit
5c2abd291a
1 changed files with 21 additions and 1 deletions
|
@ -23,9 +23,21 @@ interface IProps {
|
||||||
feed: CallFeed,
|
feed: CallFeed,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class AudioFeed extends React.Component<IProps> {
|
interface IState {
|
||||||
|
audioMuted: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class AudioFeed extends React.Component<IProps, IState> {
|
||||||
private element = createRef<HTMLAudioElement>();
|
private element = createRef<HTMLAudioElement>();
|
||||||
|
|
||||||
|
constructor(props: IProps) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
audioMuted: this.props.feed.isAudioMuted(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.feed.addListener(CallFeedEvent.NewStream, this.onNewStream);
|
this.props.feed.addListener(CallFeedEvent.NewStream, this.onNewStream);
|
||||||
this.playMedia();
|
this.playMedia();
|
||||||
|
@ -38,6 +50,7 @@ export default class AudioFeed extends React.Component<IProps> {
|
||||||
|
|
||||||
private playMedia() {
|
private playMedia() {
|
||||||
const element = this.element.current;
|
const element = this.element.current;
|
||||||
|
if (!element) return;
|
||||||
const audioOutput = CallMediaHandler.getAudioOutput();
|
const audioOutput = CallMediaHandler.getAudioOutput();
|
||||||
|
|
||||||
if (audioOutput) {
|
if (audioOutput) {
|
||||||
|
@ -75,6 +88,7 @@ export default class AudioFeed extends React.Component<IProps> {
|
||||||
|
|
||||||
private stopMedia() {
|
private stopMedia() {
|
||||||
const element = this.element.current;
|
const element = this.element.current;
|
||||||
|
if (!element) return;
|
||||||
|
|
||||||
element.pause();
|
element.pause();
|
||||||
element.src = null;
|
element.src = null;
|
||||||
|
@ -86,10 +100,16 @@ export default class AudioFeed extends React.Component<IProps> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private onNewStream = () => {
|
private onNewStream = () => {
|
||||||
|
this.setState({
|
||||||
|
audioMuted: this.props.feed.isAudioMuted(),
|
||||||
|
});
|
||||||
this.playMedia();
|
this.playMedia();
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
// Do not render the audio element if there is no audio track
|
||||||
|
if (this.state.audioMuted) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<audio ref={this.element} />
|
<audio ref={this.element} />
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue