JS-IPFS pubsub support with html/javascript only?

Is pubsub supported in the browser directly, without the need for node-modules or a web packager? I found a few tutorials and reviewed the example code, but everything is suggesting I will need to use a node server. I would like to be able to run this serverless in the browser, and I prefer not to use a web packager like browserify.

If it is possible, would you mind sharing an example? I could not find anything that worked.

I was directed to https://github.com/ipfs/js-ipfs/blob/master/packages/ipfs-http-client/examples/browser-pubsub/index.js, however this would only work by delivering via a node server or packaging with something like browserify which I’m trying to implicitly not use.

You need peers to send pubsub messages to, so unless you know peer addresses out of band and manually dial them you need some way of discovering those peers.

To do browser -> browser right now that means connecting to a webrtc-star server to do that initial peer discovery - there are public webrtc servers but they have no uptime guarantees so shouldn’t be used in a production setting - you should stand your own webrtc servers up for this.

In terms of webpack/browserify you can use a js cdn url in a script tag instead, see https://github.com/ipfs/js-ipfs/tree/master/examples/browser-script-tag

Hopefully that helps.

This is currently painful as the webrtc-star stuff is under supported and in flux

See https://github.com/libp2p/js-libp2p/issues/385 and the in progress replacement here https://github.com/libp2p/js-libp2p-rendezvous/pull/6

We’ve had discussions elsewhere about standing up and supporting webrtc servers that can be used publicly, which we’ll do as part of what we’re doing at Fission.

I’ve been playing around with an API called Bugout (https://github.com/chr15m/bugout) that uses WebTorrent to set up a WebRTC connection, which is a very interesting idea. It may be worthwhile to take a look at how it works for pubsub without webrtc-star

1 Like