A drop-in replacement for WebSocket that automatically reconnects, buffers messages while disconnected, and handles connection timeouts. Version 1.1.19 is stable with regular updates. Supports multiple environments (Web, Node.js, React Native, Cloudflare Workers, Deno, Bun) and can be used independently of PartyKit. Key differentiators: built-in message buffering, dynamic URL/protocol providers, and zero dependencies.
npm install partysocketNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to create a PartySocket connection to a PartyKit room with event listeners for open and message events.
Use options object: new PartySocket({ host: '...', room: '...' }) instead of new PartySocket('wss://...', [], {...})After ws.updateProperties(...), always call ws.reconnect() to apply changes.
Add 'WebSocket: require("ws")' to the options object or use import WS from 'ws' and pass as WebSocket: WS.Install 'ws' and provide it via options: new PartySocket({ host: '...', room: '...', WebSocket: WS })Use 'import PartySocket from "partysocket"' instead of 'import { PartySocket } from "partysocket"'.Change import to default: import PartySocket from 'partysocket'.
Provide an object with at least 'host' and 'room': new PartySocket({ host: 'myhost', room: 'myroom' }).Verify the host and port are correct and the server is running. In dev, ensure localhost:1999 is active.