Package detail

@miniflare/web-sockets

cloudflare478.6kMITdeprecated2.14.4

Miniflare v2 is no longer supported. Please upgrade to Miniflare v4

WebSocket module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers

cloudflare, workers, worker, local

readme

@miniflare/web-sockets

WebSocket module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers. See ✉️ WebSockets for more details.

Example

import StandardWebSocket from "ws";
import { WebSocketPair, coupleWebSocket } from "@miniflare/web-sockets";

const [webSocket1, webSocket2] = Object.values(new WebSocketPair());

// Manually accept the first WebSocket
webSocket1.accept();
webSocket1.addEventListener("message", (event) => {
  console.log(event.data);
});
webSocket1.send("hello");

// Couple (forward messages from/to) the second WebSocket with a real WebSocket
const ws = new StandardWebSocket("ws://...");
coupleWebSocket(ws, webSocket2);