mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
added WebSocket transport support
Signed-off-by: GautamBytes <manchandanigautam@gmail.com>
This commit is contained in:
18
tests/interop/js_libp2p/js_node/src/package.json
Normal file
18
tests/interop/js_libp2p/js_node/src/package.json
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "src",
|
||||
"version": "1.0.0",
|
||||
"main": "ping.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"description": "",
|
||||
"dependencies": {
|
||||
"@libp2p/ping": "^2.0.36",
|
||||
"@libp2p/websockets": "^9.2.18",
|
||||
"libp2p": "^2.9.0",
|
||||
"multiaddr": "^10.0.1"
|
||||
}
|
||||
}
|
||||
35
tests/interop/js_libp2p/js_node/src/ws_ping_node.mjs
Normal file
35
tests/interop/js_libp2p/js_node/src/ws_ping_node.mjs
Normal file
@ -0,0 +1,35 @@
|
||||
import { createLibp2p } from 'libp2p'
|
||||
import { webSockets } from '@libp2p/websockets'
|
||||
import { ping } from '@libp2p/ping'
|
||||
import { plaintext } from '@libp2p/insecure'
|
||||
import { mplex } from '@libp2p/mplex'
|
||||
|
||||
async function main() {
|
||||
const node = await createLibp2p({
|
||||
transports: [ webSockets() ],
|
||||
connectionEncryption: [ plaintext() ],
|
||||
streamMuxers: [ mplex() ],
|
||||
services: {
|
||||
// installs /ipfs/ping/1.0.0 handler
|
||||
ping: ping()
|
||||
},
|
||||
addresses: {
|
||||
listen: ['/ip4/127.0.0.1/tcp/0/ws']
|
||||
}
|
||||
})
|
||||
|
||||
await node.start()
|
||||
|
||||
console.log(node.peerId.toString())
|
||||
for (const addr of node.getMultiaddrs()) {
|
||||
console.log(addr.toString())
|
||||
}
|
||||
|
||||
// Keep the process alive
|
||||
await new Promise(() => {})
|
||||
}
|
||||
|
||||
main().catch(err => {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
})
|
||||
Reference in New Issue
Block a user