summaryrefslogtreecommitdiff
path: root/ws/mod.ts
diff options
context:
space:
mode:
Diffstat (limited to 'ws/mod.ts')
-rw-r--r--ws/mod.ts18
1 files changed, 10 insertions, 8 deletions
diff --git a/ws/mod.ts b/ws/mod.ts
index 316e19abd..2f85e58f8 100644
--- a/ws/mod.ts
+++ b/ws/mod.ts
@@ -480,15 +480,17 @@ export async function connectWebSocket(
headers: Headers = new Headers()
): Promise<WebSocket> {
const url = new URL(endpoint);
- let { hostname, port } = url;
- if (!port) {
- if (url.protocol === "http" || url.protocol === "ws") {
- port = "80";
- } else if (url.protocol === "https" || url.protocol === "wss") {
- throw new Error("currently https/wss is not supported");
- }
+ let { hostname } = url;
+ let conn: Conn;
+ if (url.protocol === "http:" || url.protocol === "ws:") {
+ const port = parseInt(url.port || "80");
+ conn = await Deno.dial({ hostname, port });
+ } else if (url.protocol === "https:" || url.protocol === "wss:") {
+ const port = parseInt(url.port || "443");
+ conn = await Deno.dialTLS({ hostname, port });
+ } else {
+ throw new Error("ws: unsupported protocol: " + url.protocol);
}
- const conn = await Deno.dial({ hostname, port: Number(port) });
const bufWriter = new BufWriter(conn);
const bufReader = new BufReader(conn);
try {