Project files

This commit is contained in:
2023-11-09 18:47:11 +01:00
parent 695abe054b
commit c415135aae
8554 changed files with 858111 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
name: build
on:
release:
types: [created]
jobs:
build-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
registry-url: https://registry.npmjs.org/
- run: yarn install
- run: yarn build
- run: git config --global user.name "ON LX Team"
- run: git config --global user.email "team@onlx.ltd"
- run: npm version ${{ github.event.release.tag_name }} --allow-same-version
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

View File

@@ -0,0 +1,10 @@
language: node_js
os:
- linux
- osx
node_js:
- '6'
- '5'
- '4'
- '0.12'
- '0.10'

View File

@@ -0,0 +1,23 @@
The MIT License (MIT)
Copyright (https://github.com/onlxltd/bonjour-service) (c) 2021 ON LX Limited
Portions Copyright (Bonjour - https://github.com/watson/bonjour) (c) 2015-2016 Thomas Watson Steen
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.

View File

@@ -0,0 +1,192 @@
# bonjour-service
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/onlxltd/bonjour-service/build?style=flat-square) ![npm bundle size](https://img.shields.io/bundlephobia/min/bonjour-service?style=flat-square) ![GitHub Release Date](https://img.shields.io/github/release-date/onlxltd/bonjour-service?style=flat-square) ![GitHub](https://img.shields.io/github/license/onlxltd/bonjour-service?style=flat-square) [![DeepScan grade](https://deepscan.io/api/teams/13435/projects/16430/branches/352351/badge/grade.svg?style=flat-square)](https://deepscan.io/dashboard#view=project&tid=13435&pid=16430&bid=352351)
A Bonjour/Zeroconf protocol implementation in TypeScript. Publish
services on the local network or discover existing services using
multicast DNS.
This is a rewrite of the project Bonjour (https://github.com/watson/bonjour) into modern TypeScript.
## Installation
Add to your project dependencies using Yarn or NPM.
#### Install with Yarn
```
yarn add bonjour-service
```
#### Install with NPM
```
npm install bonjour-service
```
## Usage
```js
import Bonjour from 'bonjour-service'
const instance = new Bonjour()
// advertise an HTTP server on port 3000
instance.publish({ name: 'My Web Server', type: 'http', port: 3000 })
// browse for all http services
instance.find({ type: 'http' }, function (service) {
console.log('Found an HTTP server:', service)
})
```
## API
### Initializing
```js
var instance = new Bonjour({ options })
```
The `options` are optional and will be used when initializing the
underlying multicast-dns server. For details see [the multicast-dns
documentation](https://github.com/mafintosh/multicast-dns#mdns--multicastdnsoptions).
### Publishing
#### `var service = bonjour.publish(options)`
Publishes a new service.
Options are:
- `name` (string)
- `host` (string, optional) - defaults to local hostname
- `port` (number)
- `type` (string)
- `subtypes` (array of strings, optional)
- `protocol` (string, optional) - `udp` or `tcp` (default)
- `txt` (object, optional) - a key/value object to broadcast as the TXT
record
IANA maintains a [list of official service types and port
numbers](http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml).
#### `bonjour.unpublishAll([callback])`
Unpublish all services. The optional `callback` will be called when the
services have been unpublished.
#### `bonjour.destroy()`
Destroy the mdns instance. Closes the udp socket.
### Browser
#### `var browser = bonjour.find(options[, onup])`
Listen for services advertised on the network. An optional callback can
be provided as the 2nd argument and will be added as an event listener
for the `up` event.
Options (all optional):
- `type` (string)
- `subtypes` (array of strings)
- `protocol` (string) - defaults to `tcp`
- `txt` (object) - passed into [dns-txt
module](https://github.com/watson/dns-txt) contructor. Set to `{
binary: true }` if you want to keep the TXT records in binary
#### `var browser = bonjour.findOne(options[, callback])`
Listen for and call the `callback` with the first instance of a service
matching the `options`. If no `callback` is given, it's expected that
you listen for the `up` event. The returned `browser` will automatically
stop it self after the first matching service.
Options are the same as given in the `browser.find` function.
#### `Event: up`
Emitted every time a new service is found that matches the browser.
#### `Event: down`
Emitted every time an existing service emmits a goodbye message.
#### `browser.services()`
An array of services known by the browser to be online.
#### `browser.start()`
Start looking for matching services.
#### `browser.stop()`
Stop looking for matching services.
#### `browser.update()`
Broadcast the query again.
### Service
#### `Event: up`
Emitted when the service is up.
#### `Event: error`
Emitted if an error occurrs while publishing the service.
#### `service.stop([callback])`
Unpublish the service. The optional `callback` will be called when the
service have been unpublished.
#### `service.start()`
Publish the service.
#### `service.name`
The name of the service, e.g. `Apple TV`.
#### `service.type`
The type of the service, e.g. `http`.
#### `service.subtypes`
An array of subtypes. Note that this property might be `null`.
#### `service.protocol`
The protocol used by the service, e.g. `tcp`.
#### `service.host`
The hostname or ip address where the service resides.
#### `service.port`
The port on which the service listens, e.g. `5000`.
#### `service.fqdn`
The fully qualified domain name of the service. E.g. if given the name
`Foo Bar`, the type `http` and the protocol `tcp`, the `service.fqdn`
property will be `Foo Bar._http._tcp.local`.
#### `service.txt`
The TXT record advertised by the service (a key/value object). Note that
this property might be `null`.
#### `service.published`
A boolean indicating if the service is currently published.
## License
MIT

View File

@@ -0,0 +1,15 @@
const { Bonjour } = require('../dist')
const service = new Bonjour()
service.publish({ name: 'My Web Server', type: 'http', port: 3000 })
let browser = service.find({ type: 'http' })
browser.on('up', (service) => {
console.log('up', service)
})
browser.on('down', (service) => {
console.log('down', service)
})

View File

@@ -0,0 +1,52 @@
{
"name": "bonjour-service",
"version": "1.0.11",
"description": "A Bonjour/Zeroconf implementation in TypeScript",
"main": "./dist/index.js",
"dependencies": {
"array-flatten": "^2.1.2",
"dns-equal": "^1.0.0",
"fast-deep-equal": "^3.1.3",
"multicast-dns": "^7.2.4"
},
"devDependencies": {
"@types/node": "^14.14.35",
"@typescript-eslint/eslint-plugin": "^4.19.0",
"@typescript-eslint/parser": "^4.19.0",
"after-all": "^2.0.2",
"eslint": "^7.22.0",
"standard": "^11.0.0",
"tape": "^5.2.2",
"ts-node-dev": "^1.1.8",
"typescript": "^4.4.4"
},
"scripts": {
"test": "standard --fix && tape test/*.js",
"build": "tsc --removeComments true",
"dev": "ts-node-dev --respawn --transpile-only ./src/index.ts",
"example:simple": "node examples/simple"
},
"repository": {
"type": "git",
"url": "https://github.com/onlxltd/bonjour-service.git"
},
"keywords": [
"bonjour",
"zeroconf",
"zero",
"configuration",
"mdns",
"dns",
"service",
"discovery",
"multicast",
"broadcast",
"dns-sd"
],
"author": "ON LX Lited <team@onlx.ltd> (https://labs.onlx.ltd)",
"license": "MIT",
"bugs": {
"url": "https://github.com/onlxltd/bonjour-service/issues"
},
"homepage": "https://github.com/onlxltd/bonjour-service"
}

View File

@@ -0,0 +1,70 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./dist", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"baseUrl": ".", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
"allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
/* Advanced Options */
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
}