distube 5.0.3 → 5.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,11 +1,5 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
4
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
5
- }) : x)(function(x) {
6
- if (typeof require !== "undefined") return require.apply(this, arguments);
7
- throw Error('Dynamic require of "' + x + '" is not supported');
8
- });
9
3
 
10
4
  // src/type.ts
11
5
  var Events = /* @__PURE__ */ ((Events2) => {
@@ -507,6 +501,7 @@ var DisTubeVoice = class extends TypedEmitter {
507
501
  emittedError;
508
502
  isDisconnected = false;
509
503
  stream;
504
+ pausingStream;
510
505
  #channel;
511
506
  #volume = 100;
512
507
  constructor(voiceManager, channel) {
@@ -629,8 +624,8 @@ var DisTubeVoice = class extends TypedEmitter {
629
624
  * Play a {@link DisTubeStream}
630
625
  * @param dtStream - DisTubeStream
631
626
  */
632
- play(dtStream) {
633
- if (!checkEncryptionLibraries()) {
627
+ async play(dtStream) {
628
+ if (!await checkEncryptionLibraries()) {
634
629
  dtStream.kill();
635
630
  throw new DisTubeError("ENCRYPTION_LIBRARIES_MISSING");
636
631
  }
@@ -640,11 +635,15 @@ var DisTubeVoice = class extends TypedEmitter {
640
635
  this.emittedError = true;
641
636
  this.emit("error", error);
642
637
  });
643
- if (this.audioPlayer.state.status !== AudioPlayerStatus.Paused) this.audioPlayer.play(dtStream.audioResource);
644
- this.stream?.kill();
638
+ if (this.audioPlayer.state.status !== AudioPlayerStatus.Paused) {
639
+ this.audioPlayer.play(dtStream.audioResource);
640
+ this.stream?.kill();
641
+ dtStream.spawn();
642
+ } else if (!this.pausingStream) {
643
+ this.pausingStream = this.stream;
644
+ }
645
645
  this.stream = dtStream;
646
646
  this.volume = this.#volume;
647
- dtStream.spawn();
648
647
  }
649
648
  set volume(volume) {
650
649
  if (typeof volume !== "number" || isNaN(volume)) {
@@ -676,6 +675,9 @@ var DisTubeVoice = class extends TypedEmitter {
676
675
  if (state.status !== AudioPlayerStatus.Paused) return;
677
676
  if (this.stream?.audioResource && state.resource !== this.stream.audioResource) {
678
677
  this.audioPlayer.play(this.stream.audioResource);
678
+ this.stream.spawn();
679
+ this.pausingStream?.kill();
680
+ delete this.pausingStream;
679
681
  } else {
680
682
  this.audioPlayer.unpause();
681
683
  }
@@ -1433,7 +1435,7 @@ var QueueManager = class extends GuildIdManager {
1433
1435
  const dtStream = new DisTubeStream(stream.url, streamOptions);
1434
1436
  dtStream.on("debug", (data) => this.emit("ffmpegDebug" /* FFMPEG_DEBUG */, `[${queue.id}] ${data}`));
1435
1437
  this.debug(`[${queue.id}] Started playing: ${willPlaySong}`);
1436
- queue.voice.play(dtStream);
1438
+ await queue.voice.play(dtStream);
1437
1439
  if (emitPlaySong) this.emit("playSong" /* PLAY_SONG */, queue, song);
1438
1440
  } catch (e) {
1439
1441
  this.#handlePlayingError(queue, e);
@@ -1635,21 +1637,31 @@ var Queue = class extends DisTubeBase {
1635
1637
  * Pause the guild stream
1636
1638
  * @returns The guild queue
1637
1639
  */
1638
- pause() {
1639
- if (this.paused) throw new DisTubeError("PAUSED");
1640
- this.paused = true;
1641
- this.voice.pause();
1642
- return this;
1640
+ async pause() {
1641
+ await this._taskQueue.queuing();
1642
+ try {
1643
+ if (this.paused) throw new DisTubeError("PAUSED");
1644
+ this.paused = true;
1645
+ this.voice.pause();
1646
+ return this;
1647
+ } finally {
1648
+ this._taskQueue.resolve();
1649
+ }
1643
1650
  }
1644
1651
  /**
1645
1652
  * Resume the guild stream
1646
1653
  * @returns The guild queue
1647
1654
  */
1648
- resume() {
1649
- if (!this.paused) throw new DisTubeError("RESUMED");
1650
- this.paused = false;
1651
- this.voice.unpause();
1652
- return this;
1655
+ async resume() {
1656
+ await this._taskQueue.queuing();
1657
+ try {
1658
+ if (!this.paused) throw new DisTubeError("RESUMED");
1659
+ this.paused = false;
1660
+ this.voice.unpause();
1661
+ return this;
1662
+ } finally {
1663
+ this._taskQueue.resolve();
1664
+ }
1653
1665
  }
1654
1666
  /**
1655
1667
  * Set the guild stream's volume
@@ -2011,10 +2023,10 @@ function isNsfwChannel(channel) {
2011
2023
  }
2012
2024
  __name(isNsfwChannel, "isNsfwChannel");
2013
2025
  var isTruthy = /* @__PURE__ */ __name((x) => Boolean(x), "isTruthy");
2014
- var checkEncryptionLibraries = /* @__PURE__ */ __name(() => {
2026
+ var checkEncryptionLibraries = /* @__PURE__ */ __name(async () => {
2015
2027
  for (const lib of ["sodium-native", "sodium", "libsodium-wrappers", "tweetnacl"]) {
2016
2028
  try {
2017
- __require(lib);
2029
+ await import(lib);
2018
2030
  return true;
2019
2031
  } catch {
2020
2032
  }
@@ -2411,7 +2423,7 @@ ${e.message}`;
2411
2423
  };
2412
2424
 
2413
2425
  // src/index.ts
2414
- var version = "5.0.3";
2426
+ var version = "5.0.5";
2415
2427
  export {
2416
2428
  BaseManager,
2417
2429
  DisTube,