refactor(Queue): add queue parameter to createStream

This commit is contained in:
DevAndromeda 2021-09-06 22:30:52 +05:45
parent ea8108979b
commit 1357e10d94
No known key found for this signature in database
GPG key ID: FA40E3EC5CB6DCD6
3 changed files with 20 additions and 3 deletions

View 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;
};
```

View file

@ -11,6 +11,8 @@
files: files:
- name: Extractors API - name: Extractors API
path: extractor.md path: extractor.md
- name: Creating Stream
path: create_Stream.md
- name: FAQ - name: FAQ
files: files:
- name: Custom Filters - name: Custom Filters

View file

@ -28,7 +28,7 @@ class Queue<T = unknown> {
private _filtersUpdate = false; private _filtersUpdate = false;
#lastVolume = 0; #lastVolume = 0;
#destroyed = false; #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 * Queue constructor
@ -645,7 +645,7 @@ class Queue<T = unknown> {
if (!link) return void this.play(this.tracks.shift(), { immediate: true }); if (!link) return void this.play(this.tracks.shift(), { immediate: true });
if (customDownloader) { if (customDownloader) {
stream = (await this.createStream(track, link)) ?? null; stream = (await this.createStream(track, link, this)) ?? null;
if (stream) if (stream)
stream = ytdl stream = ytdl
.arbitraryStream(stream, { .arbitraryStream(stream, {
@ -670,7 +670,7 @@ class Queue<T = unknown> {
}); });
} }
} else { } 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 const arbitrarySource = tryArb
? tryArb ? tryArb
: track.raw.source === "soundcloud" : track.raw.source === "soundcloud"