mirror of
https://github.com/ading2210/libcurl.js.git
synced 2025-05-14 06:50:00 -04:00
31 lines
710 B
JavaScript
31 lines
710 B
JavaScript
/* REPLACE
|
|
ws ?= ?new WebSocketConstructor\(url, ?opts\)
|
|
*/
|
|
try {
|
|
let transport;
|
|
let tls = url.includes("---tls-enabled---");
|
|
url = url.replace("---tls-enabled---", "");
|
|
if (api.transport === "wisp") {
|
|
transport = new WispWebSocket(url);
|
|
}
|
|
else if (api.transport === "wsproxy") {
|
|
transport = new WebSocket(url);
|
|
}
|
|
else if (typeof api.transport === "string") {
|
|
throw new TypeError("invalid transport type");
|
|
}
|
|
else { //custom transports
|
|
transport = new api.transport(url);
|
|
}
|
|
//
|
|
if (tls) {
|
|
ws = new tls_shim.ReclaimTLSSocket(url, transport);
|
|
}
|
|
else {
|
|
ws = transport;
|
|
}
|
|
}
|
|
catch (e) {
|
|
error_msg("Error while creating a TCP connection: " + e);
|
|
throw e;
|
|
}
|