@leofcoin/peernet-swarm
v1.1.6
Published
Peernet peer searcher and connector
Downloads
19
Readme
peernet-swarm
peernet peer discoverer & connector
usage
server
import {Server} from '@leofcoin/peernet-swarm'
const network = 'leofcoin:peach'
const port = 44444
new Server(port, network)
client
import {Client} from '@leofcoin/peernet-swarm'
const stars = ['wss://peach.leofcoin.org']
const networkVersion = 'peach'
// wrtc object is added into glabalSpace
new Client(id, networkVersion, stars)
browser
import {Client} from '@leofcoin/peernet-swarm/dist/client.browser.js'
// wrtc object is added into glabalSpace
new Client(id, networkVersion, stars)
examples
events
const client = new Client(id, networkVersion, stars)
// events exposed to pubsub
pubsub.subscribe('peer:data' data => console.log(data))
pubsub.subscribe('peer:joined', peer => console.log(peer))
pubsub.subscribe('peer:left', peer => console.log(peer))
pubsub.subscribe('peer:connected', peer => console.log(peer))
peernet.subscribe('peernet-shard', async message => console.log(message) // {id, data, size}
// const finished = await _handleMessage()
properties
const client = new Client(id, network)
client.id
client.connection
client.connections // object {id: connection}