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

Use Avahi to discover lights? #2

Open
owtaylor opened this issue Dec 1, 2021 · 6 comments
Open

Use Avahi to discover lights? #2

owtaylor opened this issue Dec 1, 2021 · 6 comments

Comments

@owtaylor
Copy link

owtaylor commented Dec 1, 2021

elgato.js.txt
Nice extension! Looking at it, I wondered if the npm requirement and the need to install node modules could be avoided. It seemed to me that tallking to Avahi over D-Bus (should be installed on most Linux systems) would allow doing this natively in GObject code without having to resort to npm and mdns-js. I did some experiments with this.

I'll attach a script here that implements a persistent browser for Elgato lights on the network. (Run as gjs elgato.js) I spent quite a bit more time on this than I expected to really try and get the corner cases right:

  • Caching inside Avahi based on the TTL of the returned records caused confusion when turning lights off and on while the browser is running. (Unlike some mDNS devices, the lights don't send "goodbye" messages when being turned off.) To deal with this, I made the code periodically retry looking up address records.
  • IPv4 and IPv6 responses needed to be sorted out and combined into a coherent picture.

Details in a comment in the code. This could could be re-simplified to just do a single-pass scan, if something more like the current UI was desired, but I think its nice if the extension "just works" without having to go into the preferences and rescan if the light gets a new DHCP address or something.

Feel free to adapt this code to your purposes, and let me know if it doesn't work :-)

@Cluster2a
Copy link
Owner

Uh, boy - that's quite a lot of code.
I will dig into it if I got some time :)

Thanks a lot for the input!

@cschalle
Copy link

Hi Alex,
Really hope you have a chance to integrate this. Would love to see your extension on extension.gnome.org and be something we can advocate for as the best solution for dealing with Elgato lights on Fedora as part of our new initiative - https://fedoraproject.org/wiki/Workstation/LiveStreamingCompatInitiative (also hope GNOME 41 support is coming soon :)

@Cluster2a
Copy link
Owner

Cluster2a commented Dec 14, 2021

@cschalle, using Avahi is not necessary to publish this project on extension.gnome.org, as GSConnect uses the same approach (mdns-js): https://extensions.gnome.org/extension/1319/gsconnect/

Unfortunately, I am working on a bigger side project, so I don't have much time left.
Feel free to add version 41 and test it: bef9eed

It might be working out of the box - not sure.

Edit: I see - Vte is not available for gnome GTK4: https://gitlab.gnome.org/GNOME/vte/-/issues/12

@cschalle
Copy link

Hi Alex, ah I didn't realize that e.g.o allows extensions with external dependencies, that said it is still a bit clunky as you can't just install the extension and go which would be a nicer experience. I guess we could work around this by packaging the extension as a RPM and have the RPM automatically pull in required dependencies, but in general I am not a huge fan of packaging extensions as RPMS and also it is a distro specific fix.

I tried running it, but as I expected it will not run under 41 due to the switch to GTK4, so beyond lacking VTE you also get an error from prefs.js due to trying to load GTK3

@Cluster2a
Copy link
Owner

@cschalle, I started working on the new version yesterday. I wasn't aware that Vte is not ready yet. I am using the approach of @owtaylor and it seems to be working fine. So in the next version will be without extra dependencies.

@cschalle
Copy link

Great! If you need a tester feel free to ping me, got a lamp here in front of me.

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

3 participants