0

I'm trying to get audio stream data from IP camera using JavaScript fetch API. The problem is that on standard http request this IP camera responses with audio data without any HTTP header. Check this my another question for details with excellent answer:

https://stackoverflow.com/a/75474493/6612987

I'm using standard code like this:

(async () => {
    let response = await fetch(URL);
    const reader = response.body.getReader();
    //do something
})()

This code work without any errors in Firefox, but Chromium based browsers give me: ERR_INVALID_HTTP_RESPONSE on fetch.

Is this possible any workaround for fetch API or other JavaScript alternatives to get data for non standard response?

alexeynl
  • 11
  • 5
  • Please don't refer to other questions for details. Each post on Stack Overflow should be self-contained with all the necessary information to understand and solve it. Consider what would happen if your other question was deleted – Phil Mar 02 '23 at 22:28
  • From your description, that doesn't sound like "non-standard HTTP". It's just not HTTP at all. More likely a plain TCP stream and the camera even ignores your request data. – Bergi Mar 02 '23 at 22:40
  • 1
    And no, you can't use non-HTTP networking from the browser. – Bergi Mar 02 '23 at 22:41
  • 2
    So get a better camera, or write a proxy sever that translates the camera stream into something your website (?) can process. – Bergi Mar 02 '23 at 22:42
  • To be more specific this half-HTTP. In that sense that server understand and apply http request, but send response that is not HTTP. As i mention in current answer Firefox browser process this response successfully. You can check screenshot https://i.stack.imgur.com/3B5ko.jpg – alexeynl Mar 02 '23 at 22:49
  • Is this a same-origin request? – Ry- Mar 02 '23 at 23:03
  • No it is cross-origin. I try to make extension for browser that play audio stream by specified camera's URL. I already success with Firefox but now want to make extension for another browsers. – alexeynl Mar 02 '23 at 23:07
  • @Bergi, actually you can use a few other protocols than HTTP, see just for WebRTC: https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API/Protocols – Kaiido Mar 03 '23 at 00:44
  • Do you have some docs for the ip camera so we can get our own idea of what you have? – Kaiido Mar 03 '23 at 00:48
  • @Kaiido, there are no official docs. I use this article: http://www.instructables.com/id/Hack-a-30-WiFi-Pan-Tilt-Camera-Video-Audio-and-Mot/ – alexeynl Mar 03 '23 at 05:59

1 Answers1

0

fetch only speaks HTTP. Browsers will simply not allow you to interact with sockets that don't speak HTTP.

Evert
  • 93,428
  • 18
  • 118
  • 189