Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 26 additions and 23 deletions.
  1. +14 −12 mojolicious-radio-box.pl
  2. +10 −10 src/radio-box-client.coffee
  3. +2 −1 src/routers.pm
View
26 mojolicious-radio-box.pl
@@ -355,7 +355,8 @@ sub _cmus_parse_info {
return $self->render_json({status => 'ok', info => cmus_get_music()});
};
-post '/set_volume' => sub {
+# curl -s -d '' 'http://localhost:8080/set_volume/20'
+post '/set_volume/:volume' => [volume => qr/\d+/] => sub {
my $self = shift;
my $volume = $self->param("volume");
@@ -535,6 +536,9 @@ sub _cmus_parse_info {
update_info: function() {
return $.get('/get_info', function(info_data) {
App.info = info_data.info;
+ if (App.info.volume != null) {
+ App.volume = App.info.volume;
+ }
return App.render_info();
});
},
@@ -570,8 +574,8 @@ sub _cmus_parse_info {
App.do_get_radio();
}
}
- if (App.info.volume != null) {
- return $('input#volume_slider').val(App.info.volume);
+ if (App.volume != null) {
+ return $('input#volume_slider').val(App.volume);
}
},
render_select_radio: function() {
@@ -671,13 +675,13 @@ sub _cmus_parse_info {
App._change_valume_tid = void 0;
}
new_volume = 0;
- if (event.data.up) {
- new_volume = App.info.volume + event.data.up;
+ if (event.data.up && (App.volume != null)) {
+ new_volume = App.volume + event.data.up;
if (new_volume > 100) {
new_volume = 100;
}
- } else if (event.data.down) {
- new_volume = App.info.volume - event.data.down;
+ } else if (event.data.down && (App.volume != null)) {
+ new_volume = App.volume - event.data.down;
if (new_volume < 0) {
new_volume = 0;
}
@@ -687,12 +691,10 @@ sub _cmus_parse_info {
return;
}
return App._change_valume_tid = window.setTimeout(function() {
- if ((new_volume != null) && new_volume !== App.info.volume) {
- App.info.volume = new_volume;
+ if ((new_volume != null) && new_volume !== App.volume) {
+ App.volume = new_volume;
$("#volume_slider").val(new_volume);
- return $.post('/set_volume', {
- volume: new_volume
- });
+ return $.post('/set_volume/' + new_volume);
}
}, 200);
}
View
20 src/radio-box-client.coffee
@@ -34,6 +34,7 @@ window.App =
update_info: ->
$.get '/get_info', (info_data) ->
App.info = info_data.info
+ App.volume = App.info.volume if App.info.volume?
App.render_info()
# ...........................................
@@ -82,8 +83,8 @@ window.App =
else
App.do_get_radio()
- if App.info.volume?
- $('input#volume_slider').val(App.info.volume)
+ if App.volume?
+ $('input#volume_slider').val(App.volume)
# ...........................................
render_select_radio: ->
@@ -167,11 +168,11 @@ window.App =
App._change_valume_tid = undefined
new_volume = 0
- if event.data.up
- new_volume = App.info.volume + event.data.up
+ if event.data.up && App.volume?
+ new_volume = App.volume + event.data.up
new_volume = 100 if new_volume > 100
- else if event.data.down
- new_volume = App.info.volume - event.data.down
+ else if event.data.down && App.volume?
+ new_volume = App.volume - event.data.down
new_volume = 0 if new_volume < 0
else if event.data.absolute
new_volume = parseInt($("#volume_slider").val())
@@ -180,11 +181,10 @@ window.App =
App._change_valume_tid = window.setTimeout(
() ->
- if new_volume? && new_volume != App.info.volume
- App.info.volume = new_volume
+ if new_volume? && new_volume != App.volume
+ App.volume = new_volume
$("#volume_slider").val(new_volume)
- $.post '/set_volume'
- volume: new_volume
+ $.post '/set_volume/' + new_volume
200
)
# .............................................................................
View
3 src/routers.pm
@@ -46,7 +46,8 @@ get '/get_music' => sub {
return $self->render_json({status => 'ok', info => cmus_get_music()});
};
-post '/set_volume' => sub {
+# curl -s -d '' 'http://localhost:8080/set_volume/20'
+post '/set_volume/:volume' => [volume => qr/\d+/] => sub {
my $self = shift;
my $volume = $self->param("volume");

No commit comments for this range

Something went wrong with that request. Please try again.