From 43136b4d906b6c61feff4096fe52011b02073157 Mon Sep 17 00:00:00 2001 From: Sumanjeet Date: Thu, 27 Feb 2025 20:56:11 +0530 Subject: [PATCH 1/2] fix: correct stream handling and protocol dialing in example code --- examples/js-libp2p-example-protocol-and-stream-muxing/1.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/js-libp2p-example-protocol-and-stream-muxing/1.js b/examples/js-libp2p-example-protocol-and-stream-muxing/1.js index a80ccf2..357e125 100644 --- a/examples/js-libp2p-example-protocol-and-stream-muxing/1.js +++ b/examples/js-libp2p-example-protocol-and-stream-muxing/1.js @@ -49,7 +49,7 @@ node2.handle(['/another-protocol/1.0.0', '/another-protocol/2.0.0'], ({ protocol stream, async function (source) { for await (const msg of source) { - console.log(uint8ArrayToString(msg)) + console.log(uint8ArrayToString(msg.subarray())) } } ) @@ -63,10 +63,10 @@ await pipe( ) /* -const stream = node1.dialProtocol(node2.peerId, ['/another-protocol/1.0.0']) +const stream = await node1.dialProtocol(node2.getMultiaddrs(), ['/another-protocol/1.0.0']) await pipe( - ['my own protocol, wow!'], + [uint8ArrayFromString('my own protocol, wow!')], stream ) */ From 4197ac0e9c3d257dcac4edbd59d40185fa72368e Mon Sep 17 00:00:00 2001 From: "sumanjeet0012@gmail.com" Date: Sat, 15 Mar 2025 11:37:35 +0530 Subject: [PATCH 2/2] fix: update protocol reference in stream handling example --- examples/js-libp2p-example-protocol-and-stream-muxing/2.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/js-libp2p-example-protocol-and-stream-muxing/2.js b/examples/js-libp2p-example-protocol-and-stream-muxing/2.js index 3f4a011..cde99d8 100644 --- a/examples/js-libp2p-example-protocol-and-stream-muxing/2.js +++ b/examples/js-libp2p-example-protocol-and-stream-muxing/2.js @@ -31,12 +31,12 @@ await node1.peerStore.patch(node2.peerId, { multiaddrs: node2.getMultiaddrs() }) -node2.handle(['/a', '/b'], ({ protocol, stream }) => { +node2.handle(['/a', '/b'], ({ stream }) => { pipe( stream, async function (source) { for await (const msg of source) { - console.log(`from: ${protocol}, msg: ${uint8ArrayToString(msg.subarray())}`) + console.log(`from: ${stream.protocol}, msg: ${uint8ArrayToString(msg.subarray())}`) } } ).finally(() => {