Hi,
I am trying to replicate the echo example [https://github.com/libp2p/js-libp2p/tree/master/examples/echo] in the browser and have found that there is not any simple documentations about using stream. Also this example uses pip
function which does is not available on the browser. Is it possible that someone give me some hint on it?
here is my example
here I have stream object and I want to send a message using it to another peer
const {
stream
} = await dialerNode.libp2p.dialProtocol(listenerMultiaddr, '/echo/1.0.0')
console.log('nodeA dialed to nodeB on protocol: /echo/1.0.0')
// ['hey'] |> stream |> async function (source) {
// // For each chunk of data
// for await (const data of source) {
// // Output the data
// console.log('received echo:', data.toString())
// }
// };
stream(['hey'])
But here stream is an object not a function. I have no idea how pipe (in the original example) is passing the ['hey']
to the stream object.
The same is here. I cannot read from stream since in that example a pipe is used.
await node.libp2p.handle('/echo/1.0.0', ({
stream
}) => {
stream => (async function () {
for await (const msg of source) {
console.log(msg.toString())
}
})()
})
Thanks