ipfs-pubsub-room icon indicating copy to clipboard operation
ipfs-pubsub-room copied to clipboard

room.broadcast only sends messages to itself not other peers.

Open niinpatel opened this issue 5 years ago • 1 comments

Problem:

I was trying to follow along this tutorial on ipfs-pubsub-room.

The problem is when I do room.broadcast('some message').

Other peers do not get the message but the sender gets its own message.

Here's the code I wrote:

const IPFS = require('ipfs')
const Room = require('ipfs-pubsub-room')

const ipfsRepo = require('./utils/ipfs-repo')

const ipfs = new IPFS({
  repo: ipfsRepo(),
  EXPERIMENTAL: {
    pubsub: true
  },
  config: {
    Addresses: {
      Swarm: [
        '/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star'
      ]
    }
  }
})

ipfs.once('ready', () => {
  ipfs.id((err, info) => {
    if (err) throw err
    console.log('IPFS node ready with address,', info.id)
  })

  const room = Room(ipfs, 'cPsnqzpAslkNCgGw6Tid')

  room.on('peer joined', (peer) => {
    console.log('peer ', peer, 'joined')
  })

  room.on('peer left', (peer) => {
    console.log('peer', peer, 'left')
  })

  room.on('message', (message) => {
    console.log('message from', message.from, 'contents:', message.data.toString())
  })

  setTimeout(() => room.broadcast('hey everyone!'), 2000)
})


Dependencies List:

"dependencies": {
    "ipfs": "^0.34.4",
    "ipfs-pubsub-room": "^1.4.1"
  }

niinpatel avatar Mar 10 '19 06:03 niinpatel

I'm having the same issue. Have you found a solution?

ahfriedman avatar Oct 23 '19 23:10 ahfriedman