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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@webnativellc/cordova-plugin-ionic-discover

v1.0.5

Published

Cordova Ionic Discover plugin

Readme

cordova-plugin-discover

Installation

npm install @webnativellc/cordova-plugin-discover

Create a file called discover.ts:

export interface Service {
  path: string
  hostname: string
  id: string
  address: string
  port: number
  name: string
  secure: boolean
}

export const IonicDiscover = (window as any).IonicDiscover;

Start checking for broadcasts:

import { IonicDiscover, Service } from '../discovery';

...

IonicDiscover.start();
setInterval(async () => { 
    const data = await IonicDiscover.getServices();
    console.log(data?.services);
    }, 2000);

The above code will console log a Service[]

Server Side

You can broadcast via UDP service information for the plugin with:

        const p: Publisher = new Publisher('devapp', 'my-app-name', 8100);
        p.start();

Create a file called discover.ts and paste:

import * as os from 'os';
import * as dgram from 'dgram';
import * as events from 'events';

import { Netmask } from 'netmask';

const PREFIX = 'ION_DP';
const PORT = 41234;

export interface Interface {
  address: string;
  broadcast: string;
}

export interface IPublisher {
  emit(event: 'error', err: Error): boolean;
  on(event: 'error', listener: (err: Error) => void): this;
}

export class Publisher extends events.EventEmitter implements IPublisher {
  id: string;
  path = '/';
  running = false;
  interval = 2000;

  timer?: any;
  client?: dgram.Socket;
  interfaces?: Interface[];

  constructor(public namespace: string, public name: string, public port: number) {
    super();

    if (name.indexOf(':') >= 0) {
      console.warn('name should not contain ":"');
      name = name.replace(':', ' ');
    }

    this.id = String(Math.round(Math.random() * 1000000));
  }

  start(): Promise<void> {
    return new Promise<void>((resolve, reject) => {
      if (this.running) {
        return resolve();
      }

      this.running = true;

      if (!this.interfaces) {
        this.interfaces = this.getInterfaces();
      }

      const client = (this.client = dgram.createSocket('udp4'));

      client.on('error', (err) => {
        this.emit('error', err);
      });

      client.on('listening', () => {
        client.setBroadcast(true);
        this.timer = setInterval(this.sayHello.bind(this), this.interval);
        this.sayHello();
        resolve();
      });

      client.bind();
    });
  }

  stop() {
    if (!this.running) {
      return;
    }

    this.running = false;

    if (this.timer) {
      clearInterval(this.timer);
      this.timer = undefined;
    }

    if (this.client) {
      this.client.close();
      this.client = undefined;
    }
  }

  buildMessage(ip: string): string {
    const now = Date.now();
    const message = {
      t: now,
      id: this.id,
      nspace: this.namespace,
      name: this.name,
      host: os.hostname(),
      ip: ip,
      port: this.port,
      path: this.path,
      secure: this.secure
    };
    return PREFIX + JSON.stringify(message);
  }

  getInterfaces(): Interface[] {
    return prepareInterfaces(os.networkInterfaces());
  }

  private sayHello() {
    if (!this.interfaces) {
      throw new Error('No network interfaces set--was the service started?');
    }

    try {
      for (const iface of this.interfaces) {
        const message = new Buffer(this.buildMessage(iface.address));

        this.client!.send(message, 0, message.length, PORT, iface.broadcast, (err) => {
          if (err) {
            this.emit('error', err);
          }
        });
      }
    } catch (e) {
      this.emit('error', e);
    }
  }
}

export function prepareInterfaces(interfaces: any): Interface[] {
  const set = new Set<string>();
  return Object.keys(interfaces)
    .map((key) => interfaces[key] as any[])
    .reduce((prev, current) => prev.concat(current))
    .filter((iface) => iface.family === 'IPv4')
    .map((iface) => {
      return {
        address: iface.address,
        broadcast: computeBroadcastAddress(iface.address, iface.netmask),
      };
    })
    .filter((iface) => {
      if (!set.has(iface.broadcast)) {
        set.add(iface.broadcast);
        return true;
      }
      return false;
    });
}

export function newSilentPublisher(namespace: string, name: string, port: number): Publisher {
  name = `${name}@${port}`;
  const service = new Publisher(namespace, name, port);
  service.on('error', (error) => {
    console.log(error);
  });
  service.start().catch((error) => {
    console.log(error);
  });
  return service;
}

export function computeBroadcastAddress(address: string, netmask: string): string {
  const ip = address + '/' + netmask;
  const block = new Netmask(ip);
  return block.broadcast;
}