在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:ipfs-shipyard/ipfs-pubsub-room开源软件地址:https://github.com/ipfs-shipyard/ipfs-pubsub-room开源编程语言:JavaScript 100.0%开源软件介绍:ipfs-pubsub-room
Install$ npm install ipfs-pubsub-room UseCreating a pubsub room from a LibP2P node const Room = require('ipfs-pubsub-room')
const Libp2p = require('libp2p')
const libp2p = new Libp2p({ ... })
await libp2p.start()
// libp2p node is ready, so we can start using ipfs-pubsub-room
const room = Room(libp2p, 'room-name') Creating a pubsub room from an IPFS node const Room = require('ipfs-pubsub-room')
const IPFS = require('ipfs')
const ipfs = await IPFS.create({ ... })
const room = Room(ipfs, 'room-name') Once we have a room we can listen for messages 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!')
}) APIRoom (libp2p:LibP2P, roomName:string, options:object)
const room = Room(libp2p, 'some-room-name') room.broadcast(message)Broacasts message (string or buffer). room.sendTo(cid, message)Sends message (string or buffer) to peer. async room.leave()Leaves room, stopping everything. room.getPeers()Returns an array of peer identifiers (strings). room.hasPeer(cid)Returns a boolean indicating if the given peer is present in the room. room.on('message', (message) => {})Listens for messages. A
room.on('peer joined', (cid) => {})Once a peer has joined the room. room.on('peer left', (cid) => {})Once a peer has left the room. room.on('subscribed',() => {})Once your program has subscribed the topic and announced through IPFS pubsub. LicenseISC |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论