Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

booth

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

booth - npm Package Compare versions

Comparing version 0.11.0 to 0.12.0

Events.js

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)
}

@@ -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;
{
"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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc