# broadcast-stream

> a more obvious interface for local udp broadcast

Latest version **0.2.2** (published 2017-12-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install broadcast-stream
pnpm add broadcast-stream
yarn add broadcast-stream
bun add broadcast-stream
```

Provides the command `broadcast-stream`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2017-12-29 |
| First published | 2014-05-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 34 |
| Author | Dominic Tarr |
| Maintainers | dominictarr |

## Links

- npm: https://www.npmjs.com/package/broadcast-stream
- Repository: https://github.com/dominictarr/broadcast-stream
- Issues: https://github.com/dominictarr/broadcast-stream/issues
- npm.io page: https://npm.io/package/broadcast-stream

## Recent versions

- 0.2.2 (latest) — 2017-12-29
- 0.2.1 — 2017-09-26
- 0.2.0 — 2017-09-26
- 0.1.2 — 2017-04-03
- 0.1.1 — 2015-08-01
- 0.1.0 — 2015-08-01
- 0.0.0 — 2014-05-19

## README

# dgram-broadcast

A more obvious dgram broadcast.

`dgram-broadcast` has the correct defaults to just work for broadcast on your
local area network.

## Example

Broadcast on port `8999` on your local area network.

```js
const createStream = require('dgram-broadcast')

const stream = createStream(8999)

stream.on('data', (msg) => {
  console.log(msg.toString())
  console.log(msg.address, msg.port, msg.echo)
})

setInterval(() => {
  stream.write(Buffer.from(new Date().toString(), 'utf8'))
}, 1000)
```

## API

### `stream = createStream(port, loopback=true, dest=['255.255.255.255'])`

Stream on the port `port`. `If `loopback` is false, do not output your own
messages. Returns a Node.js stream. `dest` is an array of all the destination
addresses on which to broadcast, by default it has only `255.255.255.255` as the
destination.

### `stream.on('data', (msg) => { ... })`

`msg` is the message as a buffer, it also has `msg.address` and `msg.port` set
to the address and port that originated the message. If `msg` is a message that
this stream sent, it will also have `msg.loopback = true`.

### Back-pressure

UDP does not have back-pressure, but the stream API in this module does. If the
stream is paused, it will just drop messages. If when the stream is resumed, it
will emit the latest message.

## License

MIT

---
_Source: https://npm.io/package/broadcast-stream · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
