Simple-peer, only calls the send method once, and the callback in ondata is triggered many times. Why?

using the simple-peer library, there is an instance peer.
binds to events peer.on ("data",func)
and then calls peer.send (data) , data is a relatively large data

at this point, you will find that func will be called multiple times. It seems that data is split into multiple chunk, and then func is executed on each chunk.

The

document says that simple-peer inherits node"s stream-Duplex , but doesn"t quite understand node"s stream, so it feels confused.

how do I know that the current chunk is the last? Because only when the complete data are obtained should we proceed to the next step.

Mar.14,2022
Menu