Skip to content

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

@niinpatel

Description

@niinpatel

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"
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions