socketsub watches RSS and Atom feeds for you. You open a WebSocket, send the feed URLs you care about, and receive a message each time one of them changes. socketsub finds each feed's rssCloud or WebSub support and handles the subscriptions.
Open a WebSocket to:
wss://sub.rsscloud.io/ws
All messages in both directions are JSON text frames. Feeds belong to the connection: when it closes, socketsub forgets them. After a reconnect, subscribe to your feeds again.
Every message you send is a JSON object with a type and
a urls array of feed URL strings.
subscribe
{
"type": "subscribe",
"urls": ["https://example.com/feed.xml", "https://blog.example/atom"]
}
http and https URLs are accepted.
unsubscribe
{
"type": "unsubscribe",
"urls": ["https://example.com/feed.xml"]
}
status with state
unsubscribed, even if this connection never
followed it.
The server sends three kinds of message. Every url
field is the exact string you sent, even if the feed redirects or
has a different canonical URL, so you can use it as a key.
statusSent once for each URL you subscribe to, again each time that feed's state changes, and once for each URL you unsubscribe from.
{
"type": "status",
"url": "https://example.com/feed.xml",
"state": "subscribed",
"via": "rsscloud"
}
| Field | Meaning |
|---|---|
state |
One of the states in the next table. |
via |
rsscloud or websub. Present
once socketsub has picked a protocol for the feed.
|
detail |
A human-readable reason. Present on
error and unsupported, and on
pending when rssCloud failed and WebSub is
being tried.
|
States:
| State | Meaning |
|---|---|
pending |
socketsub is fetching the feed or waiting for the rssCloud server or WebSub hub to confirm. |
subscribed |
You will get update messages for this feed.
A failed renewal does not change this state. socketsub
retries in the background while the old registration
still holds.
|
unsupported |
The feed advertises neither rssCloud nor WebSub. You will not get updates for it. A subscribe at least an hour later checks the feed again. |
error |
The URL was invalid, a limit was reached, the feed could
not be fetched, or the subscription failed. See
detail. You will not get updates for it. To
retry, subscribe again later. socketsub retries a failed
feed at most once a minute, and waits longer while the
server keeps failing. Before then, a subscribe gets the
same error.
|
unsubscribed |
Your unsubscribe went through. You will not get updates for it. |
updateSent each time the feed's publisher reports a change. Fetch the feed yourself to get the new content.
{ "type": "update", "url": "https://example.com/feed.xml" }
error
Sent when a whole message is rejected: it is not JSON, has no valid
type, its urls is not an array of strings,
or it has too many URLs. Problems with a single URL come back as a
status with state error
instead.
{ "type": "error", "message": "message is not valid JSON" }
> {"type":"subscribe","urls":["http://scripting.com/rss.xml","https://xkcd.com/rss.xml"]}
< {"type":"status","url":"http://scripting.com/rss.xml","state":"pending"}
< {"type":"status","url":"https://xkcd.com/rss.xml","state":"pending"}
< {"type":"status","url":"https://xkcd.com/rss.xml","state":"unsupported","detail":"feed advertises neither rssCloud nor WebSub"}
< {"type":"status","url":"http://scripting.com/rss.xml","state":"pending","via":"rsscloud"}
< {"type":"status","url":"http://scripting.com/rss.xml","state":"subscribed","via":"rsscloud"}
...
< {"type":"update","url":"http://scripting.com/rss.xml"}
> {"type":"unsubscribe","urls":["http://scripting.com/rss.xml"]}
< {"type":"status","url":"http://scripting.com/rss.xml","state":"unsubscribed"}
const feeds = ['http://scripting.com/rss.xml'];
const socket = new WebSocket('wss://sub.rsscloud.io/ws');
socket.addEventListener('open', () => {
socket.send(JSON.stringify({ type: 'subscribe', urls: feeds }));
});
socket.addEventListener('message', event => {
const message = JSON.parse(event.data);
if (message.type === 'update') {
console.log('changed:', message.url);
} else if (message.type === 'status') {
console.log(message.url, message.state, message.detail ?? '');
} else {
console.error(message.message);
}
});
| URLs in one message | 500 |
| Feeds per connection | 1000 |
| Feeds across the server | 10000 |
| Message size | 1 MiB. Larger messages close the connection with code 1009. |
Feeds on private or loopback addresses are refused.