@d1testflare/web-sockets
TypeScript icon, indicating that this package has built-in type declarations

2.9.0 • Public • Published

@d1testflare/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 "@d1testflare/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);

Package Sidebar

Install

npm i @d1testflare/web-sockets

Weekly Downloads

11

Version

2.9.0

License

MIT

Unpacked Size

23.2 kB

Total Files

5

Last publish

Collaborators

  • oconnorct1