11import { DebugEvents } from "./Constants" ;
2- import type { DestroyReasons } from "./Constants" ;
32import { bandCampSearch } from "./CustomSearches/BandCampSearch" ;
43import { FilterManager } from "./Filters" ;
4+ import { Queue , QueueSaver } from "./Queue" ;
5+ import { queueTrackEnd } from "./Utils" ;
6+
7+ import type { DestroyReasons } from "./Constants" ;
58import type { LavalinkManager } from "./LavalinkManager" ;
69import type { LavalinkNode } from "./Node" ;
710import type { NodeLinkNode } from "./NodeLink" ;
8- import { Queue , QueueSaver } from "./Queue" ;
911import type { SponsorBlockSegment } from "./Types/Node" ;
1012import type {
1113 anyObject ,
@@ -17,7 +19,6 @@ import type {
1719} from "./Types/Player" ;
1820import type { Track , UnresolvedTrack } from "./Types/Track" ;
1921import type { LavalinkPlayerVoiceOptions , LavaSearchQuery , SearchQuery } from "./Types/Utils" ;
20- import { queueTrackEnd } from "./Utils" ;
2122export class Player {
2223 /** Filter Manager per player */
2324 public filterManager : FilterManager ;
@@ -480,6 +481,19 @@ export class Player {
480481 return this ;
481482 }
482483
484+ /**
485+ * The old JSON of the player, used for the "playerClientUpdate" event, which is emitted on every update of the player via a function call, so that you can compare the old data with the new data and do something with it if you want to.
486+ */
487+ public oldJSON :PlayerJson = this . toJSON ( ) ;
488+
489+ /**
490+ * Emits the "playerClientUpdate" event, which is emitted on every update of the player via a function call, so that you can compare the old data with the new data and do something with it if you want to.
491+ */
492+ public triggerPlayerClientUpdate ( ) {
493+ this . LavalinkManager . emit ( "playerClientUpdate" , this . oldJSON , this ) ;
494+ this . oldJSON = this . toJSON ( ) ;
495+ }
496+
483497 /**
484498 * Set the Volume for the Player
485499 * @param volume The Volume in percent
@@ -506,6 +520,8 @@ export class Player {
506520 ) ,
507521 ) ;
508522
523+ this . triggerPlayerClientUpdate ( ) ;
524+
509525 const now = performance . now ( ) ;
510526 if ( this . LavalinkManager . options . playerOptions . applyVolumeAsFilter ) {
511527 this . _emitDebugEvent ( DebugEvents . PlayerVolumeAsFilter , {
@@ -583,6 +599,7 @@ export class Player {
583599 this . paused = true ;
584600 this . lastPositionChange = null ; // needs to removed to not cause issues
585601 const now = performance . now ( ) ;
602+ this . triggerPlayerClientUpdate ( ) ;
586603 await this . node . updatePlayer ( { guildId : this . guildId , playerOptions : { paused : true } } ) ;
587604 this . ping . lavalink = Math . round ( ( performance . now ( ) - now ) / 10 ) / 100 ;
588605 // emit the event
@@ -597,6 +614,7 @@ export class Player {
597614 if ( ! this . paused ) throw new Error ( "Player isn't paused - not able to resume." ) ;
598615 this . paused = false ;
599616 const now = performance . now ( ) ;
617+ this . triggerPlayerClientUpdate ( ) ;
600618 await this . node . updatePlayer ( { guildId : this . guildId , playerOptions : { paused : false } } ) ;
601619 this . ping . lavalink = Math . round ( ( performance . now ( ) - now ) / 10 ) / 100 ;
602620 // emit the event
@@ -625,6 +643,7 @@ export class Player {
625643 this . lastPosition = position ;
626644
627645 const now = performance . now ( ) ;
646+ this . triggerPlayerClientUpdate ( ) ;
628647 await this . node . updatePlayer ( { guildId : this . guildId , playerOptions : { position } } ) ;
629648 this . ping . lavalink = Math . round ( ( performance . now ( ) - now ) / 10 ) / 100 ;
630649
@@ -639,6 +658,7 @@ export class Player {
639658 if ( ! [ "off" , "track" , "queue" ] . includes ( repeatMode ) )
640659 throw new RangeError ( "Repeatmode must be either 'off', 'track', or 'queue'" ) ;
641660 this . repeatMode = repeatMode ;
661+ this . triggerPlayerClientUpdate ( ) ;
642662 return this ;
643663 }
644664
@@ -1047,7 +1067,7 @@ export class Player {
10471067 nodeId : this . node ?. id ,
10481068 nodeSessionId : this . node ?. sessionId ,
10491069 ping : this . ping ,
1050- queue : this . queue . utils . toJSON ( ) ,
1070+ queue : this . queue ? .utils ? .toJSON ?. ( ) ,
10511071 } as PlayerJson ;
10521072 }
10531073}
0 commit comments