I am looking for a solution to send a message from an IPFS peer to another
in the github doc I found this code that connect a peer to another one :
ipfs.swarm.connect(addr, function (err) {
if (err) {
throw err
}
// if no err is present, connection is now open
})
but after connection there is nothing to do according to documentation.
There a solution named ipfs-pubsub-room that deal with messaging between peers, but there is no CDN for browser.
ipfs.swarm.connect
will simply connect both nodes so that they can exchange files.ipfs-pubsub-room should work just fine from a browser but yes, you'll need to package it yourself.
However, you can also use libp2p, IPFS's networking library, directly via the
ipfs.libp2p
property if you just need to send a message directly from one peer to another.To listen for inbound messages, you can register a "protocol handler" on one of your nodes:
(Where
ipfs
is an initialized IPFS node object, not theIPFS
import.)To send a message, you'll have to "dial" the peer/protocol:
You can find a complete example in the js-ipfs documentation.