April 2018
Beginner to intermediate
406 pages
9h 33m
English
Let's quickly add a little check into our code to make that problem go away. In assets/js/socket.js, we're going to wrap our channel connection code inside of a conditional:
// Only connect to the socket if the polls channel actually exists!if (document.getElementById('enable-polls-channel')) { // Create a channel to handle joining/sending/receiving const channel = socket.channel('polls:lobby', {}); // Next, join the topic on the channel! channel .join() .receive('ok', res => console.log('Joined channel:', res)) .receive('error', res => console.log('Failed to join channel:', res));}
If we refresh our browser on the homepage of our app we'll no longer see that 'Joined channel' message, which is good! If we ...