ghaiklor / icecast-parser

Node.js module for getting and parsing metadata from SHOUTcast/Icecast radio streams
MIT License
70 stars 17 forks source link

Icecast-parser does not work with React #183

Closed haecksenwerk closed 2 years ago

haecksenwerk commented 2 years ago

I have an issue when trying to include icecast-parser in a React project running with node v16.10.0

Directly after importing the package with

import { Parser } from 'icecast-parser';

the following error occurs:

Failed to compile.

./node_modules/icecast-parser/dist/StreamReader.js 20:115
Module parse failed: Unexpected token (20:115)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|     var _part$groups, _part$groups2;
| 
>     return map.set(((_part$groups = part.groups) === null || _part$groups === void 0 ? void 0 : _part$groups.key) ?? '', ((_part$groups2 = part.groups) === null || _part$groups2 === void 0 ? void 0 : _part$groups2.value) ?? '');
|   });
|   return map;
andreasnuesslein commented 2 years ago

wow. 4 hours ago? :D just had the same issue ^^

haecksenwerk commented 2 years ago

I got it running with working around the parsing issue of '??' in streamreader.js, but then the error 'Response to preflight request doesn't pass access control check' occurs, when fetching the stream is blocked by the browsers CORS security policy. So, seemingly the parser can't be used for this purpose.

andreasnuesslein commented 2 years ago

@haecksenwerk it seems because of CORS (having become more restrictive in the last months/years) even if you circumvent the pre-flight, it still won't let you catch icymetadata anymore, unless the streaming servers have updated headers.

long story short, i threw many hours in this issue, also with this https://github.com/eshaz/icecast-metadata-js , but in the end it was far easier for me to just provide a simple icecast-server-daemon. it's currently a Proof-of-Concept alpha, but: https://gist.github.com/andreasnuesslein/5d02c3346824bdd1a29818a63a40cab2