Adding client-side chat capabilities

When we wrote our authentication code, we relied heavily on putting services in place to take care of it. In a similar way, we are going to provide a chat service that provides the central point of the client-side socket messaging:

ng g s services/ChatMessages

Unsurprisingly, this service will also incorporate Socket in the constructor:

export class ChatMessagesService {
constructor(private socket: Socket) { }
}

When we send a message from the client to the server, we use the emit method on the socket. The text that we want to send from the user will be sent over by means of the message key:

public SendMessage = (message: string) => {
this.socket.emit('message', message);
};
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.67.166