linkdave 0.1.6-dev.ade6ce7 → 0.1.6-dev.cedfd65

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/player.d.ts CHANGED
@@ -14,6 +14,7 @@ export interface PlayerOptions {
14
14
  voiceChannelId?: string;
15
15
  selfMute?: boolean;
16
16
  selfDeaf?: boolean;
17
+ inactivityTimeout?: number;
17
18
  }
18
19
  export type RawVoiceStateUpdate = Pick<GatewayVoiceStateUpdateDispatchData, "user_id" | "channel_id" | "session_id">;
19
20
  export type RawVoiceServerUpdate = Pick<GatewayVoiceServerUpdateDispatchData, "token" | "guild_id" | "endpoint">;
package/dist/player.js CHANGED
@@ -19,6 +19,8 @@ export class Player {
19
19
  #pendingVoice = null;
20
20
  #migrationTarget = null;
21
21
  #migrationResolve = null;
22
+ #inactivityTimeout;
23
+ #inactivityTimer = null;
22
24
  constructor(client, guildId, node, options) {
23
25
  this.#client = client;
24
26
  this.#guildId = guildId;
@@ -27,6 +29,7 @@ export class Player {
27
29
  this.#voiceChannelId = options?.voiceChannelId ?? null;
28
30
  this.#selfMute = options?.selfMute ?? false;
29
31
  this.#selfDeaf = options?.selfDeaf ?? true;
32
+ this.#inactivityTimeout = options?.inactivityTimeout ?? 0;
30
33
  }
31
34
  get guildId() {
32
35
  return this.#guildId;
@@ -247,16 +250,22 @@ export class Player {
247
250
  });
248
251
  }
249
252
  _onPlayerUpdate(data) {
253
+ if (data.state === PlayerState.Playing)
254
+ this.#stopTimer();
255
+ else if (this.#state === PlayerState.Playing)
256
+ this.#startTimer();
250
257
  this.#state = data.state;
251
258
  }
252
259
  _onTrackStart(data) {
253
260
  this.#current = data.track;
254
261
  this.#state = PlayerState.Playing;
262
+ this.#stopTimer();
255
263
  }
256
264
  _onTrackEnd(data) {
257
265
  if (!this.#queue.active || this.#queue.size === 0) {
258
- this.#current = null;
259
266
  this.#state = PlayerState.Idle;
267
+ this.#current = null;
268
+ this.#startTimer();
260
269
  }
261
270
  this.#queue._onTrackEnd(data.reason !== TrackEndReason.Stopped && data.reason !== TrackEndReason.Replaced);
262
271
  }
@@ -264,6 +273,7 @@ export class Player {
264
273
  if (this.#state !== PlayerState.Connecting)
265
274
  return;
266
275
  this.#state = PlayerState.Idle;
276
+ this.#startTimer();
267
277
  }
268
278
  #cleanup() {
269
279
  this.#voiceChannelId = null;
@@ -272,6 +282,7 @@ export class Player {
272
282
  this.#pendingVoice = null;
273
283
  this.#state = PlayerState.Idle;
274
284
  this.#current = null;
285
+ this.#stopTimer();
275
286
  }
276
287
  _onVoiceDisconnect() {
277
288
  this.#cleanup();
@@ -314,4 +325,28 @@ export class Player {
314
325
  this.#migrationResolve(null);
315
326
  this.#migrationResolve = null;
316
327
  }
328
+ #startTimer() {
329
+ if (this.#inactivityTimeout <= 0)
330
+ return;
331
+ this.#stopTimer();
332
+ this.#inactivityTimer = setTimeout(() => {
333
+ if (this.#state === PlayerState.Playing)
334
+ return;
335
+ this.disconnect();
336
+ if (this.#node.connected) {
337
+ void this.#node.sendDisconnect(this.#guildId);
338
+ }
339
+ this.#client._onPlayerDestroy(this.#guildId);
340
+ this.#client.emit(EventName.VoiceDisconnect, {
341
+ guild_id: this.#guildId,
342
+ reason: DisconnectReason.Inactivity
343
+ });
344
+ }, this.#inactivityTimeout);
345
+ }
346
+ #stopTimer() {
347
+ if (this.#inactivityTimer === null)
348
+ return;
349
+ clearTimeout(this.#inactivityTimer);
350
+ this.#inactivityTimer = null;
351
+ }
317
352
  }
package/dist/types.d.ts CHANGED
@@ -144,7 +144,8 @@ export interface QueueErrorPayload {
144
144
  export declare enum DisconnectReason {
145
145
  ConnectionLost = "connection_lost",
146
146
  ConnectionFailed = "connection_failed",
147
- Requested = "requested"
147
+ Requested = "requested",
148
+ Inactivity = "inactivity"
148
149
  }
149
150
  export interface VoiceConnectPayload {
150
151
  guild_id: string;
package/dist/types.js CHANGED
@@ -50,6 +50,7 @@ export var DisconnectReason;
50
50
  DisconnectReason["ConnectionLost"] = "connection_lost";
51
51
  DisconnectReason["ConnectionFailed"] = "connection_failed";
52
52
  DisconnectReason["Requested"] = "requested";
53
+ DisconnectReason["Inactivity"] = "inactivity";
53
54
  })(DisconnectReason || (DisconnectReason = {}));
54
55
  export var EventName;
55
56
  (function (EventName) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linkdave",
3
- "version": "0.1.6-dev.ade6ce7",
3
+ "version": "0.1.6-dev.cedfd65",
4
4
  "author": "Luna Seemann <luna@wamellow.com> (http://shi.gg)",
5
5
  "description": "TypeScript client library for linkdave Discord audio streaming server",
6
6
  "repository": {