-
-
Notifications
You must be signed in to change notification settings - Fork 94
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
API for Zeroconf connection to other devices on the network #352
Comments
So you'd like an API endpoint to list devides available on your network and one to connect to them? |
Basically yes - that was just a long-winded way of asking, so I could explain the use case. |
First part should be relatively easy: just need to make a mDNS probe and get the results. For the second one we need to craft the zeroconf blob which ultimately is a lot of wrapping around stored credentials data. I'll start by modifying zeroconf-java to allow probing. |
Awesome - thanks for getting started so quickly! This might be me, but I'm getting an authorisation failure (401) when I try to compile (mvn clean package): |
Yep, I know. The CI is also failing, there's something wrong with the CI on zeroconf-java because I had to switch away from Travis and it broke. Hadn't time to fix it yet. As a workaround you can either clone zeroconf-java and do |
|
@benturnberg You should be good now. |
Great - I can compile again 🤘 Using the librespot-api-1.6.1-SNAPSHOT.jar, I get the following result when running a POST to http://localhost:24879/discovery/list:
|
You should get the list of devices in the response body. |
Sorry, should have included that - the response body is:
|
Just to add to this, the API does work for me when invoking /player/next for example... On the other hand, it also returns a blank response when (while connected) I invoke /web-api/v1/me/player/devices. |
I think the problem goes back to zeroconf-java not being able to discover your librespot-java client. |
Anything I can check on my side? I tried disabling AV and firewall just as a sense-check, still the same though. |
Turns out there was a bug in |
Ok that's good. Now it can see itself, but it's not seeing any other players advertised on the local network:
|
... or at least, it's not returning them in the body of the response |
After more bug fixing it should be finally good. |
It's still only recognising itself. |
What do you see if you run |
The devices are there:
|
Hey @devgianlu let me know if there's anything else I can do to troubleshoot. Cheers |
@benturnberg I just need to find the time to debug zeroconf-java with a Spotify Connect enabled device (likely my TV). |
Thanks @devgianlu , I appreciate it. Finding the time can certainly be difficult! |
Hi, Like @benturnberg I can see the speakers with dns-sd -B _spotify-connect local
But when running the API server (via Coursier)
and then calling the discovery endpoint, I can see only the other Spotify connect devices but not the Sonos speakers: curl -s -X POST http://localhost:24879/discovery/list | jq [
{
"name": "librespot-java",
"target": "Sorens-MacBook-Pro",
"port": 34515
},
{
"name": "Kodi (mediacenter)",
"target": "mediacenter.local",
"port": 46233
}
] I also ran the discoverer manually (basically the code below from the librespot-java/api/src/main/java/xyz/gianlu/librespot/api/handlers/DiscoveryHandler.java Lines 43 to 53 in 2745b50
If there's anything I can do to help debugging the issue, I'd be happy to. |
Wow that was fast @devgianlu. While looking into zeroconf-java, I just saw that you had released |
Turns out there was a bug in the code I hadn't written myself. It was working with zeroconf-java only because the packet creation is unoptimized while official clients are. I was writing the code for the connection, but it can be done in two ways:
Let me know if you intended to use it differently. |
I think connecting with the current user of librespot-java would be the best fit for my use-case. |
Current user would work with my use case too. Thanks @devgianlu |
@devgianlu now that discovery works is there anything I can do to help with the connect part? |
I don't really have time to develop this feature. What needs to be done is writing the encryption code for the blob having the one for decryption. |
Has anyone made any progress on this? I have started the patchset to encrypt the blob and make the |
@dsheets I haven't looked into this further yet. |
Any progress on this? I am trying to make the same addUser request in Python 3. Thanks. |
Just wanted to add myself in here. I have been trying to get my Spocon setup to show up on the network for things like HomeAssistant and have been struggling. I think this is a similar issue? I am trying to do the mDNS port forwarding and Google led me here. Is there any way to wake up Spocon/librespot and show it on Spotify Connect? |
Not sure on that, as I am not familiar with “Spocon”. Or is that short for Spotify Connect? I have had success with getting the integration to work with the spotifyd and Spotify Connect Addon, both of which use librespot under the covers. You just have to configure librespot in discovery mode, and create a credentials.json file. Checkout the SpotifyPlus Device Configuation Options for librespot wiki doc for more details. |
@floodwayprintco
That should force SpoCon to advertise itself via zeroconf / mdns on port 8600. I just picked 8600 out of the blue, you can choose whatever port you want. I like a dedicated (vs random) port, in case you need to open firewalls. If you do open firewalls, open activity for 8600 TCP and 5353 UDP (mdns advertise). I would also avoid spaces in the You should then be able to start the SpoCon service; after it is started, do the following:
At this point, librespot should have generated a Please refer to the SpotifyPlus librespot Credentials File topic for further instructions on how to utilize the librespot credentials with the SpotifyPlus integration. Hope it helps - let me know either way, as you are the first person I have heard of that utilizes SpoCon. I have never used it myself, but based on the docs that I read it should work fine. If it does work, then I will add this to my SpotifyPlus wiki documentation. |
@floodwayprintco |
Problem:
Spotify Web API only allows me to connect to devices which are specifically registered to my account, rather than those devices which advertise themselves over mdns on my local network.
Possible solution:
I'd like to be able to use an API in order to programmatically connect to any Spotify devices on my local network, using Zeroconf. I can see that you've done the hard yards to be able to connect the librespot-java player via Zeroconf: would it be possible to onboard other players using a similar method, and incorporate this into the API?
Background / use case:
I have created an application in Spotify, and I can use it for Spotify Web API calls, including connecting to those devices which are registered to my Spotify account. I use Sonos speakers, which seem to rely more on Zeroconf connections for devices on the local network, so when I use the Spotify Web API to list available devices using the Spotify Web API, unless I've recently connected to the Sonos device specifically through the Spotify app, the Sonos devices do not appear in the list of available devices. The Sonos devices still show up on the Spotify Connect app (they're still advertised and over mdns), just not in the Web API, presumably because they aren't registered specifically to my account, and need to be available to other users on my local network.
The text was updated successfully, but these errors were encountered: