# @astronautlabs/rtmp

> Real Time Messaging Protocol (RTMP)

Latest version **1.2.1** (published 2026-08-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install @astronautlabs/rtmp
pnpm add @astronautlabs/rtmp
yarn add @astronautlabs/rtmp
bun add @astronautlabs/rtmp
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2026-08-06 |
| First published | 2022-02-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 609.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Astronaut Labs, LLC |
| Maintainers | rezonant |
| Keywords | rtmp, media, transport, ingress, live, stream, flex, adobe |

## Links

- npm: https://www.npmjs.com/package/@astronautlabs/rtmp
- Repository: https://github.com/astronautlabs/rtmp
- Homepage: https://github.com/astronautlabs/rtmp#readme
- Issues: https://github.com/astronautlabs/rtmp/issues
- npm.io page: https://npm.io/package/@astronautlabs/rtmp

## Dependencies (4)

- [rxjs](https://npm.io/package/rxjs.md) ^7.5.2
- [@astronautlabs/amf](https://npm.io/package/@astronautlabs/amf.md) ^0.0.6
- [@astronautlabs/flv](https://npm.io/package/@astronautlabs/flv.md) ^0.0.18
- [@astronautlabs/bitstream](https://npm.io/package/@astronautlabs/bitstream.md) ^4.1.1

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 1.2.1 (latest) — 2026-08-06
- 1.2.0 — 2026-08-06
- 1.1.1 — 2025-04-28
- 1.1.0 — 2024-01-24
- 1.0.3 — 2023-06-24
- 1.0.2 — 2022-07-30
- 1.0.1 — 2022-07-30
- 1.0.0 — 2022-07-30
- 0.0.10 — 2022-07-28
- 0.0.9 — 2022-07-25
- 0.0.8 — 2022-07-24
- 0.0.6 — 2022-07-09
- 0.0.5 — 2022-07-09
- 0.0.4 — 2022-07-09
- 0.0.3 — 2022-02-04
- … 2 more at https://npm.io/package/@astronautlabs/rtmp/versions

## README

# @/rtmp

> **[📜 Adobe RTMP (December 21, 2012)](https://rtmp.veriskope.com/docs/spec/)**  
> Adobe’s Real Time Messaging Protocol (RTMP)

> ✅ **Stable**  
> This library is a mostly-complete and working implementation of RTMP. (stable, semver 1.x.x).

> 📺 Part of the [**Astronaut Labs Broadcast Suite**](https://github.com/astronautlabs/broadcast)
>
> See also:
> - [@/amf](https://github.com/astronautlabs/amf) - Adobe's Action Message Format (AMF)
> - [@/flv](https://github.com/astronautlabs/flv) - Adobe's Flash Video format (FLV)

---

Comprehensive Typescript implementation of Adobe's Real Time Messaging Protocol (RTMP) using [Bitstream](https://github.com/astronautlabs/bitstream)

# Motivation

This library is intended to provide an approachable and comprehensive RTMP implementation for Node.js using Typescript.
It uses similar concepts to those of Adobe Flash / Flash Media Server / Flex in exposing RTMP to users. Supports AMF v0
and v3 via [@astronautlabs/amf](https://github.com/astronautlabs/amf)

# Installation

```
npm i @astronautlabs/rtmp
```

# Examples

## Client (Publishing)

```typescript
import 'reflect-metadata';
import 'source-map-support/register';

import * as RTMP from '@astronautlabs/rtmp';
import * as FLV from '@astronautlabs/flv';

async function publish() {
    let client = new RTMP.Client();

    // Connect to the server and issue the RTMP `connect` command.
    await client.connect({ host: 'localhost', app: 'live' });

    // Allocate a message stream and begin publishing under a stream key.
    let stream = await client.createStream();
    await stream.publish('my-stream-key', 'live');

    // Send stream metadata (onMetaData).
    stream.sendMetadata({ 
        width: 1280, 
        height: 720, 
        framerate: 30,
        videocodecid: FLV.VideoCodec.AVC,
        audiocodecid: FLV.AudioCodec.AAC,
    });

    // Send audio/video. Payloads are FLV tag bodies (a raw Buffer or a
    // VideoMessageData/AudioMessageData). Send codec sequence headers first.
    // You can use `@astronautlabs/flv` to construct these.
    stream.sendVideo(0, avcSequenceHeaderBody);
    stream.sendAudio(0, aacSequenceHeaderBody);
    stream.sendVideo(0, videoFrameBody);
    stream.sendAudio(23, audioFrameBody);

    // When finished:
    await stream.unpublish();
    client.disconnect();
}
```

Custom server RPC calls can be invoked with `client.call('commandName', [args])` (awaits the
`_result`/`_error` response). Subclass `RTMP.Client` and decorate methods with `@RPC()` (or override
`receiveCall`) to handle server-initiated commands. A runnable loopback example is available via
`npm run sample:client` ([src/client.example.ts](src/client.example.ts)).

## Server

```typescript
import 'reflect-metadata';
import 'source-map-support/register';

import { Socket } from 'net';
import * as RTMP from '@astronautlabs/rtmp';

class MyServer extends RTMP.Server {
    protected createSession(socket: Socket): RTMP.Session {
        return new MySession(this, socket);
    }
}

class MySession extends RTMP.Session {
    protected createStream(id: number): RTMP.ServerMediaStream {
        return new MyStream(this, id);
    }
}

class MyStream extends RTMP.ServerMediaStream {
    play(streamName: string, start: number, duration: number, reset: boolean): void {
        // Client wants to receive this stream.

        this.notifyBegin();

        this.sendVideo(Buffer.from([ ... ]));
        this.sendAudio(Buffer.from([ ... ]));
    }

    publish(streamName : string) {
        // Client is publishing this stream
    }

    receiveVideo(data : Uint8Array) {
        // Do something with the video packets
    }

    receiveAudio(data : Uint8Array) {
        // Do something with the audio packets
    }
}

let server = new MyServer();
server.listen();
```

## Custom RPC

```typescript
import 'reflect-metadata';
import 'source-map-support/register';

import { Socket } from 'net';
import * as RTMP from '.';

class MyServer extends RTMP.Server {
    protected createSession(socket: Socket): RTMP.Session {
        return new MySession(this, socket);
    }
}

class MySession extends RTMP.Session {
    protected createStream(id: number): RTMP.ServerMediaStream {
        return new MyStream(this, id);
    }
}

class MyStream extends RTMP.ServerMediaStream {

    /**
     * Mark any method with `@RPC()` to expose it as an RTMP command.
     * Here the command 'customMethod' gets mapped to this method, with
     * its parameters automatically converted from AMF0/3 to the appropriate
     * Javascript types, and the return value being sent back in a "_result" 
     * response. If an exception is thrown, an "_error" response is sent back with 
     * a summary of the error.
     */
    @RPC() customMethod(foo : string, bar : number[]) {
        return { message: 'All done!' };
    }

    play(streamName: string, start: number, duration: number, reset: boolean): void {
        console.log(`play('${streamName}', ${start}, ${duration}, ${reset})`);
        super.play(streamName, start, duration, reset);
    }
}

let server = new MyServer();
server.listen();
```

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