Socket
Socket
Sign inDemoInstall

xrs

Package Overview
Dependencies
68
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    xrs

reactive server


Version published
Weekly downloads
8.6K
decreased by-17.74%
Maintainers
1
Install size
15.7 MB
Created
Weekly downloads
 

Readme

Source

Reactive Server

  • Allows you to send a stream as input, and return a stream
  • You can also return a value, promise or stream
  • Client is ~3 kb bundled, built on top of nanosocket. Server is express + uws.
  • Allows uploading binary with progress events
Server:
xrs = reqire('xrs')
server = xrs(req => 'ack')
server = xrs(req => Promise.resolve('ack'))
server = xrs(req => stream().on('start', function(){ this.next(1); this.next(2) }))
  • You can also use the signature (req, res) if you don't want to return the value.
  • You can access the underlying uws , express and http instance on the server.
  • For additional options: you pass in { port, certs, processor } instead of just a processor function. Otherwise the port will be random, and no certs will mean you get a HTTP server rather than a HTTPS server.
  • The input stream can be accessed via req.on('data')
  • The req has the following properties: { id, socket, data, res } - data is what the client sent
Client
send = xrs()
send('value')
send(Promise.resolve('value'))
send(node.on('click').until(node.on('removed')))
  .map(...)
  .filter(...)

You can similarly send a value, promise or stream. send returns a stream of all the server responses. In all cases, you get a sent event on the stream when it's actually sent. When sending binaries you can also associate some metadata, and get a stream of progress events (this is from the end-to-end tests):

const results = []
await send(binary, { foo: 'bar' })
  .on('sent', d => results.push({ type: 'sent', value: d }))
  .on('progress', d => results.push({ type: 'progress', value: d }))
  .map(d => results.push({ type: 'complete', value: d }))
  .filter(d => results.length === 4)

results === [
  { type: 'sent'    , value: { id: '1' } }
, { type: 'progress', value: { received: 1024, total: 2000 } }
, { type: 'progress', value: { received: 2000, total: 2000 } }
, { type: 'complete', value: 'ack' }
]

Keywords

FAQs

Last updated on 22 Apr 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc