Created
July 2, 2018 14:49
-
-
Save bmorelli25/1510ae332fc6f8021021b02693dcbb0a to your computer and use it in GitHub Desktop.
Realtime Paint Application - canvas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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