@@ -12,6 +12,10 @@ var keysharky = {
1212 "voteup" : function ( ) { keysharky . gsliteswf . voteCurrentSong ( 1 ) ; } ,
1313 "votedown" : function ( ) { keysharky . gsliteswf . voteCurrentSong ( - 1 ) ; } ,
1414 "voteclear" : function ( ) { keysharky . gsliteswf . voteCurrentSong ( 0 ) ; } ,
15+
16+ "mute" : function ( ) { keysharky . gsliteswf . setIsMuted ( keysharky . gsliteswf . getIsMuted ( ) ? false : true ) ; } ,
17+ "volup" : function ( ) { keysharky . gsliteswf . setVolume ( keysharky . gsliteswf . getVolume ( ) + 10 ) ; } ,
18+ "voldown" : function ( ) { keysharky . gsliteswf . setVolume ( keysharky . gsliteswf . getVolume ( ) - 10 ) ; }
1519 } ;
1620
1721 this . defaults = {
@@ -25,13 +29,20 @@ var keysharky = {
2529 "votedown" : '{"modifiers":["control","alt"],"key":"Z","keycode":"","enabled":true}' ,
2630 "voteclear" : '{"modifiers":["control","alt"],"key":"Q","keycode":"","enabled":true}' ,
2731
32+ "mute" : '{"modifiers":["control","shift"],"key":"M","keycode":"","enabled":true}' ,
33+ "volup" : '{"modifiers":["control","shift"],"key":">","keycode":"","enabled":true}' ,
34+ "voldown" : '{"modifiers":["control","shift"],"key":"<","keycode":"","enabled":true}' ,
35+
2836 "server_port" : 8800
2937 }
3038
3139 this . serverMethods = {
3240 "currentSong" : function ( ) { return keysharky . gsliteswf . getCurrentSongStatus ( ) ; } ,
3341 "nextSong" : function ( ) { return keysharky . gsliteswf . getNextSong ( ) ; } ,
3442 "previousSong" : function ( ) { return keysharky . gsliteswf . getPreviousSong ( ) ; } ,
43+
44+ "volume" : function ( ) { return keysharky . gsliteswf . getVolume ( ) ; } ,
45+ "muted" : function ( ) { return keysharky . gsliteswf . getIsMuted ( ) ; } ,
3546 } ;
3647
3748 this . consoleObject = Components . classes [ "@mozilla.org/consoleservice;1" ] . getService ( Components . interfaces . nsIConsoleService ) ;
@@ -70,11 +81,13 @@ var keysharky = {
7081
7182 this . gsAPI . registerErrorHandler ( 404 , this . serverErrorParser ) ;
7283 this . gsAPI . registerPathHandler ( "/" , this . serverErrorParser ) ;
84+
7385 this . gsAPI . registerPathHandler ( "/gs-version" , this . serverGroovesharkVersion ) ;
7486 this . gsAPI . registerPathHandler ( "/gs-api-version" , this . serverGroovesharkAPIVersion ) ;
87+ this . gsAPI . registerPathHandler ( "/setVolume" , this . serverVolumeControl ) ;
7588
7689 for ( var method in this . serverMethods ) {
77- this . gsAPI . registerPathHandler ( "/" + method , this . serverSong ) ;
90+ this . gsAPI . registerPathHandler ( "/" + method , this . serverInfo ) ;
7891 }
7992
8093 for ( var toggle in this . allToggles ) {
@@ -104,6 +117,45 @@ var keysharky = {
104117 return true ;
105118 } ,
106119
120+ serverVolumeControl : function ( request , response ) {
121+
122+ var volume = / ^ ( \d + ) $ / i. exec ( request . queryString ) ;
123+ var toggled = false ;
124+
125+ if ( volume != null && volume [ 1 ] >= 0 && volume [ 1 ] <= 100 ) {
126+
127+ try {
128+ keysharky . gsliteswf . setVolume ( volume [ 1 ] ) ;
129+ toggled = true ;
130+ } catch ( e ) {
131+
132+ try {
133+ keysharky . findGrooveshark ( ) ;
134+
135+ keysharky . gsliteswf . setVolume ( volume [ 1 ] ) ;
136+ toggled = true ;
137+ } catch ( e ) { }
138+
139+ }
140+
141+ if ( toggled ) {
142+
143+ response . setStatusLine ( "1.1" , 200 , "OK" ) ;
144+ response . write ( "VOLUME SET TO " + volume [ 1 ] ) ;
145+
146+ } else {
147+
148+ response . setStatusLine ( "1.1" , 500 , "FAILED" ) ;
149+ response . write ( "COULDN'T SET VOLUME" ) ;
150+
151+ }
152+ } else {
153+ response . setStatusLine ( "1.1" , 500 , "FAILED" ) ;
154+ response . write ( "BAD VOLUME VALUE. MUST BE BETWEEN 0 AND 100." ) ;
155+ }
156+
157+ } ,
158+
107159 // Retrieves info about GroovesharkAPI version
108160 serverGroovesharkAPIVersion : function ( request , response ) {
109161 try {
@@ -178,8 +230,8 @@ var keysharky = {
178230 }
179231 } ,
180232
181- // Shows previous/current/next song status in plain text
182- serverSong : function ( request , response ) {
233+ // Retrieves and shows status messages
234+ serverInfo : function ( request , response ) {
183235 var method = / \/ ( \w + ) / i. exec ( request . path ) ;
184236 var jsonArr = { } ;
185237
@@ -197,26 +249,30 @@ var keysharky = {
197249
198250 response . setHeader ( "Cache-Control" , "no-cache" , false ) ;
199251
200- if ( json ) {
252+ if ( typeof ( json ) != "undefined" ) {
201253 response . setStatusLine ( "1.1" , 200 , "OK" ) ;
202254
203255 if ( method [ 1 ] == "currentSong" ) {
204256
205257 response . write ( "status: " + json . status + "\n" ) ;
206258 jsonArr = json . song ;
207259
208- } else {
260+ } else if ( method [ 1 ] == "nextSong" || method [ 1 ] == "previousSong" ) {
209261
210262 jsonArr = json ;
211263
264+ } else {
265+
266+ jsonArr [ method [ 1 ] ] = json ;
267+
212268 }
213269
214270 for ( var status in jsonArr ) {
215271 response . write ( status + ": " + jsonArr [ status ] + "\n" ) ;
216272 }
217273 } else {
218274 response . setStatusLine ( "1.1" , 500 , "FAILED" ) ;
219- response . write ( "COULDN'T RETRIEVE SONG STATUS" ) ;
275+ response . write ( "COULDN'T RETRIEVE '" + method [ 1 ] + "' STATUS") ;
220276 }
221277
222278 } ,
@@ -463,7 +519,6 @@ var keysharky = {
463519 for ( var toggle in this . allToggles ) {
464520 id_arr [ i ] = toggle ;
465521 json_arr [ i ] = this . getPref ( toggle ) ;
466-
467522 i ++ ;
468523 }
469524
@@ -492,6 +547,7 @@ var keysharky = {
492547
493548 this . optionsDoc . getElementById ( "keysharky-group-playback" ) . style . display = "none" ;
494549 this . optionsDoc . getElementById ( "keysharky-group-current" ) . style . display = "none" ;
550+ this . optionsDoc . getElementById ( "keysharky-group-sound" ) . style . display = "none" ;
495551 this . optionsDoc . getElementById ( "keysharky-group-readme" ) . style . display = "none" ;
496552
497553 }
@@ -728,7 +784,6 @@ var keysharky = {
728784 }
729785
730786 } catch ( e ) {
731- this . log ( e ) ;
732787 this . setPref ( id , this . JSON . parse ( this . defaults [ id ] ) ) ;
733788 }
734789
0 commit comments