Create a fetch
-based WebSocket wrapper
#62
Labels
addition/proposal
New features or enhancements
needs implementer interest
Moving the issue forward requires implementers to express interest
What problem are you trying to solve?
Issues like #16 and #18 eventually extend to requiring arbitrary HTTP manipulation, and implementors (notably Chromium) have found it very difficult to extend it with arbitrary header support, having fused it with images.
There's also no way to inspect the response data or even view the HTTP response code of a rejected WebSocket connection attempt.
What solutions exist today?
Currently, none. You can get halfway there with
fetch({duplex: "half"})
, but the necessary WebSocket setup headers are all forbidden byfetch
.How would you solve it?
Something like this:
response = await fetch(url, {mode: "websocket"})
: Set up a WebSocket request.response.body
contains a similar object stream of results, ifresponse.status === 101
. This stream has an overriddenclose
method that lets callers close.response
also contains any headers sent back from the server.fetch
options work as usual.Anything else?
There already is some userland precedent for such an API: https://www.npmjs.com/package/@microsoft/fetch-event-source
The text was updated successfully, but these errors were encountered: