# protomux-wakeup

> Wakeup protocol over protomux

Latest version **2.9.2** (published 2026-11-18) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install protomux-wakeup
pnpm add protomux-wakeup
yarn add protomux-wakeup
bun add protomux-wakeup
```

## Health

**Score 60/100 (C)** — status: active.

Positive: no vulnerabilities; has provenance; recently updated; high maintenance score.

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

## Facts

| | |
|---|---|
| Version | 2.9.2 |
| Published | 2026-11-18 |
| First published | 2025-02-17 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 34.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 1 |
| Author | Holepunch Inc. |
| Maintainers | mafintosh |

## Links

- npm: https://www.npmjs.com/package/protomux-wakeup
- Repository: https://github.com/holepunchto/protomux-wakeup
- Issues: https://github.com/holepunchto/protomux-wakeup/issues
- npm.io page: https://npm.io/package/protomux-wakeup

## Dependencies (4)

- [b4a](https://npm.io/package/b4a.md) ^1.6.7
- [protomux](https://npm.io/package/protomux.md) ^3.10.1
- [hyperschema](https://npm.io/package/hyperschema.md) ^1.10.4
- [hypercore-crypto](https://npm.io/package/hypercore-crypto.md) ^3.5.0

## Recent versions

- 2.9.2 (latest) — 2026-11-18
- 2.9.1 — 2026-11-12
- 2.9.0 — 2025-10-31
- 2.8.0 — 2025-10-30
- 2.7.3 — 2025-10-30
- 2.7.2 — 2025-10-30
- 2.7.1 — 2025-10-29
- 2.7.0 — 2025-10-28
- 2.6.1 — 2025-08-26
- 2.6.0 — 2025-08-26
- 2.5.0 — 2025-07-01
- 2.4.3 — 2025-05-12
- 2.4.2 — 2025-04-30
- 2.4.1 — 2025-04-24
- 2.4.0 — 2025-04-23
- … 14 more at https://npm.io/package/protomux-wakeup/versions

## README

# protomux-wakeup

Wakeup protocol over protomux

```
npm install protomux-wakeup
```

## Usage

```js
const Wakeup = require('protomux-wakeup')

const w = new Wakeup()

w.addStream(stream)

const s = w.session(capability, {
  onpeeradd (peer) {
    // peer added
  },
  onpeerremove (peer) {
    // peer removed
  },
  onlookup (req, peer) {
    // received a lookup request
  },
  onannounce (wakeup, peer) {
    // received an announce message
  }
})

// the peers
s.peers

// request wakeup
s.lookup(peer, { hash })
s.announce(peer, [{ key, length }])

// or by stream
s.lookupByStream(stream, ...)
s.announceByStream(stream, ...)

// mark session as inactive, you must call this when done
s.inactive()

// cancel an inactive call
s.active()
```

## API

#### `const w = new Wakeup([onwakeup])`

Create a new wakeup swarm with a `onwakeup` callback. `onwakeup` is called with the `id` and `stream` whenever a new peer connects. `id` is the wakeup topic (see `w.session()` for more info). `stream` is the Protomux instance.

#### `w.topics`

A map of all topics being tracked.

#### `const sessions = w.getSessions(capability, handlers = {})`

Return all sessions for the topic that matches the `capability` & `handlers`.

#### `const s = w.session(capability, handlers = {})`

Create a session to track the capability. Handlers includes hook callbacks for the life cycle of peers in the session.

```
const s = w.session(core.key, {
  onpeeradd: (peer, session) => {
    // Called when a peer is added to the session
  },
  onpeerremove: (peer, session) => {
    // Called when a peer is removed from the session
  },
  onpeeractive: (peer, session) => {
    // Called when a peer becomes active
  },
  onpeerinactive: (peer, session) => {
    // Called when a peer becomes inactive
  },
  onannounce: (wakeup, peer, session) => {
    // Called when a peer announces its available wake ups
  },
  onlookup: (req, peer, session) => {
    // Called when a peer requests available wake ups
  }
})
```

`handlers` can also includes:

```
{
  active: true, // Whether the session is currently active / replicating
  discoveryKey: crypto.discoveryKey(capability) // The buffer to use as the `id` for the wake up topic. If not provide a discoveryKey hash of the capability will be used.
}
```

#### `s.peers`

Peers on the session's topic.

#### `s.topic`

The session's topic.

#### `s.isActive`

Whether the session is active.

#### `s.addStream(stream)`

Add the `stream` to the current session. If `stream` doesn't have a Protomux instance, one will added.

#### `const peer = s.getPeer(stream)`

Get the peer for the given `stream`.

#### `s.lookup(peer, req = { hash: null })`

Send a lookup request to a `peer`. `req` can be of the form `{ hash }`.

Usually used to prompt the peer for any available wake ups.

#### `s.broadcastLookup(req)`

Call `s.lookup()` on all peers.

#### `s.lookupByStream(stream, req)`

A shortcut for calling `s.lookup()` on the peer for a given `stream`.

#### `s.announce(peer, wakeup)`

Announce to the peer an array of wake up messages. Wake up messages have the form `{ key: Buffer, length: Number }`. The `key` buffer is 32 bytes long.

#### `s.announceByStream(stream, wakeup)`

A shortcut for calling `s.announce()` on the peer for a given `stream`.

#### `s.active()`

Set the session as active. Sessions are active by default.

#### `s.inactive()`

Set the session as inactive. This must be called when the session is done.

## License

Apache-2.0

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