Skip to content
Snippets Groups Projects
Commit 19027476 authored by lazorfuzz's avatar lazorfuzz
Browse files

Fix video chat example

parent 3559b4b1
No related branches found
No related tags found
No related merge requests found
...@@ -129,6 +129,7 @@ class Party extends Component { ...@@ -129,6 +129,7 @@ class Party extends Component {
this.state = { this.state = {
nick: this.props.nick, nick: this.props.nick,
roomID: `party-${this.props.roomName}`, roomID: `party-${this.props.roomName}`,
peers: [],
muted: false, muted: false,
camPaused: false camPaused: false
}; };
...@@ -145,6 +146,7 @@ class Party extends Component { ...@@ -145,6 +146,7 @@ class Party extends Component {
autoRequestMedia: true, autoRequestMedia: true,
// Optional: nickname // Optional: nickname
nick: this.state.nick, nick: this.state.nick,
debug: true
}); });
this.webrtc.on('videoAdded', this.addVideo); this.webrtc.on('videoAdded', this.addVideo);
...@@ -155,11 +157,15 @@ class Party extends Component { ...@@ -155,11 +157,15 @@ class Party extends Component {
} }
addVideo = (stream, peer) => { addVideo = (stream, peer) => {
this.webrtc.attachStream(stream, this.remoteVideos[peer.id]); this.setState({ peers: [...this.state.peers, peer] }, () => {
this.webrtc.attachStream(stream, this.remoteVideos[peer.id]);
});
} }
removeVideo = (peer) => { removeVideo = (peer) => {
// Clean up video this.setState({
peers: this.state.peers.filter(p => !p.closed)
});
} }
handleConnectionError = (peer) => { handleConnectionError = (peer) => {
...@@ -175,10 +181,9 @@ class Party extends Component { ...@@ -175,10 +181,9 @@ class Party extends Component {
} }
// Show fellow peers in the room // Show fellow peers in the room
generateRemotes = () => this.webrtc.getPeers().map((p) => ( generateRemotes = () => this.state.peers.map((p) => (
<div key={p.id}> <div key={p.id}>
// The video parent container needs a special id <div id={/* The video container needs a special id */ `${this.webrtc.getContainerId(p)}`}>
<div id={`${this.webrtc.getContainerId(p)}`}>
<video <video
key={this.webrtc.getId(p)} key={this.webrtc.getId(p)}
// Important: The video element needs both an id and ref // Important: The video element needs both an id and ref
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment