How does Discourse update the client on new posts from the server?

Hey guys. My friend Declan and I were chatting on our forum’s Babble chat and we got curious how the chat plugin updates clients when a new message is sent in chat. I said “It probably uses the same code behind-the-scenes that Discourse uses to tell you ‘hey, there is a new/unread post’ without needing to refresh the page.”

First of all, am I wrong to say that? If so, how does Babble propagate messages across clients? And how does Discourse send those sorts of “new post” notifications out without refreshing? Declan did some inspection out of curiosity and didn’t see any sort of websockets going to the server.

My idea is that Discourse uses something similar to web sockets but doesn’t actually use true websockets. Like its own implementation. Either that or it uses something like SignalR in the ASP.NET world. What’s really going on behind the scenes? I’m really interested in those sorts of things and I’m really curious now.

2 Likes

I’ve not looked at Babble, but I’m assuming it uses the same mechanism the rest of Discourse uses:

https://github.com/SamSaffron/message_bus

It’s a process or subscribing to an endpoint on the front-end and pushing updated data to said endpoint from the back-end. You can see this process if you do a search for MessageBus on the Discourse repo.

10 Likes

See also:

5 Likes