-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver1.js
37 lines (33 loc) · 907 Bytes
/
server1.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
import { create } from "ipfs-core"
async function init() {
const ipfsd = await create({
repo: "./ipfs-user-1",
EXPERIMENTAL: {
ipnsPubsub: true,
},
config: {
Addresses: {
Swarm: [
"/ip4/0.0.0.0/tcp/9001",
// "/dns4/wrtc-star2.sjc.dwebops.pub/tcp/443/wss/p2p-webrtc-star",
],
},
},
})
await ipfsd.pubsub.subscribe("SOME_EVENT", (message) => {
console.log("GOT SOME EVENT", new TextDecoder().decode(message.data))
})
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()