setStreamHandler method

  1. @override
void setStreamHandler(
  1. String protocol,
  2. Future<void> handler(
    1. dynamic stream,
    2. PeerId remotePeer
    )
)
override

Sets the handler for new streams opened by the remote side. This operation is thread-safe.

@param protocol The protocol ID for which to set the handler @param handler The handler function that will be called when a new stream is opened

Implementation

@override
void setStreamHandler(String protocol, Future<void> Function(dynamic stream, PeerId remotePeer) handler) {
  _protocolHandlers[protocol] = handler;

  // For backward compatibility, set the default stream handler to use the protocol handler
  _defaultStreamHandler = (stream, remotePeer) async {
    // Call the protocol handler with the stream and remote peer
    await handler(stream, remotePeer);
  };
}