Comparing version 0.11.0 to 0.12.0
64
Booth.js
@@ -1,48 +0,52 @@ | ||
'use strict'; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
import Events from './Events' | ||
import Endpoint from './Endpoint' | ||
var flyd = _interopDefault(require('flyd')); | ||
var Endpoint = _interopDefault(require('./Endpoint')); | ||
/* */ | ||
/* global flyd$Stream */ | ||
/* global Booth$Socketio */ | ||
export default function Booth (wss) | ||
{ | ||
wss = Wss(wss) | ||
var booth = { wss } | ||
var events = booth.events = Events(booth) | ||
booth.on = function on (...args) | ||
{ | ||
events.on(...args) | ||
return booth | ||
} | ||
var stream = flyd.stream; | ||
booth.close = function close () | ||
{ | ||
wss.close() | ||
} | ||
var noop = () => {}; | ||
wss.on('connection', (ws) => | ||
{ | ||
Endpoint(ws, booth) | ||
}) | ||
function Booth | ||
( | ||
socketio, | ||
make = noop | ||
) | ||
{ | ||
/* @flow-off */ | ||
var clients = stream(); | ||
var booth = | ||
{ | ||
socketio, | ||
clients, | ||
}; | ||
return booth | ||
} | ||
socketio.on('connection', socket => | ||
{ | ||
var endpoint = Endpoint(socket); | ||
make(endpoint); | ||
import { Server } from 'ws' | ||
clients(endpoint); | ||
}); | ||
function Wss (wss) | ||
{ | ||
if (is_plain(wss)) | ||
{ | ||
return new Server(wss) | ||
} | ||
return booth | ||
return wss | ||
} | ||
module.exports = Booth; | ||
function is_plain (object) | ||
{ | ||
return (Object.getPrototypeOf(object) === Object.prototype) | ||
} |
184
Endpoint.js
@@ -1,139 +0,113 @@ | ||
'use strict'; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
import Events from './Events' | ||
var Promise = _interopDefault(require('bluebird')); | ||
var flyd = _interopDefault(require('flyd')); | ||
var Seq = _interopDefault(require('./lib/seq')); | ||
var hashmap = _interopDefault(require('./lib/hashmap')); | ||
var ns = _interopDefault(require('./lib/ns-booth')); | ||
var keys = _interopDefault(require('./lib/keys')); | ||
var tup3 = _interopDefault(require('./lib/tup3')); | ||
/* */ | ||
/* global Booth$Socket */ | ||
/* global $Promisable */ | ||
/* global Bluebird$Promise */ | ||
/* global flyd$Stream */ | ||
export default function Endpoint (ws, booth) | ||
{ | ||
if (booth) | ||
{ | ||
var events = booth.events | ||
var endp = | ||
{ | ||
ws: null, | ||
booth, | ||
on () { return endp }, | ||
} | ||
} | ||
else | ||
{ | ||
var events = Events() | ||
var method = Promise.method; | ||
var endp = | ||
{ | ||
ws: null, | ||
on, | ||
} | ||
var stream = flyd.stream; | ||
var on = flyd.on; | ||
function on (...args) | ||
{ | ||
events.on(...args) | ||
var timeout = 5 * 1000; | ||
return endp | ||
} | ||
} | ||
function Endpoint (socket) | ||
{ | ||
var seq = Seq(); | ||
var instance = Math.random().toString(36).slice(-5).toUpperCase(); | ||
function connect () | ||
{ | ||
if (endp.ws) | ||
{ | ||
endp.ws.close() | ||
} | ||
var awaiters = {}; | ||
var handlers = {}; | ||
endp.ws = Ws(ws) | ||
ev('message', (data) => events.handle(data, endp)) | ||
var endpoint = | ||
{ | ||
socket, | ||
request, | ||
realtime, | ||
}; | ||
ev('open', () => events.emit('@open', void 0, endp)) | ||
ev('close', () => events.emit('@close', void 0, endp)) | ||
ev('error', (e) => events.emit('@error', e, endp)) | ||
ev('close', reconnect) | ||
socket.once('disconnect', () => | ||
{ | ||
awaiters = hashmap(); | ||
handlers = hashmap(); | ||
socket.removeAllListeners(ns(keys.request)); | ||
socket.removeAllListeners(ns(keys.request_return)); | ||
socket.removeAllListeners(ns(keys.realtime)); | ||
}); | ||
if (booth) | ||
{ | ||
setTimeout(() => events.emit('@open', void 0, endp)) | ||
} | ||
function ev (name, handler) | ||
{ | ||
endp.ws.addEventListener(name, handler) | ||
} | ||
} | ||
/* #request */ | ||
function request (name, data) | ||
function reconnect () | ||
{ | ||
var id = `${ seq() }.${ instance }`; | ||
if (booth) return | ||
socket.emit(ns(keys.request), [ name, id, data ]); | ||
if (! endp) return | ||
return new Promise((rs, rj) => | ||
{ | ||
awaiters[id] = [ rj, rs ]; | ||
}) | ||
.timeout(timeout) | ||
.finally(() => | ||
{ | ||
delete awaiters[id]; | ||
}) | ||
endp.ws = null | ||
setTimeout(connect, 1e3) | ||
} | ||
request.register = (name, handler) => | ||
{ | ||
handlers[name] = method(handler); | ||
}; | ||
socket.on(ns(keys.request), | ||
tup3('string', (name, id, data) => | ||
endp.send = function send (kind, data) | ||
{ | ||
if (name in handlers) | ||
{ | ||
handlers[name](data) | ||
.timeout(timeout) | ||
.then( | ||
resp => | ||
{ | ||
socket.emit(ns(keys.request_return), [ 1, id, resp ]); | ||
}, | ||
resp => | ||
{ | ||
/* TODO guard resp?: */ | ||
socket.emit(ns(keys.request_return), [ 0, id, resp ]); | ||
}); | ||
} | ||
})); | ||
endp.ws.send('@' + kind + ':' + data) | ||
socket.on(ns(keys.request_return), | ||
tup3('number', (state, id, data) => | ||
return endp | ||
} | ||
endp.close = function close () | ||
{ | ||
if (id in awaiters) | ||
{ | ||
if ((state === 0) || (state === 1)) | ||
{ | ||
awaiters[id][state](data); | ||
} | ||
} | ||
})); | ||
/* - */ | ||
if (! endp) return | ||
if (! endp.ws) return | ||
endp.ws.close() | ||
/* #realtime */ | ||
function realtime (name) | ||
{ | ||
var s = stream(); | ||
var nsname = ns(keys.realtime, name); | ||
delete endp.ws | ||
delete endp.booth | ||
socket.on(nsname, s); | ||
on(end => end && socket.removeListener(nsname, s), s.end); | ||
socket.once('disconnect', () => s.end(true)); | ||
return s | ||
endp = null | ||
} | ||
realtime.dispatch = (name, data) => | ||
{ | ||
socket.emit(ns(keys.realtime, name), data); | ||
}; | ||
connect() | ||
realtime.register = (name, stream) => | ||
return endp | ||
} | ||
import Client from 'isomorphic-ws' | ||
function Ws (ws) | ||
{ | ||
if (typeof ws === 'string') | ||
{ | ||
on(data => endpoint.realtime.dispatch(name, data), stream); | ||
}; | ||
/* - */ | ||
return new Client(ws) | ||
} | ||
return endpoint | ||
return ws | ||
} | ||
module.exports = Endpoint; |
108
package.json
{ | ||
"name": "booth", | ||
"version": "0.11.0", | ||
"name": "booth", | ||
"version": "0.12.0", | ||
"license": "ISC", | ||
"author": "Strider <strange.transistor@gmail.com>", | ||
"description": "Booth provides request-response over socket.io and creates FRP streams from socket.io events", | ||
"homepage": "https://github.com/StreetStrider/booth", | ||
"repository": { | ||
"url": "https://github.com/StreetStrider/booth.git", | ||
"type": "git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/StreetStrider/booth/issues" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
}, | ||
"main": "Booth", | ||
"files": [ | ||
"*.js", | ||
"*.js.flow", | ||
"lib", | ||
"jsnext", | ||
"flow-typed", | ||
"!.eslintrc.js" | ||
"description": "Booth provides symmetric Event API over websocket or unix domain socket", | ||
"homepage": "https://github.com/StreetStrider/booth", | ||
"repository": { "url": "https://github.com/StreetStrider/booth.git", "type": "git" }, | ||
"bugs": { "url": "https://github.com/StreetStrider/booth/issues" }, | ||
"esm": true, | ||
"engines": { "node": ">=8" }, | ||
"files": | ||
[ | ||
"index.js", | ||
"Events.js", | ||
"Booth.js", | ||
"Endpoint.js" | ||
], | ||
"peerDependencies": { | ||
"socket.io": "2", | ||
"flyd": "0.2" | ||
"peerDependencies": | ||
{ | ||
"ws": | ||
"6 || 7" | ||
}, | ||
"scripts": { | ||
"start": "npm run dev", | ||
"dev": "metalbox p dev", | ||
"npm": "metalbox p npm", | ||
"st": "eslint .", | ||
"flow": "flow check", | ||
"unit": "mocha --recursive release/dev/test/case/", | ||
"test": "npm run st && npm run flow && npm run dev -- -1 && npm run unit" | ||
"scripts": | ||
{ | ||
"start": "node -r esm readme", | ||
"st": "eslint *.js test/", | ||
"unit": "rm -f /tmp/booth; node -r esm test/unix.test", | ||
"test": "npm run st && npm start && npm run unit" | ||
}, | ||
"dependencies": { | ||
"bluebird": "3.5", | ||
"flyd": "0.2" | ||
"dependencies": | ||
{ | ||
"isomorphic-ws": | ||
"4", | ||
"nanoevents": | ||
"1", | ||
"esm": | ||
"3" | ||
}, | ||
"devDependencies": { | ||
"socket.io": "2", | ||
"socket.io-client": "2", | ||
"metalbox": "1.16", | ||
"eslint": "3", | ||
"js-outlander": "StrangeTransistor/js-outlander#2.1.1", | ||
"mocha": "3", | ||
"chai": "3", | ||
"flow-bin": "0.54", | ||
"flow-typed": "2" | ||
}, | ||
"jsnext:main": "jsnext/Booth", | ||
"module": "jsnext/Booth" | ||
} | ||
"devDependencies": | ||
{ | ||
"eslint": | ||
"5", | ||
"js-outlander": | ||
"StrangeTransistor/js-outlander#2.5.0", | ||
"ws": | ||
"6 || 7" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
3
1
5396
7
204
52
+ Addedesm@3
+ Addedisomorphic-ws@4
+ Addednanoevents@1
+ Addedesm@3.2.25(transitive)
+ Addedisomorphic-ws@4.0.1(transitive)
+ Addednanoevents@1.0.8(transitive)
- Removedbluebird@3.5
- Removedflyd@0.2
- Removedaccepts@1.3.8(transitive)
- Removedafter@0.8.2(transitive)
- Removedarraybuffer.slice@0.0.7(transitive)
- Removedbacko2@1.0.2(transitive)
- Removedbase64-arraybuffer@0.1.4(transitive)
- Removedbase64id@2.0.0(transitive)
- Removedblob@0.0.5(transitive)
- Removedbluebird@3.5.5(transitive)
- Removedcomponent-bind@1.0.0(transitive)
- Removedcomponent-emitter@1.2.11.3.1(transitive)
- Removedcomponent-inherit@0.0.3(transitive)
- Removedcookie@0.4.2(transitive)
- Removeddebug@3.1.04.1.1(transitive)
- Removedengine.io@3.6.2(transitive)
- Removedengine.io-client@3.5.4(transitive)
- Removedengine.io-parser@2.2.1(transitive)
- Removedflyd@0.2.8(transitive)
- Removedhas-binary2@1.0.3(transitive)
- Removedhas-cors@1.1.0(transitive)
- Removedindexof@0.0.1(transitive)
- Removedisarray@2.0.1(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedms@2.0.02.1.3(transitive)
- Removednegotiator@0.6.3(transitive)
- Removedparseqs@0.0.6(transitive)
- Removedparseuri@0.0.6(transitive)
- Removedramda@0.25.0(transitive)
- Removedsocket.io@2.5.1(transitive)
- Removedsocket.io-adapter@1.1.2(transitive)
- Removedsocket.io-client@2.5.0(transitive)
- Removedsocket.io-parser@3.3.43.4.3(transitive)
- Removedto-array@0.1.4(transitive)
- Removedxmlhttprequest-ssl@1.6.3(transitive)
- Removedyeast@0.1.2(transitive)