diff --git a/README.md b/README.md index 6c30bf5..a1130ee 100644 --- a/README.md +++ b/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: You can change the URL of the websocket proxy by using `libcurl.set_websocket`. ```js @@ -153,11 +159,16 @@ If you want more information about a connection, you can pass the `_libcurl_verb ```js 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. ```js 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: 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. diff --git a/client/fragments/wisp_support.js b/client/fragments/wisp_support.js index 8ed84cd..f383585 100644 --- a/client/fragments/wisp_support.js +++ b/client/fragments/wisp_support.js @@ -1,4 +1,14 @@ /* REPLACE new WebSocketConstructor */ -new WispWebSocket \ No newline at end of file +new ((() => { + if (api.transport === "wisp") { + return WispWebSocket; + } + else if (api.transport === "wsproxy") { + return WebSocket; + } + else { //custom transports + return api.transport; + } +})()) diff --git a/client/javascript/main.js b/client/javascript/main.js index 1db8f67..d6b1884 100644 --- a/client/javascript/main.js +++ b/client/javascript/main.js @@ -244,6 +244,7 @@ api = { wisp_connections: _wisp_connections, WispConnection: WispConnection, + transport: "wisp", get copyright() {return copyright_notice}, get version() {return get_version()},