SockPipe
Reactive Node.js backend with web sockets
Install / Use
/learn @italonascimento/SockPipeREADME
SockPipe
SockPipe is a Node.js framework for development of websocket servers with use of reactive programming.
Basic helloworld, echo and ping server
const http = require('http')
const { sockpipe } = require('sockpipe')
const server = http.createServer((req, res) => {
console.log('Received request for ' + request.url);
response.writeHead(404);
response.end();
})
.listen(8080)
const sockpipeServer = sockpipe({
httpServer: server,
debug: true
}, (msg$) => [
// Any message of type 'greetings' will be responded
// with a 'Hello World'
msg$.filter(msg => msg.type === 'greetings')
.mapTo({
type: 'greetings',
data: 'Hello World'
}),
// Any message of type 'echo' will be sent back
// exactly the same
msg$.filter(msg => msg.type === 'echo'),
// Each one second the server will send a message
// of type 'ping' to it's clients
Observable.interval(1000)
.mapTo({
type: 'ping',
})
])
.on('connect', () => console.log('[SockPipe] A client has connected'))
.on('close', () => console.log('[SockPipe] A client has left'))
Routing messages by type
To simplify the rounting of messages by type, you may use the helper function
createRouter:
const http = require('http')
const { sockpipe, createRouter } = require('sockpipe')
const server = http.createServer((req, res) => {
serve(req, res, finalhandler(req, res))
})
.listen(8080)
const sockpipeServer = sockpipe({
httpServer: server,
}, (msg$) => [
const route = createRouter(msg$)
// The callback receives an Observable of the message 'data' alone
// and doesn't need to worry about returning the 'type' either.
route('greetings', greetingsHandler)
])
function greetingsHandler(msgData$) {
return msgData$.mapTo({ data: 'Hello World' })
}
Demos
For more useful exemples, such as GraphQL and authentication, check the demos folder:
https://github.com/italonascimento/SockPipe/tree/master/demo
Related Skills
node-connect
349.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.5kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
