22
33import com .google .gson .JsonObject ;
44import com .spotify .metadata .proto .Metadata ;
5- import io .undertow .server .HttpHandler ;
65import io .undertow .server .HttpServerExchange ;
76import org .jetbrains .annotations .NotNull ;
87import org .jetbrains .annotations .Nullable ;
8+ import xyz .gianlu .librespot .api .SessionWrapper ;
99import xyz .gianlu .librespot .api .Utils ;
1010import xyz .gianlu .librespot .common .ProtobufToJson ;
1111import xyz .gianlu .librespot .core .Session ;
1818import java .util .Map ;
1919import java .util .Objects ;
2020
21- public final class PlayerHandler implements HttpHandler {
22- private final Session session ;
21+ public final class PlayerHandler extends AbsSessionHandler {
2322
24- public PlayerHandler (@ NotNull Session session ) {
25- this . session = session ;
23+ public PlayerHandler (@ NotNull SessionWrapper wrapper ) {
24+ super ( wrapper ) ;
2625 }
2726
28- private void setVolume (HttpServerExchange exchange , @ Nullable String valStr ) {
27+ private void setVolume (HttpServerExchange exchange , Session session , @ Nullable String valStr ) {
2928 if (valStr == null ) {
3029 Utils .invalidParameter (exchange , "volume" );
3130 return ;
@@ -47,7 +46,7 @@ private void setVolume(HttpServerExchange exchange, @Nullable String valStr) {
4746 session .player ().setVolume (val );
4847 }
4948
50- private void load (HttpServerExchange exchange , @ Nullable String uri , boolean play ) {
49+ private void load (HttpServerExchange exchange , Session session , @ Nullable String uri , boolean play ) {
5150 if (uri == null ) {
5251 Utils .invalidParameter (exchange , "uri" );
5352 return ;
@@ -56,7 +55,7 @@ private void load(HttpServerExchange exchange, @Nullable String uri, boolean pla
5655 session .player ().load (uri , play );
5756 }
5857
59- private void current (HttpServerExchange exchange ) {
58+ private void current (HttpServerExchange exchange , Session session ) {
6059 PlayableId id = session .player ().currentPlayableId ();
6160
6261 JsonObject obj = new JsonObject ();
@@ -90,7 +89,7 @@ private void current(HttpServerExchange exchange) {
9089 }
9190
9291 @ Override
93- public void handleRequest (HttpServerExchange exchange ) throws Exception {
92+ protected void handleRequest (@ NotNull HttpServerExchange exchange , @ NotNull Session session ) throws Exception {
9493 exchange .startBlocking ();
9594 if (exchange .isInIoThread ()) {
9695 exchange .dispatch (this );
@@ -112,10 +111,10 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
112111
113112 switch (cmd ) {
114113 case CURRENT :
115- current (exchange );
114+ current (exchange , session );
116115 return ;
117116 case SET_VOLUME :
118- setVolume (exchange , Utils .getFirstString (params , "volume" ));
117+ setVolume (exchange , session , Utils .getFirstString (params , "volume" ));
119118 return ;
120119 case VOLUME_UP :
121120 session .player ().volumeUp ();
@@ -124,7 +123,7 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
124123 session .player ().volumeDown ();
125124 return ;
126125 case LOAD :
127- load (exchange , Utils .getFirstString (params , "uri" ), Utils .getFirstBoolean (params , "play" ));
126+ load (exchange , session , Utils .getFirstString (params , "uri" ), Utils .getFirstBoolean (params , "play" ));
128127 return ;
129128 case PAUSE :
130129 session .player ().pause ();
0 commit comments