refactor(Queue): add queue parameter to createStream
This commit is contained in:
parent
ea8108979b
commit
1357e10d94
3 changed files with 20 additions and 3 deletions
15
docs/extractors/create_stream.md
Normal file
15
docs/extractors/create_stream.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
# Create Stream
|
||||
|
||||
This is a checkpoint where discord-player calls `createStream` before downloading stream.
|
||||
|
||||
# Example
|
||||
|
||||
```js
|
||||
const dl = require("my-cool-vid-downloader");
|
||||
|
||||
// after creating queue, attach this handler, that's it!
|
||||
queue.createStream = (track, source, queue) => {
|
||||
const stream = dl(track.url);
|
||||
return stream;
|
||||
};
|
||||
```
|
|
@ -11,6 +11,8 @@
|
|||
files:
|
||||
- name: Extractors API
|
||||
path: extractor.md
|
||||
- name: Creating Stream
|
||||
path: create_Stream.md
|
||||
- name: FAQ
|
||||
files:
|
||||
- name: Custom Filters
|
||||
|
|
|
@ -28,7 +28,7 @@ class Queue<T = unknown> {
|
|||
private _filtersUpdate = false;
|
||||
#lastVolume = 0;
|
||||
#destroyed = false;
|
||||
public createStream: (track: Track, source: TrackSource) => Promise<Readable> | Readable = null;
|
||||
public createStream: (track: Track, source: TrackSource, queue: Queue) => Promise<Readable> | Readable = null;
|
||||
|
||||
/**
|
||||
* Queue constructor
|
||||
|
@ -645,7 +645,7 @@ class Queue<T = unknown> {
|
|||
if (!link) return void this.play(this.tracks.shift(), { immediate: true });
|
||||
|
||||
if (customDownloader) {
|
||||
stream = (await this.createStream(track, link)) ?? null;
|
||||
stream = (await this.createStream(track, link, this)) ?? null;
|
||||
if (stream)
|
||||
stream = ytdl
|
||||
.arbitraryStream(stream, {
|
||||
|
@ -670,7 +670,7 @@ class Queue<T = unknown> {
|
|||
});
|
||||
}
|
||||
} else {
|
||||
const tryArb = (customDownloader && (await this.createStream(track, track.raw.source || track.raw.engine))) || null;
|
||||
const tryArb = (customDownloader && (await this.createStream(track, track.raw.source || track.raw.engine, this))) || null;
|
||||
const arbitrarySource = tryArb
|
||||
? tryArb
|
||||
: track.raw.source === "soundcloud"
|
||||
|
|
Loading…
Reference in a new issue