1.0.0 • Published 5 years ago
@ssvn/library v1.0.0
wsrpc
Client-side
// <script src='/wsrpc.js'></script>
var api = { }
ws = wsrpc.open('/ws', api)
api.foo = function (ws, args) {
// *** ws is a wrapper here: ws == {ws, ok, error, call}
console.log(args.x, args.y)
setTimeout(() => ws.error('foo timeout error'), 5000)
ws.call('ask_back', {pi:3.14, s:'Hello'})
.then(result => ws.ok('roundtrip done'))
.catch(error => ws.error('roundtrip error'))
}
Server-side
var wsrpc = require('@ssvn/library/wsrpc')
require('express-ws')(app)
app.ws('/ws', (ws, request) => wsrpc.init(ws, {request}, api))
Additional fields after wsrpc.init/open
ws.id new unique id (integer)
ws.address peer address
ws.api api
ws.promises outgoing call promises
sqlite
TODO
ut
TODO
1.0.0
5 years ago