Code Monkey home page Code Monkey logo

lms-discovery's Introduction

lms-discovery

Logitech Media Server discovery for Node.js

Install

npm install --save lms-discovery

Usage

// ESM
import discovery from 'lms-discovery';
// CJS
const discovery = require('lms-discovery');

discovery.on('discovered', (server) => {
    console.log('Server discovered:', server);
});

discovery.on('lost', (server) => {
    // Do something with lost server
});

discovery.start();

...

discovery.stop();


// Output
Server discovered: {
    ip: '192.168.1.85',     // Server's IP address
    name: 'my-lms-server',  // Server name
    ver: '8.2.1',           // Server version
    uuid: '187fa185-d108-408b-a8bd-8f5a4bb855bd',  // Unique identifier
    jsonPort: '9000',       // Port for JSON-RPC requests
    cliPort: '9090'         // Port for CLI commands and queries   
}

Run example:

npm run example

API

start([options])

Starts the discovery service.

Params

  • options: (optional and all properties optional)
    • broadcastAddress: (string) network address used to transmit discovery requests. Default: 255.255.255.255.
    • discoveredTTL: (number) how long in milliseconds to wait for a discovered server to respond to a subsqeuent discovery request before it is presumed lost. Only applicable for servers that do not advertise cliPort. Default: 60000 (60 seconds).
    • discoverInterval: (number) how often in milliseconds to broadcast discovery requests. Default: 30000 (30 seconds).

discoveredTTL must be larger than discoverInterval.


stop()

Stops the discovery service.


getStatus()

Gets the status of the discovery service.

Returns

running or stop


getAllDiscovered()

Gets all servers discovered so far.

Returns

Array<ServerInfo>


setDebug(enabled[, callback])

Whether to enable debug messages.

Params

  • enabled: (boolean)
  • callback: (function)
    • If specified, debug messages will be passed to callback.
    • If not specified, debug messages will be printed to console.

Events

on('discovered', (server) => ...)

Emitted when a server is discovered.

Listener Params


on('lost', (server) => ...)

Emitted when a server is lost.

Listener Params


on('error', (error) => ...)

Emitted when an error has occurred.

Listener Params

  • error: (any)

Changelog

1.1.0:

  • Instead of detecting server lost through discoveredTTL timers, emit 'lost' events immediately as they occur for servers that advertise cliPort.

1.0.0:

  • Migrate to TypeScript and package as ESM / CJS hybrid module

0.1.0:

  • Initial release

License

MIT

lms-discovery's People

Contributors

patrickkfkan avatar

Watchers

 avatar

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.