Help with ipfs-pubsub-room

I’ve been following this tutorial

I think I’m doing everything right.

The ipfs nodes are getting created and logging the following message:

IPFS node ready with address QmX7qsqNew4qcJrzeDJ7QJrkuanvikr9MXKoe1J6i4YdMc

But I’m not seeing any messages logged to the console in response to the “peer join” and “peer left” events

Without errors it’s hard to figure out where I’m going wrong. I’ve pasted the code below and then details about my environment in case someone has an idea about what’s going wrong.

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

const ipfs = new IPFS({
  repo: repo(),
  EXPERIMENTAL: {
    pubsub: true
  }
})

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

const room = Room(ipfs, 'ipfs-pubsub-demo');
//console.log("ipfs", ipfs)
//console.log("room", room)

room.on("peer join", (peer) => console.log('peer' + peer + 'joined'))
room.on("peer left", (peer) => console.log('peer' + peer + 'left'))

// send and receive
room.on("peer joined", (peer) => room.sendTo(peer, 'Hello ' + peer + '!'))
room.on("message", (message) => console.log('got message from ' + message.from + ': ' + message.data.toString()))


function repo (){
  return 'ipfs/pubsub-demo/' + Math.random()
}

I’m running node v9.4.0

And here is my json package.json

{
  "name": "ipfs-pubsub-demo",
  "version": "0.0.1",
  "description": "IPFS pub-sub demo",
  "main": "index.js",
  "scripts": {
    "compile": "browserify src/app.js -o public/js/app.js -d",
    "start": "http-server -c-1 -p 12345 public"
  },
  "author": "jeff following pedro",
  "license": "MIT",
  "dependencies": {
    "browserify": "^16.2.2",
    "http-server": "^0.11.1",
    "ipfs": "^0.28.2",
    "ipfs-pubsub-room": "^1.2.1"
  }
}

hi,

you need to be sure your ipfs node is started so try that :

ipfs.on(‘ready’, () => {
const room = Room(ipfs, ‘room-name’)

room.on(‘peer joined’, (peer) => {
console.log(‘Peer joined the room’, peer)
})

room.on(‘peer left’, (peer) => {
console.log(‘Peer left…’, peer)
})

// now started to listen to room
room.on(‘subscribed’, () => {
console.log(‘Now connected!’)
})
})