April 2018
Beginner to intermediate
406 pages
9h 33m
English
The dummy code is there, but it's not doing anything other than validating that we've done something good to start. Let's expand on that more by pushing a socket message up to the server. We'll start off by writing a function that is responsible for actually pushing the vote back up to the server. Place this function preceding to your onJoin function for now:
// Push the vote up to the serverconst pushVote = (el, channel) => { channel .push('vote', { option_id: el.getAttribute('data-option-id') }) .receive('ok', res => console.log('You Voted!')) .receive('error', res => console.log('Failed to vote:', res));};
We want to grab the current option ID for the button clicked and use that as part of ...