July 2019
Intermediate to advanced
416 pages
10h 6m
English
Before we add the actual component implementations, we are going to add in the rest of our server-side socket behavior. You may remember that we added the ability to read all the historical records and send them back to the newly connected client:
socket.on('joinRoom', (room: string) => { if (lastRoom !== '') { socket.leave(lastRoom); } if (room !== '') { socket.join(room); } this.messageDataAccess.GetAll({room: room}, {messageText: 1, _id: 0}).then((msgs: string[]) =>{ socket.emit('allMessages', msgs); }); lastRoom = room;});
What we have here is the server reacting to joinRoom coming over from the client. When we receive this event, we leave the last room if it has been set and then join the room that's passed ...
Read now
Unlock full access