Hey everybody,
I’m developing a chat application with Meteor and try now to implement a “Is typing…” notification. My problem is, that I don’t know the way how I should implement it.
2: Using a Socket.IO connection and sending events with timeout - but that means, that I’ve to use a second connection for each user (Meteor Instance and Socket.IO Instance) - also it is possible, that the client doesn’t support web sockets.
That are my 2 ideas how to implement it. Are there any other “better” ways to implement that function?
Agreed with @ahref, it’s unnecessary to write this to db and would become a performance issue fast when scaling. Another alternative would be to write it all yourself using streams, so feel free to use what fits you more: http://arunoda.github.io/meteor-streams/
Agree on some kind of streams implementation for performance. Makes your stack more complex though so would start with a simple update of the already available collection and later “upgrade” to a stream solution unless you are already expecting performance issues.
Actually everything required is already in your stack. Your clients maintain a websocket connection to the server. Use it for realtime messages, don’t use collections.
Implementing a collection level handler for this feature is just bad practice and will still lead to additional code not to mention unnecessary template re-runs.
Why not finish the rest of the app before you worry about syncronised UX experiences.
@ahref Thank you for the plugin recommendation. I’ve now implemented the “streamy” plugin, works fine, only problem now is when a user has multiple instances running (f.e. smartphone and web browser), then only the latest will get a notification (I save the socket id as a single value to my user profile). Think a solution would be if I save all socket ids of a user to an array in my user collection. But at this time, I don’t need it .
Does streams really work for this? Last I knew streams didn’t scale to multiple instances properly. Also what happens when you have several people in a chat conversation and you need to show the typing message to each of them? I don’t think a couple small updates to a field on a collection is going to be a huge performance bottleneck.
If you take a look at my socialize:messaging package it uses a participants collection which has a record for each participant in the conversation and a field called typing. Using the provided typing subscription you can subscribe when typing begins and it will update typing field of the participant record the current user, then you can stop the subscription when typing stops and it will update the record again.
This allows you to display the typing status to multiple users that are participating in the conversation even if they are all connected to many different instances of your application.
Hi, this is a similar question to what I tried to check once. For us it was and is best to use collections but not storing to database, just publish the data to a local mini mongo collection but only change the one and only record. See MeteorPads in the comment. Maybe this is a good decision for you too.