John
John

Reputation: 480

Socket io rooms (MEAN stack)

I am building a buy and sell website that is built on MEAN stack. Im planning to use socket.io. So here's how my website will work

  1. User will register and login
  2. They can post an item either buy/sell
  3. Other users can offer to the post (i'll use socket.io on this so that the user who posted the item will have a notification)
  4. The poster will have an option to view the current offers, then they will choose who'll they accept.
  5. Once they accept the offer, both the Poster and the User who offered will have a communication both of them (Chat room)

So when the poster accepted the offer of the customer, it will open a chat for them to communicate. So here's my question, i will use socket io rooms. Once the poster accepts the offer, both of them will join the room (so i'll generate a room for them and automatically join them) then this room will be saved to the MongoDB, then every message they'll send, it will be saved to the database. So that they can see the history of their message even though they logout.

Is this the best method?

Upvotes: 1

Views: 459

Answers (1)

zoecarver
zoecarver

Reputation: 6403

That would probably be the best way to do it. Here is a similar question is there a good way to save socket.io message history it shows how to save the message history.

You do not have to save the messages, but if you would like to be able to see messages later, you should save every message to a database. If you do not save every message to a database, when you reload the page all previous messages will disappear.

If you want a free database, mongoLab will host small mongoose databases for free. Here is a good tutorial showing how to use mongoLab, it does not use socket.io, but it will probably be very easy to implement it.

Hope this helps! Feel free to ask any questions below.

Upvotes: 1

Related Questions