Socket
Socket
Sign inDemoInstall

@ionic/discover

Package Overview
Dependencies
Maintainers
13
Versions
139
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ionic/discover - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

17

dist/publisher.js

@@ -6,2 +6,4 @@ "use strict";

var Netmask = require('netmask').Netmask;
var PREFIX = 'ION_DP';
var PORT = 41234;
var Publisher = (function () {

@@ -44,3 +46,11 @@ function Publisher(name, port, interval) {

var now = Date.now();
return ['ION_DP', now, this.id, this.name, iface.address, this.port].join(':');
var message = {
t: now,
id: this.id + '',
name: this.name,
host: os.hostname(),
ip: iface.address,
port: this.port
};
return PREFIX + JSON.stringify(message);
};

@@ -50,4 +60,5 @@ Publisher.prototype.sayHello = function () {

var iface = _a[_i];
console.log(iface);
var message = new Buffer(this.getMessage(iface));
this.client.send(message, 0, message.length, 41234, iface.broadcast);
this.client.send(message, 0, message.length, PORT, iface.broadcast);
}

@@ -59,3 +70,3 @@ };

return Object.keys(interfaces)
.map(function (key) { return interfaces[key].find(function (i) { return i.internal === false && i.family === 'IPv4'; }); })
.map(function (key) { return interfaces[key].find(function (i) { return i.family === 'IPv4'; }); })
.filter(function (iface) { return !!iface; })

@@ -62,0 +73,0 @@ .map(function (iface) {

4

package.json
{
"name": "@ionic/discover",
"version": "0.0.1",
"version": "0.0.2",
"description": "Simple UDP based protocol for service discovery implemented in pure JS. Not mDNS or bonjour. ",

@@ -34,3 +34,3 @@ "main": "dist/index.js",

},
"repository": {
"repository": {
"type": "git",

@@ -37,0 +37,0 @@ "url": "git+https://github.com/ionic-team/ionic-discover.git"

# Ionic Discover
Simple UDP based protocol for service discovery implemented in pure JS. Not mDNS or bonjour.
Simple UDP based protocol for service discovery implemented in pure JS. It is not mDNS or bonjour, but it tries to accomplish the same thing.
## Spec
It uses a JSON based textual format:
```ts
const message = {
t: now,
id: this.id,
name: this.name,
host: os.hostname(),
ip: iface.address,
port: this.port
};
return 'ION_DP' + JSON.stringify(message);
```
- t: unix timestamp in second
- id: unique id for this session
- name: name of the announced service
- host: hostname of the machine announcing the service
- ip: ipv4 address
- port: tcp port of the announced service
## Why?
Complexity of mDNS and lack of good pure JS implementations. We tried different NPM packages that
implemented mDNS, ZeroConf or Bonjour but non of them worked for us:
- mdns: it worked very realiably, but required compiling C code with dependencies. It required complicated and different instructions steps for osx, windows and linux
- node-bonjour: buggy
- node-mdns: buggy
We were in a dead end road with the approach and trying to reimplement mDNS by our own was completely out of scope.
## Installation
```
npm install @ionic/discover --save
```
## Usage
```
const Publisher = require('@ionic/discover').Publisher;
const serviceName = 'Ionic thing!';
const tcpPort = 8100;
const service = new Publisher(serviceName, tcpPort);
service.start();
```
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