setStreamHandlerMatch method
SetStreamHandlerMatch sets the protocol handler on the Host's Mux using a matching function for protocol selection.
Implementation
@override
void setStreamHandlerMatch(ProtocolID pid, bool Function(ProtocolID) match, StreamHandler handler) {
// Convert StreamHandler to HandlerFunc
// final handlerFunc = (ProtocolID protocol, P2PStream stream) {
// handler(stream);
// };
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.addHandlerWithFunc(pid, match, handlerFunc);
// Emit protocol updated event
if (_evtLocalProtocolsUpdated != null) {
_evtLocalProtocolsUpdated!.emit(EvtLocalProtocolsUpdated(added: [pid], removed: []));
}
}