-
Notifications
You must be signed in to change notification settings - Fork 0
/
server2.js
44 lines (39 loc) · 1018 Bytes
/
server2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { create } from "ipfs-core"
async function init() {
const ipfsd = await create({
repo: "./ipfs-user-2",
EXPERIMENTAL: {
ipnsPubsub: true,
},
config: {
Addresses: {
Swarm: [
"/ip4/0.0.0.0/tcp/9002",
// "/dns4/wrtc-star2.sjc.dwebops.pub/tcp/443/wss/p2p-webrtc-star",
],
},
},
})
let counter = 1
setInterval(async () => {
counter++
console.log("sending event", counter)
await ipfsd.pubsub.publish(
"SOME_EVENT",
new TextEncoder().encode("hello " + counter),
)
}, 1000)
const stop = async () => {
try {
await ipfsd.stop()
} catch (e) {
console.log(e.message)
}
process.exit()
}
process.on("SIGTERM", stop)
process.on("SIGINT", stop)
process.on("SIGHUP", stop)
process.on("uncaughtException", stop)
}
init()