magmastream 2.10.0 → 2.10.1-dev.1

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.
@@ -4,7 +4,7 @@ import { EventEmitter } from "events";
4
4
  import { Node } from "./Node";
5
5
  import { Player } from "./Player";
6
6
  import { Redis as RedisClient } from "ioredis";
7
- import { AnyGuild, AnyUser, ManagerEvents, ManagerInitOptions, ManagerOptions, NodeOptions, PlayerOptions, SearchQuery, SearchResult, TrackData, VoicePacket, VoiceServer, VoiceState } from "./Types";
7
+ import { AnyGuild, AnyUser, DiscordVoiceState, ManagerEvents, ManagerInitOptions, ManagerOptions, NodeOptions, PlayerOptions, SearchQuery, SearchResult, TrackData, VoicePacket, VoiceServer } from "./Types";
8
8
  /**
9
9
  * The main hub for interacting with Lavalink and using Magmastream.
10
10
  */
@@ -95,7 +95,7 @@ export declare class Manager extends EventEmitter {
95
95
  * @returns A promise that resolves when the voice state update is handled.
96
96
  * @emits {debug} - Emits a debug message indicating the voice state is being updated.
97
97
  */
98
- updateVoiceState(data: VoicePacket | VoiceServer | VoiceState): Promise<void>;
98
+ updateVoiceState(data: VoicePacket | VoiceServer | DiscordVoiceState): Promise<void>;
99
99
  /**
100
100
  * Decodes an array of base64 encoded tracks and returns an array of TrackData.
101
101
  * Emits a debug event with the tracks being decoded.
@@ -544,7 +544,8 @@ class Manager extends events_1.EventEmitter {
544
544
  await player.play(Utils_1.TrackUtils.build(lavaPlayer.track, currentTrack.requester, currentTrack.isAutoplay), { startTime: lavaPlayer.state.position ?? 0 });
545
545
  await node.rest.delete(`/v4/sessions/${state.node.sessionId}/players/${state.guildId}`);
546
546
  }
547
- await player.pause(state.paused);
547
+ if (state.paused)
548
+ await player.pause(true);
548
549
  await cleanup();
549
550
  this.emit(Enums_1.ManagerEventTypes.PlayerRestored, player, node);
550
551
  await this.sleep(1000);
@@ -1,7 +1,7 @@
1
1
  import { Filters } from "./Filters";
2
2
  import { Manager } from "./Manager";
3
3
  import { Node } from "./Node";
4
- import { AnyMessage, IQueue, Lyrics, PlayerOptions, PlayOptions, SearchQuery, SearchResult, Track, VoiceState } from "./Types";
4
+ import { AnyMessage, IQueue, Lyrics, PlayerOptions, PlayerVoiceState, PlayOptions, SearchQuery, SearchResult, Track } from "./Types";
5
5
  import { SponsorBlockSegment, StateTypes } from "./Enums";
6
6
  import { WebSocket } from "ws";
7
7
  export declare class Player {
@@ -38,8 +38,8 @@ export declare class Player {
38
38
  state: StateTypes;
39
39
  /** The equalizer bands array. */
40
40
  bands: number[];
41
- /** The voice state object from Discord. */
42
- voiceState: VoiceState;
41
+ /** The voice state object from the node. */
42
+ voiceState: PlayerVoiceState;
43
43
  /** The Manager. */
44
44
  manager: Manager;
45
45
  /** The autoplay state of the player. */
@@ -46,7 +46,7 @@ class Player {
46
46
  state = Enums_1.StateTypes.Disconnected;
47
47
  /** The equalizer bands array. */
48
48
  bands = new Array(15).fill(0.0);
49
- /** The voice state object from Discord. */
49
+ /** The voice state object from the node. */
50
50
  voiceState;
51
51
  /** The Manager. */
52
52
  manager;
@@ -95,10 +95,7 @@ class Player {
95
95
  };
96
96
  // Set the guild ID and voice state.
97
97
  this.guildId = options.guildId;
98
- this.voiceState = Object.assign({
99
- op: "voiceUpdate",
100
- guild_id: options.guildId,
101
- });
98
+ this.voiceState = {};
102
99
  // Set the voice and text channels if they exist.
103
100
  if (options.voiceChannelId)
104
101
  this.voiceChannelId = options.voiceChannelId;
@@ -388,8 +385,11 @@ class Player {
388
385
  await this.node.rest.updatePlayer({
389
386
  guildId: this.guildId,
390
387
  data: {
391
- encodedTrack: (await this.queue.getCurrent()).track,
388
+ track: {
389
+ encoded: (await this.queue.getCurrent()).track,
390
+ },
392
391
  ...finalOptions,
392
+ position: finalOptions.startTime || 0,
393
393
  },
394
394
  });
395
395
  this.playing = true;
@@ -694,7 +694,10 @@ class Player {
694
694
  guildId: this.guildId,
695
695
  data: {
696
696
  position: 0,
697
- encodedTrack: (await this.queue.getCurrent())?.track,
697
+ track: {
698
+ encoded: (await this.queue.getCurrent())?.track,
699
+ userData: (await this.queue.getCurrent())?.requester,
700
+ },
698
701
  },
699
702
  });
700
703
  return this;
@@ -730,7 +733,7 @@ class Player {
730
733
  this.node.rest.updatePlayer({
731
734
  guildId: this.guildId,
732
735
  data: {
733
- encodedTrack: null,
736
+ track: null,
734
737
  },
735
738
  });
736
739
  this.manager.emit(Enums_1.ManagerEventTypes.PlayerStateUpdate, oldPlayer, this, {
@@ -940,7 +943,13 @@ class Player {
940
943
  this.manager.players.set(this.guildId, this);
941
944
  await this.node.rest.updatePlayer({
942
945
  guildId: this.guildId,
943
- data: { paused: this.paused, volume: this.volume, position: playerPosition, encodedTrack: currentTrack?.track, voice: { token, endpoint, sessionId, channelId } },
946
+ data: {
947
+ paused: this.paused,
948
+ volume: this.volume,
949
+ position: playerPosition,
950
+ track: { encoded: currentTrack?.track },
951
+ voice: { token, endpoint, sessionId, channelId },
952
+ },
944
953
  });
945
954
  await this.filters.updateFilters();
946
955
  }
@@ -645,7 +645,7 @@ export interface ManagerEvents {
645
645
  */
646
646
  export interface VoicePacket {
647
647
  t?: "VOICE_SERVER_UPDATE" | "VOICE_STATE_UPDATE";
648
- d: VoiceState | VoiceServer;
648
+ d: DiscordVoiceState | VoiceServer;
649
649
  }
650
650
  /**
651
651
  * Voice Server
@@ -663,7 +663,7 @@ export interface Extendable {
663
663
  /**
664
664
  * Voice State
665
665
  */
666
- export interface VoiceState {
666
+ export interface PlayerVoiceState {
667
667
  op: "voiceUpdate";
668
668
  guildId: string;
669
669
  event: VoiceServer;
@@ -673,12 +673,14 @@ export interface VoiceState {
673
673
  /**
674
674
  * Voice State
675
675
  */
676
- export interface VoiceState {
676
+ export interface DiscordVoiceState {
677
677
  guild_id: string;
678
678
  user_id: string;
679
679
  session_id: string;
680
680
  channel_id: string;
681
681
  }
682
+ /** @deprecated Use DiscordVoiceState or PlayerVoiceState instead */
683
+ export type VoiceState = DiscordVoiceState | PlayerVoiceState;
682
684
  /**
683
685
  * NodeStats interface
684
686
  */
@@ -1069,28 +1071,32 @@ export interface PlayOptions {
1069
1071
  * RestPlayOptions interface
1070
1072
  */
1071
1073
  export interface RestPlayOptions {
1074
+ /** The guild ID the Player belongs to. */
1072
1075
  guildId: string;
1076
+ /** Whether to not replace the track if a play payload is sent. */
1077
+ noReplace?: boolean;
1073
1078
  data: {
1074
1079
  /** The base64 encoded track. */
1075
- encodedTrack?: string;
1076
- /** The track ID. */
1077
- identifier?: string;
1078
- /** The track time to start at. */
1079
- startTime?: number;
1080
+ track?: {
1081
+ /** The base64 encoded track. */
1082
+ encoded?: string | null;
1083
+ /** The track ID. */
1084
+ identifier?: string | null;
1085
+ /** The user data of the track. */
1086
+ userData?: object;
1087
+ };
1088
+ /** The player position in a track. */
1089
+ position?: number;
1080
1090
  /** The track time to end at. */
1081
1091
  endTime?: number;
1082
1092
  /** The player volume level. */
1083
1093
  volume?: number;
1084
- /** The player position in a track. */
1085
- position?: number;
1086
1094
  /** Whether the player is paused. */
1087
1095
  paused?: boolean;
1088
1096
  /** The audio effects. */
1089
1097
  filters?: object;
1090
1098
  /** voice payload. */
1091
1099
  voice?: LavalinkVoiceStateUpdate;
1092
- /** Whether to not replace the track if a play payload is sent. */
1093
- noReplace?: boolean;
1094
1100
  };
1095
1101
  }
1096
1102
  /**
@@ -1111,7 +1117,7 @@ export interface SerializedPlayerState {
1111
1117
  queueRepeat: boolean;
1112
1118
  dynamicRepeat: boolean;
1113
1119
  dynamicLoopInterval?: number;
1114
- voiceState: VoiceState;
1120
+ voiceState: PlayerVoiceState;
1115
1121
  options: PlayerOptions;
1116
1122
  node: {
1117
1123
  sessionId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "magmastream",
3
- "version": "2.10.0",
3
+ "version": "2.10.1-dev.1",
4
4
  "description": "A user-friendly Lavalink client designed for NodeJS.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -100,9 +100,9 @@
100
100
  ],
101
101
  "repository": {
102
102
  "type": "git",
103
- "url": "git+https://gitryx.com/MagmaStream/magmastream.git#main"
103
+ "url": "https://gitryx.com/MagmaStream/magmastream.git"
104
104
  },
105
105
  "homepage": "https://docs.magmastream.com",
106
106
  "author": "Abel Purnwasy",
107
107
  "license": "Apache-2.0"
108
- }
108
+ }