@skweb/socketio
v0.2.0
Published
Socket.IO runtime adapter for skweb realtime framework.
Downloads
63
Maintainers
Readme
@skweb/socketio
Socket.IO runtime adapter for skweb realtime framework.
Implements the same RealtimeApp contract as @skweb/ws, so message handlers are portable between the two runtimes. Provides Socket.IO's auto-reconnect, fallback transports, and native ack support.
Wire Format
Unlike @skweb/ws (which uses a JSON envelope { type, data, ackId }), this adapter uses Socket.IO's native named events:
// Client
socket.emit('chat.message', { text: 'hi' }, (ack) => { console.log(ack) })
// Server (via message handler)
handle(ctx) {
ctx.ack({ ok: true }) // calls the client's callback
}The adapter bridges this to the unified InboundMessage contract internally, so handler code is identical between ws and socket.io.
Usage
import { createSocketIoApp } from '@skweb/socketio'
const app = createSocketIoApp({ logger: console })
app.onConnection(socket => {
console.log('connected:', socket.id)
})
app.onMessage((socket, msg) => {
if (msg.type === 'ping') {
socket.send('pong', { timestamp: Date.now() })
}
})
app.startServe(3001)For multi-node broadcast and declarative message handlers, use RealtimeFramework from @skweb/framework.
