itty-sockets
v0.9.2
Published
WebSockets : simplified and minified.
Readme
Full Documentation | Discord
Zero-Config WebSockets.
No accounts, no API keys, nothing to deploy. Just connect and start sending.
~466 bytes • free forever
After building realtime apps for years, I wanted something absolutely frictionless for prototyping. Spinning up socket servers or authenticating to services like Pusher/Ably involves overhead every time... so I built a service for myself (and everyone else). Then I designed this super-tiny WebSocket client that made even that side really easy to work with.
Welcome to
itty-sockets!
Features
- Zero Configuration - No accounts, no API keys, no server. Pick a channel name and you're live.
- Zero Cost - No tiers. No credit card. Built for the community.
- Private by Default - No logging, no tracking, no storage. Messages are relayed and forgotten.
- Send Anything - Strings, objects, arrays — anything JSON-serializable.
- Access Control - Reserve a namespace to control who can join or send on your channels.
- Use Anywhere - No vendor lock. This client works with any WebSocket server. Want to host your own? No problem.
- Tiny Client - Only 466 bytes gzipped.
Quick Start
import { connect } from 'itty-sockets' // ~466 bytes
connect('my-channel')
.on('message', ({ message }) => console.log(message))
.send('hello world') // strings
.send([1, 2, 3]) // arrays
.send({ foo: 'bar' }) // objectsChat Example
import { connect } from 'itty-sockets'
// two users, same channel
const alice = connect('chat-room', { as: 'Alice' })
const bob = connect('chat-room', { as: 'Bob' })
alice.on('message', ({ message, alias }) =>
console.log(`${alias}: ${message}`)
)
bob.send('hey Alice!')
// → "Bob: hey Alice!"API at a Glance
| Method | Description |
|---|---|
| connect(channel, options?) | Connect to a channel (or raw wss:// URL) |
| .on(type, listener) | Listen for events ('message', 'join', 'leave', 'open', 'close', 'error', custom types, or '*') |
| .on(filterFn, listener) | Listen with a custom filter function |
| .send(message, uid?) | Send a message (optionally to a specific user) |
| .push(message, uid?) | Send a message and disconnect |
| .open() | (Re)connect — safe to call anytime, listeners are preserved |
| .close() | Disconnect |
| .remove(type, listener) | Remove a listener |
