Skip to content

StreamServer

A local HTTP server that the plugins use to stream the audio.

Every plugin that cannot hand out a static URL to FFmpeg needs an HTTP server: a source that has to be decrypted, captured or negotiated cannot be fetched by FFmpeg directly. Instead of every plugin running its own server, they register a handler on this one.

The server is started on the first registration and it is closed by DisTube#destroy.

new StreamServer(options?): StreamServer;

Create a stream server.

StreamServerOptions = {}

Optional options

StreamServer

get baseUrl(): string;

The base URL of the server, e.g. http://127.0.0.1:51234.

When the server is not started yet.

string


get prefix(): string;

The prefix of the URLs of the server.

string

close(): Promise<void>;

Close the server and release every handler.

Promise<void>

A promise that resolves when the server is closed


register(source, handler): Disposable;

Register a source.

The handler is called for every request of that source. Return null to answer a 404.

string

The identifier of the source

StreamHandler

The handler of the source

Disposable

A handle to unregister the source

const disposable = distube.streams.register("my-source", async req => ({
body: Readable.from(Buffer.from("audio")),
contentType: "audio/mpeg",
}));

url(
source,
path?,
query?
): Promise<string>;

Build the URL of a stream.

The server is started when it is not running yet.

string

The identifier of the source

string

The path after the source

Record<string, string | number | boolean>

The query parameters

Promise<string>

The URL of the stream

const url = await distube.streams.url("my-source", "abc123", { token: "secret" });