ivandotv / radio-browser-api

Wrapper around free and open-source radio browser API. It simplifies the task of querying the API
https://api.radio-browser.info/
MIT License
46 stars 16 forks source link

hardcoded server by default #31

Closed segler-alex closed 3 years ago

segler-alex commented 3 years ago

Hi,

I am the maintainer of radio-browser.info. Thank you for your work! it looks good! This is just my hobby project, it is nice to see it is usefull to people. there is one thing i want to add. please do not use a hardcoded server by default. most people that use your library might just keep the hardcoded one and this drains resources of a single server more than the others. to keep the experience good for everyone, try to randomize somehow by default, PLEASE

oh, and do not use the url https://all.api.radio-browser.info because the certificate on each individual server does only have its own name. you will get a certificate error when you do curl https://all.api.radio-browser.info for example.

if you are inside nodejs you could just do

const dns = require('dns');
dns.resolveSrv("_api._tcp.radio-browser.info", (err, result)=>{
    console.log("servers",result);
});

to get a list of all registered servers without the reverse dns stuff, which of course you may also do. but his approch is only 1 step , it gives you directly the server names. i keep both types of information up to date in the DNS, so it is up to you. https://api.radio-browser.info/ has the other example for nodejs.

browsers do not allow SRV dns requests and also no reverse lookups, so you can only query http://all.api.radio-browser.info/json/servers to get a list of all servers. this list is also kept up to date.

sorry for my long message, i just like to explain stuff :)

Thanks again alex

segler-alex commented 3 years ago

oh, and i will add your library to the list if you are ok with it? https://www.radio-browser.info/#!/users

ivandotv commented 3 years ago

I want to make the library work both server-side and in the browser (I'm using it in an isomorphic app). I have read your whole documentation and I already have a method to resolve the base server. https://github.com/ivandotv/radio-browser-api/blob/3cb39739e9cfb901bc8b57e65ef8e26875528794/src/radioBrowser.ts#L51-L65

Although it has to be called manually. I could change the code to always first resolve the base server before continuing with the actual API call. And I could take a random server from the list.

As for adding the library to the list, I wanted to contact you about it, but I decided to wait to see what the end API will look like, and also I'm building a PWA radio app based on your API, and this library (hobby project also), so I'm going to submit both projects to you when I'm done.

ivandotv commented 3 years ago

ping @segler-alex I've have an app in development, check it out: https://live-radio.vercel.app/