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

spacebro-client

Package Overview
Dependencies
Maintainers
5
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spacebro-client - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

dist/config.js

246

dist/index.js

@@ -11,2 +11,6 @@ 'use strict';

var _assign = require('babel-runtime/core-js/object/assign');
var _assign2 = _interopRequireDefault(_assign);
var _typeof2 = require('babel-runtime/helpers/typeof');

@@ -36,15 +40,12 @@

var _config = require('./config');
var _config2 = _interopRequireDefault(_config);
var _log = require('./log');
var _log2 = _interopRequireDefault(_log);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// Default config
var config = {
zeroconfName: 'spacebro',
channelName: null,
clientName: null,
packers: [],
unpackers: [],
sendBack: true,
verbose: true
};
// Variables

@@ -62,9 +63,20 @@ var connected = false;

return connect(false, false, address);
} else if ((typeof port === 'undefined' ? 'undefined' : (0, _typeof3.default)(port)) === 'object') {
return connect(address, false, port);
}
config = _lodash2.default.merge(config, options);
log('Connect with the config:', config);
(0, _assign2.default)(_config2.default, options);
(0, _log2.default)('Connect with the config:', _config2.default);
if (address && port) {
socketioInit(null, address, port);
} else if (address) {
_mdns2.default.connectToService(_config2.default.zeroconfName, function (err, addressReceived, port) {
if (address === addressReceived) {
socketioInit(err, address, port);
} else {
(0, _log2.default)('Not connecting, the address does not match the one defined ' + address);
}
});
} else {
_mdns2.default.connectToService(config.zeroconfName, function (err, address, port) {
_mdns2.default.connectToService(_config2.default.zeroconfName, function (err, address, port) {
socketioInit(err, address, port);

@@ -78,3 +90,3 @@ });

try {
for (var _iterator = (0, _getIterator3.default)(config.packers), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
for (var _iterator = (0, _getIterator3.default)(_config2.default.packers), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var packer = _step.value;

@@ -104,3 +116,3 @@

try {
for (var _iterator2 = (0, _getIterator3.default)(config.unpackers), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
for (var _iterator2 = (0, _getIterator3.default)(_config2.default.unpackers), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var unpacker = _step2.value;

@@ -127,3 +139,3 @@

function socketioInit(err, address, port) {
if (err) log(err.stack);
if (err) (0, _log2.default)(err.stack);
var url = 'http://' + address + ':' + port;

@@ -133,15 +145,53 @@ var socket = (0, _socket2.default)(url);

socket.on('connect', function () {
log('Socket', url, 'connected');
(0, _log2.default)('Socket', url, 'connected');
socket.emit('register', {
clientName: config.clientName,
channelName: config.channelName
clientName: _config2.default.clientName,
channelName: _config2.default.channelName
});
socket.broName = address;
sockets.push(socket);
connected = true;
if (events['connect']) {
events['connect'].dispatch({
server: {
address: address,
port: port
}
});
}
}).on('error', function (err) {
log('Socket', url, 'error:', err);
(0, _log2.default)('Socket', url, 'error:', err);
if (events['error']) {
events['error'].dispatch({
server: {
address: address,
port: port
},
err: err
});
}
}).on('disconnect', function () {
log('Socket', url, 'down');
(0, _log2.default)('Socket', url, 'down');
sockets.splice(sockets.indexOf(socket), 1);
connected = false;
if (events['disconnect']) {
events['disconnect'].dispatch({
server: {
address: address,
port: port
}
});
}
}).on('reconnect', function () {
(0, _log2.default)('Socket', url, 'reconnected');
sockets.push(socket);
connected = true;
if (events['reconnect']) {
events['reconnect'].dispatch({
server: {
address: address,
port: port
}
});
}
}).on('*', function (_ref) {

@@ -156,32 +206,38 @@ var data = _ref.data;

log('Socket', url, 'received', eventName, 'with data:', args);
if (config.sendBack && args._from === config.clientName) return;
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
(0, _log2.default)('Socket', url, 'received', eventName, 'with data:', args);
if (!_config2.default.sendBack && args._from === _config2.default.clientName) {
(0, _log2.default)('Received my own event, not dispatching');
return;
} else {
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
try {
for (var _iterator3 = (0, _getIterator3.default)(filterHooks(eventName, unpackers)), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var unpack = _step3.value;
try {
for (var _iterator3 = (0, _getIterator3.default)(filterHooks(eventName, unpackers)), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var unpack = _step3.value;
var unpacked = unpack({ eventName: eventName, data: args });
if (unpacked === false) return;
data = unpacked || data;
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
var unpacked = unpack({ eventName: eventName, data: args });
if (unpacked === false) return;
data = unpacked || data;
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
}
if (_lodash2.default.has(events, eventName)) {
events[eventName].dispatch(args);
}
}
if (_lodash2.default.has(events, eventName)) events[eventName].dispatch(args);
});

@@ -199,2 +255,6 @@ }

function emit(eventName, data) {
if ((typeof data === 'undefined' ? 'undefined' : (0, _typeof3.default)(data)) !== 'object') {
data = { data: data };
data.altered = true;
}
sendTo(eventName, null, data);

@@ -207,50 +267,54 @@ }

if (!connected) return log('You\'re not connected.');
data._to = to;
data._from = config.clientName;
var _iteratorNormalCompletion4 = true;
var _didIteratorError4 = false;
var _iteratorError4 = undefined;
if (!connected) {
return (0, _log2.default)("You're not connected.");
} else {
data._to = to;
data._from = _config2.default.clientName;
var _iteratorNormalCompletion4 = true;
var _didIteratorError4 = false;
var _iteratorError4 = undefined;
try {
for (var _iterator4 = (0, _getIterator3.default)(filterHooks(eventName, packers)), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
var pack = _step4.value;
try {
for (var _iterator4 = (0, _getIterator3.default)(filterHooks(eventName, packers)), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
var pack = _step4.value;
data = pack({ eventName: eventName, data: data }) || data;
}
} catch (err) {
_didIteratorError4 = true;
_iteratorError4 = err;
} finally {
try {
if (!_iteratorNormalCompletion4 && _iterator4.return) {
_iterator4.return();
data = pack({ eventName: eventName, data: data }) || data;
}
} catch (err) {
_didIteratorError4 = true;
_iteratorError4 = err;
} finally {
if (_didIteratorError4) {
throw _iteratorError4;
try {
if (!_iteratorNormalCompletion4 && _iterator4.return) {
_iterator4.return();
}
} finally {
if (_didIteratorError4) {
throw _iteratorError4;
}
}
}
}
var _iteratorNormalCompletion5 = true;
var _didIteratorError5 = false;
var _iteratorError5 = undefined;
var _iteratorNormalCompletion5 = true;
var _didIteratorError5 = false;
var _iteratorError5 = undefined;
try {
for (var _iterator5 = (0, _getIterator3.default)(sockets), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
var socket = _step5.value;
socket.emit(eventName, data);
}
} catch (err) {
_didIteratorError5 = true;
_iteratorError5 = err;
} finally {
try {
if (!_iteratorNormalCompletion5 && _iterator5.return) {
_iterator5.return();
for (var _iterator5 = (0, _getIterator3.default)(sockets), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
var socket = _step5.value;
socket.emit(eventName, data);
}
} catch (err) {
_didIteratorError5 = true;
_iteratorError5 = err;
} finally {
if (_didIteratorError5) {
throw _iteratorError5;
try {
if (!_iteratorNormalCompletion5 && _iterator5.return) {
_iterator5.return();
}
} finally {
if (_didIteratorError5) {
throw _iteratorError5;
}
}

@@ -291,18 +355,4 @@ }

// Old Stuff
registerToMaster: registerToMaster, iKnowMyMaster: iKnowMyMaster
};
registerToMaster: registerToMaster, iKnowMyMaster: iKnowMyMaster };
// = Helpers ===
function log() {
var _console;
if (!config.verbose) return;
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
(_console = console).log.apply(_console, ['SpaceBro -'].concat(args));
}
function filterHooks(eventName, hooks) {

@@ -338,2 +388,3 @@ return hooks.filter(function (hook) {

function iKnowMyMaster(address, port) {
console.warn('this are deprecated function and will be removed');
staticAddress = address;

@@ -344,3 +395,4 @@ staticPort = port;

function registerToMaster(actionList, clientName, zeroconfName) {
console.warn('this are deprecated function and will be removed');
return connect(staticAddress, staticPort, { clientName: clientName, zeroconfName: zeroconfName });
}

@@ -18,3 +18,3 @@ 'use strict';

browser.on('serviceUp', function (service) {
console.log('service up: ', service.type.name);
console.log('service up: ', service.type.name, service.host.substr(0, service.host.length - 1), service.port);
if (_.findWhere(services, {

@@ -21,0 +21,0 @@ name: service.type.name,

{
"name": "spacebro-client",
"version": "0.1.0",
"version": "0.1.1",
"description": "Allow to automagically 🌟 connect to a Spacebro server",

@@ -8,6 +8,6 @@ "main": "dist/index.js",

"test": "echo \"Warning: no test specified\" && exit 0",
"example": "node ./example/ponger.js",
"example-no-mdns": "node ./example/pinger.js",
"transform-example": "node ./node_modules/babel-cli/bin/babel ./example/src --out-dir ./example",
"build": "babel src -d build",
"example-pong": "node ./example/ponger.js",
"example-ping": "node ./example/pinger.js",
"build-example": "./node_modules/.bin/babel ./example/src --out-dir ./example; echo \"now, run: \n npm run example-ping \n and \n npm run example-pong\n\"",
"build": "./node_modules/.bin/babel src -d build",
"start": "gulp"

@@ -14,0 +14,0 @@ },

@@ -23,4 +23,4 @@ # Spacebro client

spacebroClient.connect('localhost', 8888, {
computer: 'foo',
channel: 'bar'
clientName: 'foo',
channelName: 'bar'
})

@@ -72,6 +72,8 @@

We will name our version by the name of the stars that you can find here: https://en.wikipedia.org/wiki/List_of_brightest_stars
We will name our version by the name of the stars that you can find here: https://en.wikipedia.org/wiki/List_of_stars_in_Andromeda
Currently latest correspond to Sirrah which belongs to the Andromeda galaxy.
You can modify the source in `src/index.js`. Run `npm run build` to transpile and test.
Enjoy !
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