A production-grade, high-availability, auto-recovery, dual-end WebSocket toolkit.
Go Server + TypeScript Client β Solving all WebSocket pain points in one package.
Building reliable WebSocket applications is hard. You need to handle reconnections, heartbeats, message acknowledgments, and more. WarpSocket provides a complete solution with:
- Go Server β Robust, concurrent-safe WebSocket server with connection management
- TypeScript Client β Auto-reconnecting client with seamless recovery for browser & Node.js
| Feature | Description |
|---|---|
| π Auto Reconnection | Exponential backoff strategy (1s β 2s β 4s β 8s...) |
| π Heartbeat Keep-Alive | Automatic ping/pong with connection health monitoring |
| β Message ACK | Reliable message delivery with acknowledgment mechanism |
| πΎ Message Persistence | Optional message caching and queue for offline scenarios |
| π Auto Retry | Automatic resend for unacknowledged messages |
| π Full-Duplex Protocol | Unified message protocol for both ends |
| π‘οΈ Middleware System | Interceptors for logging, authentication, and more |
| π‘ Event-Driven | Clean event-based API for all connection states |
| π Type-Safe | Full TypeScript + Go type definitions |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β WarpSocket β
βββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββ€
β Go Server β TypeScript Client β
βββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββ€
β β’ Connection Manager β β’ Auto Reconnection β
β β’ Lifecycle Hooks β β’ Network Status Detection β
β β’ Heartbeat Detection β β’ Background/Foreground Recovery β
β β’ Concurrent-Safe Write β β’ Message Queue & Retry β
β β’ Broadcast/Unicast β β’ State Management β
β β’ Room/Channel Support β β’ Event-Driven API β
β β’ Middleware System β β’ TypeScript Type Safety β
βββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββ
Both Go server and TypeScript client share the same message format:
{
"type": "event | ack | heartbeat",
"id": "uuid",
"data": {},
"timestamp": 1700000000000
}Go Server
- WebSocket connection manager
- Connection lifecycle hooks (OnOpen/OnClose/OnError)
- Automatic heartbeat (Ping/Pong)
- Concurrent-safe write operations
- Broadcast / Unicast / Group send
- Automatic resource cleanup on disconnect
TypeScript Client
- Exponential backoff auto-reconnection
- Network status detection (
navigator.onLine) - Background/foreground recovery
- Manual/auto reconnection control
- Automatic heartbeat maintenance
- State machine:
connectingβopenβdisconnectedβreconnecting
Go Server
- Message ACK confirmation
- Unacknowledged message timeout handling
- Connection rate limiting
- Idle connection eviction
- Middleware system (logging, interceptors, auth)
TypeScript Client
- Message send queue (offline caching)
- Auto-send pending messages on reconnect
- Message deduplication (idempotency)
- Timeout retry mechanism
- Manual/auto ACK
- State restoration after reconnect
Go Server
- Distributed support (Redis pub/sub)
- Room/Channel system
- Connection metrics & monitoring
- Security validation (Origin check, Token auth)
- Graceful shutdown
TypeScript Client
- Max reconnection attempts
- Network change detection (WiFi/5G switch)
- Custom reconnection conditions
- Custom encoding/decoding (Protobuf support)
- Node.js + Browser dual environment
Tooling
- Unified error codes
- Debug mode
- Performance statistics
- Reconnection success rate metrics
- State sync after reconnection
- Message compression
- Binary message support
- Flow control
- Custom retry strategies
- Distributed message sync
- Connection state animations
- Isomorphic TS-Go protocol definitions
Security
- TLS/SSL support (WSS)
- JWT token authentication & auto-refresh
- Message encryption (AES-256)
- Message signature verification
- IP whitelist/blacklist
Performance
- Backpressure control
- Message batching
- Connection pooling
- Zero-copy optimization
Developer Experience
- Browser DevTools extension
- CLI testing tool
- Mock server for frontend development
- React/Vue hooks
Observability
- Prometheus metrics export
- OpenTelemetry integration
- Health check HTTP endpoint
- Slow message alerts
Protocol
- Message priority queue
- Large file transfer (chunked)
- Message TTL expiration
- Request-Response (RPC) pattern
Cluster
- Session persistence (Redis)
- Service discovery (Consul/etcd)
- Load balancer awareness
go get github.com/leoheung/wrapsocket/go-patternsnpm install wrapsocket-ts
# or
yarn add wrapsocket-ts
# or
pnpm add wrapsocket-tswrapsocket/
βββ go-patterns/ # Go server implementation
β βββ net/ # Network utilities
β βββ parallel/ # Concurrency patterns
β βββ container/ # Data structures
β βββ utils/ # Helper functions
βββ wrapsocket-ts/ # TypeScript client implementation
βββ README.md
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Made with β€οΈ by leoheung