mirror of
https://github.com/ading2210/libcurl.js.git
synced 2025-05-13 14:30:02 -04:00
add custom network transport support
This commit is contained in:
parent
53a474430a
commit
be3fc7286c
3 changed files with 23 additions and 1 deletions
11
README.md
11
README.md
|
@ -141,6 +141,12 @@ socket.onmessage = (data) => {
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Changing the Network Transport:
|
||||||
|
You can change the underlying network transport by setting `libcurl.transport`. The following values are accepted:
|
||||||
|
- `"wisp"` - Use the [Wisp protocol](https://github.com/MercuryWorkshop/wisp-protocol).
|
||||||
|
- `"wsproxy"` - Use the wsproxy protocol, where a new websocket is created for each TCP connection.
|
||||||
|
- Any custom class - Use a custom network protocol. If you pass in custom code here, it must be roughly conformant with the standard `WebSocket` API. The URL that is passed into this fake websocket always looks like `"wss://example.com/ws/ading.dev:443"`, where `wss://example.com/ws/` is the proxy server URL, and `ading.dev:443` is the destination server.
|
||||||
|
|
||||||
### Changing the Websocket Proxy URL:
|
### Changing the Websocket Proxy URL:
|
||||||
You can change the URL of the websocket proxy by using `libcurl.set_websocket`.
|
You can change the URL of the websocket proxy by using `libcurl.set_websocket`.
|
||||||
```js
|
```js
|
||||||
|
@ -153,11 +159,16 @@ If you want more information about a connection, you can pass the `_libcurl_verb
|
||||||
```js
|
```js
|
||||||
await libcurl.fetch("https://example.com", {_libcurl_verbose: 1});
|
await libcurl.fetch("https://example.com", {_libcurl_verbose: 1});
|
||||||
```
|
```
|
||||||
|
|
||||||
By default this will print the output to the browser console, but you can set `libcurl.stdout` and `libcurl.stderr` to intercept these messages. This callback will be executed on every line of text that libcurl outputs.
|
By default this will print the output to the browser console, but you can set `libcurl.stdout` and `libcurl.stderr` to intercept these messages. This callback will be executed on every line of text that libcurl outputs.
|
||||||
```js
|
```js
|
||||||
libcurl.stderr = (text) => {document.body.innerHTML += text};
|
libcurl.stderr = (text) => {document.body.innerHTML += text};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Libcurl.js will also output some error messages to the browser console. You can intercept these messages by setting the `libcurl.logger` callback, which takes two arguments:
|
||||||
|
- `type` - The type of message. This will be one of the following: `"log"`, `"warn"`, `"error"`
|
||||||
|
- `text` - The text that is to be logged.
|
||||||
|
|
||||||
### Getting Version Info:
|
### Getting Version Info:
|
||||||
You can get version information from the `libcurl.version` object. This object will also contain the versions of all the C libraries that libcurl.js uses. `libcurl.version.lib` returns the version of libcurl.js itself.
|
You can get version information from the `libcurl.version` object. This object will also contain the versions of all the C libraries that libcurl.js uses. `libcurl.version.lib` returns the version of libcurl.js itself.
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,14 @@
|
||||||
/* REPLACE
|
/* REPLACE
|
||||||
new WebSocketConstructor
|
new WebSocketConstructor
|
||||||
*/
|
*/
|
||||||
new WispWebSocket
|
new ((() => {
|
||||||
|
if (api.transport === "wisp") {
|
||||||
|
return WispWebSocket;
|
||||||
|
}
|
||||||
|
else if (api.transport === "wsproxy") {
|
||||||
|
return WebSocket;
|
||||||
|
}
|
||||||
|
else { //custom transports
|
||||||
|
return api.transport;
|
||||||
|
}
|
||||||
|
})())
|
||||||
|
|
|
@ -244,6 +244,7 @@ api = {
|
||||||
|
|
||||||
wisp_connections: _wisp_connections,
|
wisp_connections: _wisp_connections,
|
||||||
WispConnection: WispConnection,
|
WispConnection: WispConnection,
|
||||||
|
transport: "wisp",
|
||||||
|
|
||||||
get copyright() {return copyright_notice},
|
get copyright() {return copyright_notice},
|
||||||
get version() {return get_version()},
|
get version() {return get_version()},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue