Package Exports
- xrs
- xrs/client
- xrs/server
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (xrs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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,expressandhttpinstance on theserver. - For additional options: you pass in
{ port, certs, processor }instead of just aprocessorfunction. Otherwise theportwill be random, and nocertswill mean you get a HTTP server rather than a HTTPS server. - The input stream can be accessed via
req.on('data') - The
reqhas the following properties:{ id, socket, data, res }-datais 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' }
]