@altafonte/simple-secure-websocket-server
Package to easily create a WebSocket server that runs over TLS.
Quick Links
Usage
Server
import { createSimpleSecureWebsocketServer } from "https://deno.land/x/simple-secure-websocket-server/mod.ts";
const socketHandler = (socket: WebSocket) => {
socket.onerror = (e) => console.error("socket error", e);
socket.onopen = () => console.log("new socket connection", socket);
socket.onclose = () => console.log("bye, socket connection", socket);
};
const server = createSimpleSecureWebsocketServer({
socketHandler,
port: 8888,
certFile: "./certs/certfile.pem", // certfile path
keyFile: "./certs/keyfile.pem", // keyfile path
});
server.listen();
Client
const ws = new WebSocket("wss://127.0.0.1:8888/websocket");
ws.addEventListener("open", () => console.log("open"));
ws.addEventListener("close", () => console.log("close"));
ws.addEventListener("message", e => console.log("message!", e));