poru 2.0.0 → 2.0.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.
- package/package.json +1 -1
- package/src/Node.js +30 -8
- package/src/Player.js +31 -12
- package/src/Poru.js +4 -4
- package/src/config.js +1 -0
- package/src/platform/AppleMusic.js +6 -2
- package/typings/index.d.ts +2 -3
package/package.json
CHANGED
package/src/Node.js
CHANGED
|
@@ -55,6 +55,17 @@ class Node {
|
|
|
55
55
|
this.ws.on("close", this.#close.bind(this));
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
disconnect(){
|
|
59
|
+
if(!this.isConnected) return;
|
|
60
|
+
|
|
61
|
+
this.ws?.removeAllListeners();
|
|
62
|
+
this.ws?.close();
|
|
63
|
+
this.ws = null;
|
|
64
|
+
this.isConnected = false;
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
|
|
58
69
|
|
|
59
70
|
#open(){
|
|
60
71
|
if (this.reconnectAttempt) {
|
|
@@ -74,35 +85,46 @@ class Node {
|
|
|
74
85
|
this.manager.emit("nodeConnect", this);
|
|
75
86
|
this.isConnected = true;
|
|
76
87
|
this.manager.emit('debug', this.name, `[Web Socket] Connection ready ${this.url}`);
|
|
88
|
+
|
|
89
|
+
if(config.autoResume){
|
|
90
|
+
|
|
91
|
+
for (const player of this.manager.players.values()) {
|
|
92
|
+
if (player.node === this) {
|
|
93
|
+
player.restart();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
}
|
|
77
103
|
|
|
78
104
|
}
|
|
79
105
|
|
|
80
106
|
#message(payload) {
|
|
81
|
-
if (Array.isArray(payload)) payload = Buffer.concat(payload);
|
|
82
|
-
else if (payload instanceof ArrayBuffer) payload = Buffer.from(payload);
|
|
83
107
|
|
|
84
108
|
const packet = JSON.parse(payload);
|
|
85
109
|
if(!packet.op) return;
|
|
86
110
|
|
|
87
111
|
if (packet.op && packet.op === "stats") {
|
|
88
112
|
this.stats = { ...packet };
|
|
89
|
-
delete this.stats.op;
|
|
90
113
|
}
|
|
91
114
|
const player = this.manager.players.get(packet.guildId);
|
|
92
115
|
if (packet.guildId && player) player.emit(packet.op, packet);
|
|
93
|
-
|
|
94
|
-
packet.node = this;
|
|
116
|
+
packet.node = this;
|
|
95
117
|
this.manager.emit("debug",this.name,`[Web Socket] Lavalink Node Update : ${packet.op} `)
|
|
96
118
|
this.manager.emit("raw", packet);
|
|
97
119
|
}
|
|
98
120
|
|
|
99
121
|
#close(event) {
|
|
100
|
-
this.
|
|
122
|
+
this.disconnect();
|
|
123
|
+
this.manager.emit("nodeDisconnect",this,event);
|
|
101
124
|
this.manager.emit("debug",this.name,`[Web Socket] Connection with Lavalink closed with Error code : ${event||"Unknown code"}`)
|
|
102
125
|
if (event !== 1000){
|
|
103
126
|
|
|
104
|
-
|
|
105
|
-
}
|
|
127
|
+
}
|
|
106
128
|
}
|
|
107
129
|
|
|
108
130
|
|
package/src/Player.js
CHANGED
|
@@ -23,7 +23,7 @@ class Player extends EventEmitter {
|
|
|
23
23
|
|
|
24
24
|
this.isPlaying = false;
|
|
25
25
|
|
|
26
|
-
this.
|
|
26
|
+
this.isPaused = false;
|
|
27
27
|
|
|
28
28
|
this.trackRepeat = false;
|
|
29
29
|
|
|
@@ -51,23 +51,25 @@ class Player extends EventEmitter {
|
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
async play() {
|
|
54
|
+
async play(options={}) {
|
|
55
55
|
|
|
56
56
|
if (!this.queue.length) {
|
|
57
|
-
return
|
|
57
|
+
return null;
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
|
|
60
|
+
this.currentTrack = this.queue.shift()
|
|
61
|
+
|
|
60
62
|
if(!this.currentTrack.track){
|
|
61
63
|
this.currentTrack = await this.currentTrack.resolve(this.manager);
|
|
62
64
|
}
|
|
65
|
+
|
|
63
66
|
this.isPlaying = true;
|
|
64
|
-
this.timestamp = Date.now();
|
|
65
67
|
this.node.send({
|
|
66
68
|
op: "play",
|
|
67
69
|
guildId: this.guild,
|
|
68
70
|
track: this.currentTrack.track,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
noReplace:options.noReplace || true,
|
|
72
|
+
});
|
|
71
73
|
this.position = 0;
|
|
72
74
|
return this;
|
|
73
75
|
}
|
|
@@ -94,7 +96,7 @@ class Player extends EventEmitter {
|
|
|
94
96
|
pause,
|
|
95
97
|
});
|
|
96
98
|
this.isPlaying = !pause;
|
|
97
|
-
this.
|
|
99
|
+
this.isPaused = pause;
|
|
98
100
|
|
|
99
101
|
return this;
|
|
100
102
|
}
|
|
@@ -129,6 +131,7 @@ class Player extends EventEmitter {
|
|
|
129
131
|
return this;
|
|
130
132
|
}
|
|
131
133
|
|
|
134
|
+
|
|
132
135
|
async QueueRepeat() {
|
|
133
136
|
this.loop = 2;
|
|
134
137
|
this.queueRepeat = true;
|
|
@@ -140,9 +143,7 @@ class Player extends EventEmitter {
|
|
|
140
143
|
this.loop = 0;
|
|
141
144
|
this.trackRepeat = false;
|
|
142
145
|
this.queueRepeat = false;
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return this;
|
|
146
|
+
return this;
|
|
146
147
|
}
|
|
147
148
|
|
|
148
149
|
async setTextChannel(channel) {
|
|
@@ -187,7 +188,7 @@ class Player extends EventEmitter {
|
|
|
187
188
|
if (this.voiceChannel === null) return null;
|
|
188
189
|
this.pause(true);
|
|
189
190
|
this.isConnectd = false;
|
|
190
|
-
this.
|
|
191
|
+
this.node.send({
|
|
191
192
|
op: 4,
|
|
192
193
|
d: {
|
|
193
194
|
guild_id: this.guild,
|
|
@@ -210,6 +211,24 @@ class Player extends EventEmitter {
|
|
|
210
211
|
this.manager.players.delete(this.guild);
|
|
211
212
|
}
|
|
212
213
|
|
|
214
|
+
restart(){
|
|
215
|
+
this.filters.updateFilters();
|
|
216
|
+
if(this.currentTrack){
|
|
217
|
+
|
|
218
|
+
this.isPlaying = true;
|
|
219
|
+
this.node.send({
|
|
220
|
+
op: "play",
|
|
221
|
+
startTime: this.position,
|
|
222
|
+
noReplace:true,
|
|
223
|
+
guildId: this.guild,
|
|
224
|
+
track: this.currentTrack.track,
|
|
225
|
+
puase: this.isPaused
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
213
232
|
async autoplay(toggle = false) {
|
|
214
233
|
|
|
215
234
|
if (!toggle) return null;
|
package/src/Poru.js
CHANGED
|
@@ -100,7 +100,7 @@ class Poru extends EventEmitter {
|
|
|
100
100
|
|
|
101
101
|
}
|
|
102
102
|
this.deezer = new Deezer(this, this.options)
|
|
103
|
-
|
|
103
|
+
|
|
104
104
|
}
|
|
105
105
|
console.log(`Thanks for using Poru`)
|
|
106
106
|
}
|
|
@@ -190,16 +190,16 @@ class Poru extends EventEmitter {
|
|
|
190
190
|
|
|
191
191
|
|
|
192
192
|
|
|
193
|
-
async resolve(track,source) {
|
|
193
|
+
async resolve(track, source) {
|
|
194
194
|
|
|
195
195
|
const node = this.leastUsedNodes[0];
|
|
196
196
|
if (!node) throw new Error("No nodes are available.");
|
|
197
197
|
|
|
198
198
|
if (this.spotify && this.spotify.check(track)) {
|
|
199
199
|
return await this.spotify.resolve(track);
|
|
200
|
-
}else if (this.apple && this.apple.check(track)) {
|
|
200
|
+
} else if (this.apple && this.apple.check(track)) {
|
|
201
201
|
return await this.apple.resolve(track);
|
|
202
|
-
}else if (this.deezer && this.deezer.check(track)) {
|
|
202
|
+
} else if (this.deezer && this.deezer.check(track)) {
|
|
203
203
|
return await this.deezer.resolve(track);
|
|
204
204
|
}
|
|
205
205
|
|
package/src/config.js
CHANGED
|
@@ -109,14 +109,13 @@ class AppleMusic {
|
|
|
109
109
|
let query = new URL(url).pathname.split('/');
|
|
110
110
|
let id = query.pop();
|
|
111
111
|
let playlist = await this.requestData(`/playlists/${id}`)
|
|
112
|
-
|
|
112
|
+
let name = playlist.data[0].attributes.name
|
|
113
113
|
|
|
114
114
|
const limitedTracks = this.options.playlistLimit
|
|
115
115
|
? playlist.data[0].relationships.tracks.data.slice(0, this.options.playlistLimit * 100)
|
|
116
116
|
: playlist.data[0].relationships.tracks.data;
|
|
117
117
|
|
|
118
118
|
let tracks = await Promise.all(limitedTracks.map(x => this.buildUnresolved(x)))
|
|
119
|
-
|
|
120
119
|
return this.buildResponse('PLAYLIST_LOADED', tracks, name);
|
|
121
120
|
} catch (e) {
|
|
122
121
|
return this.buildResponse(
|
|
@@ -242,3 +241,8 @@ class AppleMusic {
|
|
|
242
241
|
|
|
243
242
|
}
|
|
244
243
|
module.exports = AppleMusic
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
const apple = new AppleMusic("",{apple:{}})
|
|
247
|
+
|
|
248
|
+
apple.resolve("https://music.apple.com/us/playlist/bollywood-hits/pl.d60caf02fcce4d7e9788fe01243b7c2c")
|
package/typings/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { EventEmitter, WebSocket } from "ws";
|
|
|
2
2
|
|
|
3
3
|
declare module'Poru' {
|
|
4
4
|
|
|
5
|
-
import { EventEmitter } from 'events';
|
|
6
5
|
|
|
7
6
|
export class Poru extends EventEmitter {
|
|
8
7
|
constructor(client: typeof EventEmitter| any,nodes:[],options:{})
|
|
@@ -108,7 +107,7 @@ export class Player extends EventEmitter {
|
|
|
108
107
|
|
|
109
108
|
public isPlaying:boolean;
|
|
110
109
|
|
|
111
|
-
public
|
|
110
|
+
public isPaused:boolean;
|
|
112
111
|
|
|
113
112
|
public trackRepeat:boolean;
|
|
114
113
|
|
|
@@ -157,4 +156,4 @@ export class Player extends EventEmitter {
|
|
|
157
156
|
|
|
158
157
|
autoplay(toggle:Boolean)
|
|
159
158
|
|
|
160
|
-
}
|
|
159
|
+
}
|