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

commander-udp-pos

v1.0.0

Published

Easy Commander POS with UDP

Readme

commander-udp-pos

Easy Commander POS with UDP

Install

npm install commander-udp-pos
npx cap sync

Quick intro

This plugin was developed for Android App with CapacitorJS. The plugin's main feature is to create a UDP connection to send data 1:1 from device to device on a local network, useful in cases where one device needs to receive information from another device within a local network.

📋️ Requirements

  • capacitor/android 7.x.x
  • capacitor/core 7.x.x

💻️ Quick example

The best way to add the plugin to CapacitorJS app (ex: Angular) is creating a service, the following example is a suggestion of application and logic.

import { Injectable, NgZone } from '@angular/core';
import { PluginListenerHandle } from '@capacitor/core';
import { CommanderUdpPos as CUP, listenToMessages } from 'commander-udp-pos';

@Injectable({
  providedIn: 'root'
})
export class UdpServerService {
  private udpPort: number = 41234;
  listening!: PluginListenerHandle;

  constructor(private zone: NgZone) { }

  async initializeUdp(): Promise<void> {
    try {
      await CUP.listen({ port: this.udpPort });
      console.log(`Server UDP port listening: ${this.udpPort}`);

        // Listening local network messages from other device
      this.listening = listenToMessages((data) => {
        this.zone.run(async ()=>{
          const msg = await this.decompressText(data.message);
          const order = JSON.parse(msg);
          order.ip = data.senderAddress.replaceAll('/','');
          console.log(order);
          /* 
          * Here you can add logic, ex: new shared service for sending 
          * a menssage to other app section.
          */
        });
      });

    } catch (error) {
      console.error('Error starting UDP server:', error);
    }
  }

  private async sendMessage(message: string, address: string, port: number): Promise<void> {
    try {
      await CUP.sendMessage({
        message: message,
        address: address,
        port: port,
      });
    } catch (error) {
      console.error('Error sending UDP message:', error);
    }
  }

  // Adjust payload parameters or interface according to your application
  async sendOrder(payload: {ip: string; order: number; msg: string;}): Promise<void> {
      const message = await this.compressText(JSON.stringify({order: payload.order, msg: payload.msg}));
      const targetAddress = payload.ip;
      const targetPort = 41234;
      await this.sendMessage(message, targetAddress, targetPort);
  }

  async closeServer(): Promise<void> {
    try {
      this.listening.remove();
      await CUP.closeServer();
      console.log('Server UDP is closed: OK.');
    } catch (error) {
      console.error('Error closing UDP server:', error);
    }
  }

  private async compressText(text: string): Promise<string> {
    // Your method for compress text

    return text_compressed;
  }

  private async decompressText(compressedText: string): Promise<string> {
    // Your method for decompress text

    return text_uncompressed;
  }

}

The next step is to use the service in any component, that's all.

//...
import { UdpServerService } from '../services/udpServer.service';

// Example of interface
export interface Order {
  ip: string; 
  order: number; 
  msg: string;
}

//...
export class CommanderComponent implements OnInit, AfterViewInit, OnDestroy {
constructor(private cupService: UdpServerService, private sharedData: SharedDataService){}

  async ngAfterViewInit() {
    await this.cupService.initializeUdp();
  }

  async ngOnDestroy() {
    await this.cupService.closeServer();
  }

  ngOnInit(): void {
    /*
    * Here it could be have the shared service suscribed that process the upd message received in 
    * listener <listenToMessages> for logic into the angular-capacitor app.
    */ 
  }

  sendMessage(){
    this.cupService.sendOrder(this.payload);
  }
}

🗒️ Notes

The plugin can be used for various issues, such as activating devices within the same network (IoT) or exchanging metadata, and it is very important to use a compression or encryption method for the message to avoid sending and receiving problems.

The maximum DatagramPacket buffer is 8 KB (8192 bytes), consider this compressing large messages or sending them partially.

API

sendMessage(...)

sendMessage(options: { message: string; port: number; address: string; }) => Promise<void>

| Param | Type | | ------------- | ---------------------------------------------------------------- | | options | { message: string; port: number; address: string; } |


listen(...)

listen(options: { port: number; }) => Promise<void>

| Param | Type | | ------------- | ------------------------------ | | options | { port: number; } |


closeServer()

closeServer() => Promise<void>

📌 Showcase Example

A real example of an application using this plugin:

🔗 See the app

Contact, Reports or Bugs

Thanks for checking out the project. You can take a peek about my work by visiting my website.

🌍 Website: Visit

NivarDev