Skip to content

Instantly share code, notes, and snippets.

@bmorelli25
Created July 2, 2018 14:49
Show Gist options
  • Save bmorelli25/1510ae332fc6f8021021b02693dcbb0a to your computer and use it in GitHub Desktop.
Save bmorelli25/1510ae332fc6f8021021b02693dcbb0a to your computer and use it in GitHub Desktop.
Realtime Paint Application - canvas
// canvas.js
...
import Pusher from 'pusher-js';
class Canvas extends Component {
constructor(props) {
super(props);
...
this.pusher = new Pusher('PUSHER_KEY', {
cluster: 'eu',
});
}
...
componentDidMount(){
...
const channel = this.pusher.subscribe('painting');
channel.bind('draw', (data) => {
const { userId, line } = data;
if (userId !== this.userId) {
line.forEach((position) => {
this.paint(position.start, position.stop, this.guestStrokeStyle);
});
}
});
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment