Emitting newLoactionMessage

To get started, let's go ahead and move into Atom into server.js, and instead of emitting a newMessage event we're going to emit newLocationMessage:

socket.on('createLocationMessage', (coords) => { 
  io.emit('newLocationMessage', generateMessage('Admin', `${coords.latitude}, ${coords.longitude}`)); 
});

Now we don't have a handler for that over in index.js, but that's perfectly fine, we'll set that up later in the section. Now we are going to need to change the data we send across too. Currently, we're sending the plain text data; what we want to do is generate a URL. We're actually going to create a completely separate function for generating a location message, and we'll call it generateLocationMessage.

io.emit('newLocationMessage', ...

Get Advanced Node.js Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.