If you are only interested in one-to-one chat rooms, you can simply clone the starter project from GitHub and follow this tutorial instructions to learn how to implement the feature. Prerequisites You need to have the following prerequisites to work with this tutorial: Knowledge of TypeScript Required by both Nest. Recent versions of Ons.
In our starter project we have added a public chat room where registered users can meet and start chatting with each other in group. This means everyone can see what others are saying in the chat room.
Creating and ing rooms According to the docs : Each user can be a member of many rooms. Rooms can be used for chats or group chats; Chatkit does not differentiate between the two concepts at the room level. You can create private or public rooms.
You can create a room using the currentUser. This way we make it very easy to check if a room is already created.
We get the rooms of the current user using this. Otherwise, we call the createRoom method to create the private room. Since this method is asynchronous, we need to subscribe to the returned RxJS subject to get the room ID.
We also store the retrieved Lonely housewives from Gould room ID in the roomId variable of the component. This way we can call it from the other methods of the component. After ho, we call the connectToRoom method of ChatService to subscribe the current user to the room identified by the retrieved ID.
Note: We added the async keyword before the ngOnInit hook because we are using the await keyword in the body. Otherwise we send the message to the general public room.
OnDestroy is an Angular interface that defines the ngOnDestroy life-cycle hook which gets called when a component, directive, pipe, or service is destroyed. The logout method go AuthService is already defined in the tutorials.
You can get the source code of this demo from this GitHub repository.