Skip to content
This repository was archived by the owner on Aug 9, 2021. It is now read-only.

Commit c5953d7

Browse files
committed
feat: add pubsub room monitoring tool
1 parent 4c620ff commit c5953d7

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ tmp/
77
.DS_Store
88
yarn.lock
99
orbitdb
10-
.idea
10+
.idea
11+
example/build.js

tools/pubsub-room-listen.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env node
2+
3+
const Ipfs = require('ipfs')
4+
const Pubsub = require('orbit-db-pubsub')
5+
const multiaddr = require('multiaddr')
6+
const { pinning_node } = require('../lib/config.js')
7+
8+
const start = async (room) => {
9+
console.log('\nOpening pubsub room:\n', room)
10+
const ipfs = await Ipfs.create({ repo: `./tmp/ipfs/` })
11+
const pubsub = new Pubsub(ipfs, (await ipfs.id()).id)
12+
console.log('Connecting to pinning node')
13+
await ipfs.swarm.connect(multiaddr(pinning_node))
14+
console.log('Connected')
15+
16+
pubsub.subscribe(room, (topic, data) => {
17+
console.log('message', topic, data)
18+
}, (topic, peer) => {
19+
console.log('peer', topic, peer)
20+
})
21+
console.log('Subscribed')
22+
}
23+
24+
const room = process.argv[2]
25+
start(room)

0 commit comments

Comments
 (0)