Reusable WebSocket wrapper with builder pattern, exponential/linear/constant backoff strategies, JSON/Bebop serialization, SolidJS reactive effects, heartbeat, and auto-reconnection. Works standalone in any TypeScript project.
# WebSocket
Shared, type-safe WebSocket abstraction with reconnect, buffering, heartbeat,
serialization, and Solid lifecycle helpers. Import its public API through the
`@macro-inc/collaboration/websocket` export.
## Basic Usage
```typescript
import { JsonSerializer, WebsocketBuilder, WebsocketEvent } from '@macro-inc/collaboration/websocket';
const ws = new WebsocketBuilder('ws://localhost:5000')
.withSerializer(new JsonSerializer<SendType, ReceiveType>())
.build();
ws.addEventListener(WebsocketEvent.Message, (_socket, event) => {
console.log('Received:', event.data);
});
ws.send({ type: 'hello' });
```
## Builder Pattern
```typescript
import { ExponentialBackoff, WebsocketBuilder } from '@macro-inc/collaboration/websocket';
const ws = new WebsocketBuilder('ws://localhost:50
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key