Giter Site home page Giter Site logo

ardean / spread-the-word Goto Github PK

View Code? Open in Web Editor NEW
10.0 2.0 4.0 1.22 MB

:loudspeaker: A Bonjour / Zeroconf implementation in TypeScript

License: MIT License

TypeScript 100.00%
bonjour bonjour-discovery multicast-dns mdns typescript javascript spread zeroconf

spread-the-word's Introduction

spread-the-word

A Bonjour / Zeroconf implementation in TypeScript.

Github Version NPM Version NPM Downloads License CircleCI

Spread services across your local network and discover other services

Installation

$ npm i spread-the-word

Usage

import stw from "spread-the-word";

stw.on("up", (remoteService, response, referrer) => {
  console.log(`${remoteService.name} (type: ${remoteService.type}, port: ${remoteService.port}) is up (from ${referrer.address})`);
  if (remoteService.txt) {
    console.log("TXT found:", remoteService.txt);
  }
}).on("down", (remoteService, response, referrer) => {
  console.log(`${remoteService.name} (type: ${remoteService.type}, port: ${remoteService.port}) is down (from ${referrer.address})`);
});

stw.listen({ type: "jsremote" });

stw.spread({
  type: "jsremote",
  name: "awesome remote receiver",
  port: 4444,
  txt: {
    message: "Custom Data"
  }
});

Features

  • easy service detection & advertisement on your local network
  • TXT record support
  • subtypes support
  • auto probing on spread
  • no extra native dependencies
  • typescript types included

Documentation

You can find the latest version of documentation hosted here.

Debug

$ DEBUG=SpreadTheWord:* npm start

License

MIT

spread-the-word's People

Contributors

ardean avatar dependabot[bot] avatar dizzyluo avatar omgimalexis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

spread-the-word's Issues

Describe differences with nbonjour package?

It seems like the biggest differences I see are

  • under active development
  • generated documentation
  • typescript?

Maybe a changelog or more technical features would help those who are browsing npm to choose spread-the-word over something like nbonjour.
This mostly comes down to nbonjour not having a feature list and spread-the-word having one, but I'm not sure which features are in spread-the-word but not in nbonjour.

I just found this because I like searching by new :)

Just a thought, I hope this package becomes more popular.

Add service subtype to event emitters?

It would be nice if the up and down events passed back the listener.typeName in the response

const testStw = async () => {
  const stw = require('spread-the-word').default
  stw.init()

  const listener = await stw.listen({ type: 'http', protocol: 'tcp', subtypes: ['livingroom'] })

  // works but seems hacky
  listener.on('up', function({name}) {
    console.log(name, this.typeName)
  })

  // would love for this to work
  listener.on('up', ({name, typeName}) => {
    console.log(name, typeName)
  })

  stw.spread({
    name: "coolbeans",
    port: 4444,
    type: 'http',
    subtypes: ['livingroom'],
    protocol: 'tcp'
  })
}

testStw()

Unhandled promise rejection

Hi there,

Getting an error running the demo app,
(node:6052) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: send EMSGSIZE

Any idea what's going? Using node 8.9.0

Thanks!
(Awesome lib btw, most of the others don't work well)

Unable to find avahi daemon with default options

I have a raspberry pi on my network that I can ping with it's local domain and can discover with avahi-browse -all, but spread-the-word doesn't seem to work.

I assume I'm doing something wrong:

 stw
  .on("up", (remoteService, res, referrer) => {
    console.log(`${remoteService.name} is up! (from ${referrer.address})`);
  })
  .on("down", (remoteService, res, referrer) => {
    console.log(`${remoteService.name} is down! (from ${referrer.address})`);
  });

  stw.listen();

I was able to find another device on the network, so something is working. Any ideas / tips for debugging this?

Docs and types should be built before publish

I'm about to open a PR to add some changes and I noticed docs and dist are both added to the repo. I'd suggest removing them and using github actions to build the docs before pushing and the same for npm publishing.

How to pass in custom TXT?

When I start the broadcast, I can see a default TXT record 0=0, is there a way to pass in custom records please?

Server.ts imports itself

When type checking my project I'm getting the following error:

node_modules/spread-the-word/dist/Server.d.ts:7:10 - error TS2440: Import declaration conflicts with local declaration of 'ServerOptions'.

and it does seem like Server.d.ts is importing itself

Typescript error "Cannot find name 'default'"

When trying to build my project with tsc I get couple of errors, do you know where that could come from please? Using tsc v2.9.2 and stw 0.5.0

node_modules/spread-the-word/dist/Records/TXT.d.ts:14:9 - error TS2304: Cannot find name 'default'.

14     }): default;
           ~~~~~~~


node_modules/spread-the-word/dist/Records/TXT.d.ts:17:9 - error TS2304: Cannot find name 'default'.

17     }): default;
           ~~~~~~~


node_modules/spread-the-word/dist/Response.d.ts:10:65 - error TS2304: Cannot find name 'default'.

10     static parse(options: ResponseOptions, parseOptions?: any): default;
                                                                   ~~~~~~~


node_modules/spread-the-word/dist/Response.d.ts:11:73 - error TS2304: Cannot find name 'default'.

11     static serialize(options: ResponseOptions, serializeOptions?: any): default;

Cannot listen to simple service?

In two different node processes, i run:

const stw = require('spread-the-word').default
stw.on('up', console.dir)
stw.listen({type: 'osc', protocol: 'udp', subtypes: ['livingroom']})
  .then(listener => {
    console.dir(listener)
    console.log('listening')
  })
const stw = require('spread-the-word').default
stw.spread({type: 'osc', protocol: 'udp', subtypes: ['livingroom'], name: 'lol', hostname: 'talon.local', port: 12345})
  .then(spreader => {
    console.dir(spreader)
    console.log('spread')
  })

I dont get any output from the listener.

If I run this in the same process, then it works. What am I missing?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.