eshaz / icecast-metadata-js

Browser and NodeJS packages for playing and reading Icecast compatible streaming audio with realtime metadata updates.
158 stars 20 forks source link

CORS enabled on Icecast Server but error #43

Closed zanarduz closed 3 years ago

zanarduz commented 3 years ago

Hello, i receive this error if i try the player on my icecast server and can receive audio stream but not metadata. If I open Chrome with --disable-web-security all works without errors.

Chrome Console log

icecast-metadata-player-0.0.3.min.js:formatted:2011 GET URL net::ERR_EMPTY_RESPONSE
t   @   icecast-metadata-pla…n.js:formatted:2011
Ae  @   icecast-metadata-pla…n.js:formatted:2016
play    @   icecast-metadata-pla…n.js:formatted:1928
onclick @   VM103 :125

icecast-metadata-player-0.0.3.min.js:formatted:1954 icecast-metadata-js 
  Network request failed, possibly due to a CORS issue. Trying again without ICY Metadata.

icecast-metadata-player-0.0.3.min.js:formatted:227 icecast-metadata-js 
  Passed in Icy-MetaInt is invalid. Attempting to detect ICY Metadata. 
  See https://github.com/eshaz/icecast-metadata-js for information on how to properly request ICY Metadata.

icecast-metadata-player-0.0.3.min.js:formatted:244 icecast-metadata-js 
  ICY Metadata not detected after searching 107800 bytes for 2.095 seconds. 
  Assuming stream does not contain ICY metadata. Audio errors will occur if there is ICY metadata.

Testing Icecast server with CURL seems to respond with correct headers:

curl -H "Icy-MetaData: 1" -v "URL"
*   Trying IP...
* TCP_NODELAY set
* Connected to host (ip) port #### (#0)
> GET /stream HTTP/1.1
> Host: host:port
> User-Agent: curl/7.64.1
> Accept: */*
> Icy-MetaData: 1
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Server: Icecast 2.4.4
< Connection: Close
< Date: Sat, 23 Jan 2021 10:37:46 GMT
< Content-Type: audio/mpeg
< Cache-Control: no-cache, no-store
< Expires: Mon, 26 Jul 1997 05:00:00 GMT
< Pragma: no-cache
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET, OPTIONS
< Access-Control-Allow-Headers: Content-Type, Icy-Metadata
< Access-Control-Expose-Headers: Icy-MetaInt, Icy-Br, Icy-Description, Icy-Genre, Icy-Name, Ice-Audio-Info, Icy-Url, Icy-Sr, Icy-Vbr, Icy-Pub
< icy-br:160
< ice-audio-info: ice-bitrate=160;ice-channels=2;ice-samplerate=44100
< icy-name:no name
< icy-pub:0
< icy-metaint:16000

What am I doing wrong?

eshaz commented 3 years ago

Your Icecast CORS policy is set up correctly. Are you serving your website using HTTPS? Browsers will block requests to HTTP resources (your Icecast server) if they are being referenced from a HTTPS origin. Disabling the Chrome web security is likely what is allowing these requests to succeed. The simplest way to fix this would be to enable HTTPS on your Icecast server: https://icecast.org/docs/icecast-2.4.1/config-file.html#path

zanarduz commented 3 years ago

Serving website over http and https, in this case accessing over http. If I access website over https and stream over http it says icecast-metadata-player-0.0.3.min.js:20 Mixed Content: The page at 'https://websiteurl' was loaded over HTTPS, but requested an insecure resource 'http://streamurl'. This request has been blocked; the content must be served over HTTPS.

I'm doing various tests... (all failed until now)

eshaz commented 3 years ago

Since you're serving on both http and https, this could be happening when you switch over to http: https://superuser.com/questions/565409/how-to-stop-an-automatic-redirect-from-http-to-https-in-chrome

zanarduz commented 3 years ago

Quite sure i'm accessing it over http, it says "not secure" and if I copy and paste the url it's "http://"

Reinstalled all the stream package (icecast, butt, etc) in another computer in another network just to test but same results.

zanarduz commented 3 years ago

Analyzed some of the stream found on your demo page and I found a solution: All the demo servers i tried were "Icecast 2.4.0-kh*", in fact the only server which works for me is Server: Icecast 2.4.0-kh15

Here is the CURL log:

curl -H "Icy-MetaData: 1" -v "http://url:port/stream"
*   Trying IP...
* TCP_NODELAY set
* Connected to IP (IP) port #### (#0)
> GET /stream HTTP/1.1
> Host: IP:port
> User-Agent: curl/7.64.1
> Accept: */*
> Icy-MetaData: 1
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Content-Type: audio/mpeg
< Date: Sat, 23 Jan 2021 16:24:30 GMT
< icy-br:128
< ice-audio-info: ice-bitrate=128;ice-channels=2;ice-samplerate=44100
< icy-name:none
< icy-pub:0
< Server: Icecast 2.4.0-kh15
< Cache-Control: no-cache, no-store
< Expires: Mon, 26 Jul 1997 05:00:00 GMT
< Connection: Close
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: Origin, Accept, X-Requested-With, Content-Type, Icy-MetaData
< Access-Control-Allow-Methods: GET, OPTIONS, SOURCE, PUT, HEAD, STATS
< icy-metaint:16000

Don't know why it's happening :(