Social Web Blog




Creating a group chat between feed readers using real-time feed subscriptions (2024-09-01):

IMAGE ALT TEXT

This blog post will walk you through the process of creating a group chat between feed readers, using real-time feed subscriptions and web sockets.

Introduction

"I was excited and math was flying behind my head."

That was my friend Frankie's reaction when he used a feed reader with a real-time connection to another feed reader. This article will outline how we created a group chat with feed subscriptions, MetaWebLog API and WebSockets.

To make a group chat with feeds, we will make one of the feed reader/publisher apps the "host" (feed publisher) of the group chat messages and each of the other group chat participants will be a "client" (feed consumer).

Feed items with < group >

The host's feed includes the most recent messages from all users in the chat, each message looks like this in the XML feed:

Message item element in a RSS feed

We need some group information added to these messages, we can use a namespace to define new elements in a feed, so we will add a < GROUP > tag so the feed XML now looks like this:

Message item element in a RSS feed with group element added

The < GROUP > element has attributes named "id", "url" and "title". The "id" attribute is a string that uniquely identifies the particular group chat on the "host" feed reader/publisher web app. The "title" attribute is a string that contains the name of the group. In the Social Web group chat app, the group name is currently set to display the email addresses of all group chat participants. The "url" element contains the URL of the feed.

New message via MetaWebLog newPost

With these changes a feed reader can now "see" the group in the feed. Lets use the information about the group to send a new message to the group from the "client" feed reader to the "host".

MetaWebLog protocol was built for this, it is a standard used by blogging tools like Wordpress, a standard way to format an XML fragment with the new blog message title and content.

Adding a new message to the feed host's group chat from a feed reader with MetaWebLog protocol

The feed reader "client" will take the "id" of the group from the feed and put that into MetaWebLog's "category" field. The feed URL from the "url" attribute of the < group > element will be used as the endpoint for the XML-RPC POST request. This URL includes a unique key to identify which "client" account on the host's feed reader/publisher app created the new message.

Real-time with < cloud >

OK, now the "client" can "see" the group in the host's feed and send new messages to the group, but how will he know when there is a new post on the "host"?

The < CLOUD > element of RSS includes information for an additional feed-subscription step. This step involves using information from the cloud element attributes to make a request to the feed source to subscribe to callback "pings" when the feed changes. This is called a "light ping" because the callback does not include any message data in it.

Using the cloud element in a feed to receive real-time notifications of feed changes

Real-time with WebSockets

When the cloud callback executes, the "client" re-loads the host's feed again to get the fresh messages. It will then use WebSockets to push the fresh messages instantly to the Web browser for rendering.