Recommended way to build a chat?


In my app, I would need to create chat rooms between 2 users (to fix appointments).

What is the most elegant way to do so?

Meteor Streams? Create a new collection for every chatroom? One big collection for all the chats?



1 Like

webrtc. They are entirely client side, they don’t require a connection to the server. This way you save money and get scalability.

There are plenty of wrappers, check the exceptional work from Feross , or PeerJS

One big collection for all the chats. Put a roomId field on each document in the Messages collection and then, in a template helper:

return Messages.find({roomId: currentRoomId});

But there are probably some drop in packages that will do what you want:

Jumping in, what would be the best approach if you’d want to branch out and have a 1-1 but also a 1-many? Would you still have one big collection and then have an array of userids to filter who can see what?

@muaddib What do you mean save money? You spend way more time implementing webrtc - saving text to collection is not expensive in any way. If you’re using Meteor and not it’s collections then why use Meteor?

Use one collection for all chats. You get the Meteor magic, it’s easy to write and you get to keep chat history.

@tejpen just make you app to allow any number of users to one room so 1-1 or 1-X wouldn’t matter.

@babrahams makes sense.

My messaging package provides both single and multi user chat capabilities…

@KristerV webrtc doesn’t touch the server. Data and video is p2p. It saves you bandwidth, and allow 1 server to handle 10k concurrent users. has a chat module (supporting rooms, autocomplete input, and more) which I am planning to refactor out into a standalone package.

The implementation of the chatrooms might be interesting for you to look at. It should also be available as a drop-in to your app once the package is out.

1 Like

yeah, but then why would you use Meteor in the first place?

What’s worse is, why would you suggest a beginner webrtc if he/she hasn’t gotten to know Meteor or perhaps even JS?

That’s your app, I don’t know anything about it, so I can’t help you. Is it a production app or a toy for learning?

What I know is that if you use the wrong tool for a problem, sooner or later it will bite you in the ass. And collections are the wrong tool for a chat.

I’m a noob too, but I feel at ease with simple-peers from Feross. He’s a genius, using and reading his code will make you a better JS developer, just like following @arunoda makes you a better Meteor developer.

I disagree that collections are the wrong tool for a chat. It might be the wrong tool for a ephemeral, high-volume chat without the need for history, which WebRTC would be good for - but definitely not the wrong tool for all different types of chat.

1 Like

you are right. They are wrong as a flamethrower is the wrong tool to kill a fly. You can do it, but if not webrtc why not websockets?

collections are really overkill imho. Plus you have the file share scenario, where without webrtc you are forced to spend a lot of money

1 Like

Any Updates on the package?

No, sorry — I’ve moved on to other projects now. But you should feel free to rip the chatroom out of that one, the relevant aspects of the code are mostly clearly delineated.