Pubsub Comments

Yesterday, I threw together a proof-of-concept comment system for use with IPFS websites. You can find the demo here. I expect this link to become unreachable once I transition from a proof-of-concept to a production system.

How it Works

The comment system consists of the following parts:

  • The web page with comment submission form. This is hosted on IPFS using IPNS for mutability
  • comments.js that contains the existing comments.
  • pubsub-comment.js contains functions for submitting comments with AJAX and updating the static page to include existing comments
  • A pubsub relay server. I’m using NGINX to proxy three API functions from an IPFS node
  • Comment server that subscribes to a pubsub channel, collects comments and packages them into comments.js

When you reload the page, the contents of comments.js is used to populate the comments section. It does a probe to determine available relays for comment submission. The script as written prioritizes 127.0.0.1:5001.

When you submit a comment, a function pulls the comment information from the form, packs it into a json object, then uses a relay to submit to the server. The server receives the comments, adds them to an array, serializes them to comments.js, and then republishes the comments data.

Next Steps

To get to a production system, the comment server needs to support multiple pages with different comment threads and needs to use a configuration file to specify all the relevant information like the pubsub channel to use. Support for administration also needs to be made, for things like removing comments that violate site policies or for approving comments before allowing them to be published.

A network of relays would also be useful to ensure the comment system is usable before browsers support native IPFS/pubsub. Ideally, each site would have its own comment server on its own pubsub channel, but there is probably room for an IPFS comment service.

Comments