Hi, so I’m looking to build a live chat app with Meteor and React. I know how to fetch and send data from my MongoDB database, but I was wondering how should I build this live chat feature? In other words - how do I trigger a change on the client side when the database holding my messages between 2 users is updated? Polling the database every X seconds is a way but I highly doubt that that’s the way to go.
That video is quite a bit old. Meteor’s react-meteor-data package now has a useTracker hook and a withTracker HOC so mixins won’t be necessary.
As far as getting started with react and meteor, https://react-tutorial.meteor.com/ is a good resource to get started with. Once you are familiar with how react integrates with meteor, socialize:messaging could be of interest for the live chat.
Thank you, I will check this out. I’ve done quite a bit with Meteor/React but not this aspect specifically. I’ll check out how to use the useTracker hook with this.
I did this some time ago. Basically, I made a collection with messages, filtered by the server on userid.
Then, clientside, I watched for changes in the collection:
Do you have any references to which I can see how you implemented it? I understand the concept but I’m not quite sure about its implementation. Where does this observe function come from?
observe is just a callback you can recieve on any changes on the collection:
this way, if a document is added to the collection, you get “notified” by the callback that something happened. It is then up to you to decide what to do with the (added) document.
Clientside I just have a clacks.find({}) to recieve all the clacks for me.
Go to “officer dashboard” and you’ll see a messages section there. The code is very rudimentary (been like this for about 8 years) and like the other poster said it just tracks changes in a “messages” collection. Not sure how scalable, but our sites are all limited user sites.