setStreamHandler method
SetStreamHandler sets the protocol handler on the Host's Mux. This is equivalent to: host.Mux().SetHandler(proto, handler) (Thread-safe)
Implementation
@override
void setStreamHandler(ProtocolID pid, StreamHandler handler) {
// Convert StreamHandler to HandlerFunc
final handlerFunc = (ProtocolID protocol, P2PStream stream) {
// Extract remotePeer from the stream's connection
final remotePeer = stream.conn.remotePeer;
// Call the handler with both stream and remotePeer
handler(stream, remotePeer);
};
_mux.addHandler(pid, handlerFunc);
// Emit protocol updated event
if (_evtLocalProtocolsUpdated != null) {
_evtLocalProtocolsUpdated!.emit(EvtLocalProtocolsUpdated(added: [pid], removed: []));
}
}