npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ts-udp-discovery

v1.0.0

Published

Provides zero-config discovery service using broadcast UDP.

Downloads

6

Readme

ts-udp-discovery

This is updated typescript version of udp-discovery. Module provides discovery services using UDP multicast. ts-udp-discovery implements the zero-configuration UDP multicast discovery and works only between nodes on the same subnet as typically, broadcast packets don't route.

Installation

yarn add ts-udp-discovery

Example

Application sending advertisements

import { TSUDPDiscovery } from "ts-udp-discovery";
const service = {
  port: 80,
  proto: "tcp",
  annInterval: 1000,
  addrFamily: "IPv4",
  data: {
    name: "Edmond",
    day: 2233,
    week: ["monday", "tuesday", "wednesday", "thursday", "friday"],
  },
};

const discovery = new TSUDPDiscovery({ port, timeOutIntervalTime: interval });

discovery.announce(name, serv, interval, available);

discovery.on('MessageBus', function(event, data) {
  ...
});

Application receiving advertisements


discovery.on('available', function(name, data, reason) {
  var obj = {a: 1, b: '2', c: true, d: {e: 333}};
  discovery.sendEvent('Hello', obj);
});

discover.on('unavailable', function(name, data, reason) {
  ...
});

Discovery constructor

new Discovery({options})

Invokes the constructor to create an instance of Discovery to receive discovery events. The config options object is optional, but if included, the following options are available:

  • Number port - The port to listen upon for service announcements. Default: 44201.

  • String timeOutIntervalTime - duration of time between timeout checks in ms. Default 1000.

  • String bindAddress - The address to bind to. Default: listens to all interfaces.

  • String type - Either 'udp4' or 'udp6'. Default: 'udp4'.

Discovery methods

announce(name, userData, [,interval] [,available])

Starts announcing the service at the specified interval. The parameter, serviceObject, is an object describing the service that udp-discoveryy announces.

  • String name The name of the service being announced. It must be unique, or it will collide with another.
  • Number interval The duration between announcements in milliseconds.
  • Any userData Any data that can be serialized into JSON.
  • Boolean available Optional parameter to set availability of the service. If not specified, the default is 'true', meaning available.

Any property with a default can be left out and the code supplies the default value. The name and data are required.

pause(name)

  • String name The name of the service.
  • Returns true if successful, false otherwise.

Halts announcements.

resume(name, [,interval])

  • String name name of the service.
  • Number [interval] optional interval between announcements in ms.
  • Returns true if successful, false otherwise.

Resumes the announcements at the time interval.

getData(name)

  • String name name of the service.
  • Returns Object serviceObject from announce.

Returns the service object, which can be modified. For example, if you need to alter the userData, you can. You cannot, however, alter the name (it's a constant property).

update(name, userData [,interval] [,available])

Updates the existing service.

  • String name The name of the service being announced. It must be unique, or it will collide with another.
  • Any userData Any data that can be serialized into JSON.
  • Number [interval] Optional duration between announcements in milliseconds.
  • Boolean [available] Optional parameter to set availability of the service. If not specified, the default is 'true', meaning available.

Discovery Events

'available'

Has the following parameters:

  • String name name of the service.
  • Object data user-defined object describing the service.
  • String reason why this event was sent: 'new', 'availabilityChange', 'timedOut'.

This event can happen when:

  • The first announcement for a service is received.
  • The availability changes, if the available status changes from false to true.

'unavailable'

Has the following parameters:

  • String name name of the service.
  • Object data user-defined object describing the service.
  • String reason why this event was sent: 'new', 'availabilityChange', 'timedOut'.

This event can happen when:

  • The first announcement for a service is received and the service is unavailable..
  • The availability changes, if the available status changes from true to false.
  • When 2x the announce interval time for the service elapsed without an announcement being seen. The service is considered unavailable and removed from the list of services.

License

Copyright (c) 2014 Edmond Meinfelder

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.