March 2018
Intermediate to advanced
592 pages
13h 44m
English
To broadcast a new user in the chat, we'll use socket.broadcast.emit and we'll emit a newMessage event, providing our props. The from property, once again, will be set equal to the Admin string; text is going to be set equal to our little message, New user joined; and last up is createdAt, which is going to be set equal to new Date by calling the Date().getTime method:
// socket.broadcast.emit from Admin text New user joinedsocket.broadcast.emit('newMessage', { from: 'Admin', text: 'New user joined', createdAt: new Date().getTime()})
Now we can remove our comment for the second call and everything should work as expected. The next thing you need to do is test out that all of this is working as expected ...