mirror of
https://github.com/ading2210/libcurl.js.git
synced 2025-05-12 14:00:01 -04:00
handle text frames properly, add docs
This commit is contained in:
parent
b053ec8e77
commit
9cc0e4178b
6 changed files with 67 additions and 19 deletions
16
README.md
16
README.md
|
@ -7,6 +7,7 @@ This is an experimental port of [libcurl](https://curl.se/libcurl/) to WebAssemb
|
|||
- End to end encryption between the browser and the destination server
|
||||
- Support for up to TLS 1.3
|
||||
- Support for tunneling HTTP/2 connections
|
||||
- Support for proxying WebSockets
|
||||
- Bypass CORS restrictions
|
||||
- Low latency via multiplexing and reusing open connections
|
||||
|
||||
|
@ -54,6 +55,21 @@ Most of the standard Fetch API's features are supported, with the exception of:
|
|||
- Sending credentials/cookies automatically
|
||||
- Caching
|
||||
|
||||
### Creating WebSocket Connections:
|
||||
To use WebSockets, create a `libcurl.WebSocket` object, which works identically to the regular [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) object.
|
||||
```js
|
||||
let ws = new libcurl.WebSocket("wss://echo.websocket.org");
|
||||
ws.binaryType = "arraybuffer";
|
||||
ws.addEventListener("open", () => {
|
||||
console.log("ws connected!");
|
||||
ws.send("hello".repeat(128));
|
||||
});
|
||||
ws.addEventListener("message", (event) => {
|
||||
let text = new TextDecoder().decode(event.data);
|
||||
console.log(text);
|
||||
});
|
||||
```
|
||||
|
||||
### Changing the Websocket URL:
|
||||
You can change the URL of the websocket proxy by using `libcurl.set_websocket`.
|
||||
```js
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue