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.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new StreamServer(options?): StreamServer;Create a stream server.
Parameters
Section titled “Parameters”options?
Section titled “options?”StreamServerOptions = {}
Optional options
Returns
Section titled “Returns”StreamServer
Accessors
Section titled “Accessors”baseUrl
Section titled “baseUrl”Get Signature
Section titled “Get Signature”get baseUrl(): string;The base URL of the server, e.g. http://127.0.0.1:51234.
Throws
Section titled “Throws”When the server is not started yet.
Returns
Section titled “Returns”string
prefix
Section titled “prefix”Get Signature
Section titled “Get Signature”get prefix(): string;The prefix of the URLs of the server.
Returns
Section titled “Returns”string
Methods
Section titled “Methods”close()
Section titled “close()”close(): Promise<void>;Close the server and release every handler.
Returns
Section titled “Returns”Promise<void>
A promise that resolves when the server is closed
register()
Section titled “register()”register(source, handler): Disposable;Register a source.
The handler is called for every request of that source. Return null to
answer a 404.
Parameters
Section titled “Parameters”source
Section titled “source”string
The identifier of the source
handler
Section titled “handler”The handler of the source
Returns
Section titled “Returns”A handle to unregister the source
Example
Section titled “Example”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.
Parameters
Section titled “Parameters”source
Section titled “source”string
The identifier of the source
string
The path after the source
query?
Section titled “query?”Record<string, string | number | boolean>
The query parameters
Returns
Section titled “Returns”Promise<string>
The URL of the stream
Example
Section titled “Example”const url = await distube.streams.url("my-source", "abc123", { token: "secret" });