I've been using a package called icy that uses the Http Client from Node v8.11.3.
I'm connecting to a streamer Icecast server with continuous audio.
The code looks like the following:
icy.get(url, (res) => {
res.on('end', (e) => console.log('connection ends')); // end of connection
res.on('metadata' => () => {...}); // metadata handler
}
The problem comes when the Icecast server restarts or times out.
I want the function to try to reconnect after timeout but haven't found an option to it in the docs.
Any help would be appreciated.
Cheers!
You need to catch the error event and the finish of the stream event: