Skip to content

Instantly share code, notes, and snippets.

@nkt
Created May 7, 2017 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkt/c6ece97a1703d363b9b1a292f7dbed7c to your computer and use it in GitHub Desktop.
Save nkt/c6ece97a1703d363b9b1a292f7dbed7c to your computer and use it in GitHub Desktop.
/**
* Copyright 2017 dialog LLC <info@dlg.im>
* @flow
*/
import React, { PureComponent } from 'react';
type Props = {
className: string,
stream: MediaSource
};
class CallVideoStream extends PureComponent {
props: Props;
video: ?HTMLVideoElement;
componentDidMount() {
if (this.video) {
if ('srcObject' in this.video) {
this.video.srcObject = this.props.stream;
} else {
this.video.src = URL.createObjectURL(this.props.stream);
}
this.video.play();
}
}
componentWillUnmount() {
if (this.video) {
if ('srcObject' in this.video) {
this.video.srcObject = null;
} else {
URL.revokeObjectURL(this.video.src);
this.video.src = null;
}
this.video = null;
}
}
setVideo = (video: ?HTMLVideoElement) => {
this.video = video;
};
render() {
return (
<video
ref={this.setVideo}
className={this.props.className}
/>
);
}
}
export default CallVideoStream;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment