Official JavaScript/TypeScript SDK for wSocket — Realtime Pub/Sub over WebSockets.
npm install @wsocket-io/sdk<script src="https://cdn.jsdelivr.net/npm/@wsocket-io/sdk@latest"></script>import { createClient } from '@wsocket-io/sdk';
const client = createClient('wss://node00.wsocket.online', 'your-api-key');
client.connect();
const chat = client.channel('chat:general');
chat.subscribe((data, meta) => {
console.log(`[${meta.channel}]`, data);
});
chat.publish({ text: 'Hello from JavaScript!' });- Pub/Sub — Subscribe and publish to channels in real-time
- Presence — Track who is online in a channel
- History — Retrieve past messages
- Push Notifications — Web Push via Service Workers
- Connection Recovery — Automatic reconnection with message replay
- TypeScript — Full type definitions included
const chat = client.channel('chat:general');
chat.presence.onEnter((member) => {
console.log(`Joined: ${member.clientId}`);
});
chat.presence.onLeave((member) => {
console.log(`Left: ${member.clientId}`);
});
chat.presence.enter({ name: 'Alice' });
const members = chat.presence.get();chat.onHistory((result) => {
result.messages.forEach((msg) => {
console.log(`[${msg.timestamp}] ${JSON.stringify(msg.data)}`);
});
});
chat.history({ limit: 50 });client.configurePush({
vapidPublicKey: 'your-vapid-public-key',
serviceWorkerPath: '/sw.js',
});
await client.push?.subscribe('alerts');- Node.js >= 18 or modern browsers
ws >= 8.0(Node.js only)
npm install
npm run build
npm testMIT