Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support filtering on host, name and address family (IPv4 vs IPv6) #31

Open
wimleers opened this issue Mar 15, 2023 · 2 comments
Open

Support filtering on host, name and address family (IPv4 vs IPv6) #31

wimleers opened this issue Mar 15, 2023 · 2 comments

Comments

@wimleers
Copy link

wimleers commented Mar 15, 2023

First off: THANK YOU! This works great! 🚀 I'm using this in https://github.com/wimleers/homebridge-sma-home-manager.

This is what I have today:

bonjour.find({ type: 'http' }, function () {
  // custom filtering logic
});

finds the result I need:

 {
  addresses: [ '2a02:1812:1416:6f00:240:adff:feb7:e999', '192.168.0.237' ],
  subtypes: [],
  rawTxt: [ <Buffer > ],
  txt: {},
  name: 'Website for SMA-Inverter: SMA3010955555-3',
  fqdn: 'Website for SMA-Inverter: SMA3010955555-3._http._tcp.local',
  host: 'SMA3010955555-3.local',
  referer: { address: '192.168.0.237', family: 'IPv4', port: 5353, size: 177 },
  port: 443,
  type: 'http',
  protocol: 'tcp'
}

But much of that custom filtering logic could easily be done by making .find() and .findOne()'s options argument more powerful, by expanding what src/lib/utils/filter-service.ts does.

IOW:

bonjour.findOne({
  type: 'http',
  host: /SMAd+/,
  name: /^Website for SMA-Inverter .*/
  addressFamily: 'IPv4'
}, function () {
  // no filtering logic needed anymore!
});

That'd result in my getting

 {
  addresses: [ '192.168.0.237' ],
  subtypes: [],
  rawTxt: [ <Buffer > ],
  txt: {},
  name: 'Website for SMA-Inverter: SMA3010955555-3',
  fqdn: 'Website for SMA-Inverter: SMA3010955555-3._http._tcp.local',
  host: 'SMA3010955555-3.local',
  referer: { address: '192.168.0.237', family: 'IPv4', port: 5353, size: 177 },
  port: 443,
  type: 'http',
  protocol: 'tcp'
}

… with less logic needed on my end 😊

@mdidon
Copy link
Member

mdidon commented Mar 21, 2023

@wimleers Not a problem. To confirm, you're looking for RegExr filtering for the browser?

@wimleers
Copy link
Author

Yes: a declarative equivalent for a callback, with each of the supported fields allowing a regex 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants