Refactor Jukebox control
- Moves the functions to make the jukebox-related API calls to the subsonic service - Initiate the API calls from the player directive to centralize the logic.
This commit is contained in:
parent
8c279093df
commit
ee7d11d8d7
5 changed files with 55 additions and 53 deletions
|
@ -258,35 +258,6 @@ angular.module('JamStash')
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$rootScope.addToJukebox = function (id) {
|
|
||||||
if (globals.settings.Debug) { console.log("LOAD JUKEBOX"); }
|
|
||||||
$.ajax({
|
|
||||||
url: globals.BaseURL() + '/jukeboxControl.view?' + globals.BaseParams() + '&action=set&id=' + id,
|
|
||||||
method: 'GET',
|
|
||||||
dataType: globals.settings.Protocol,
|
|
||||||
timeout: globals.settings.Timeout,
|
|
||||||
success: function (data) {
|
|
||||||
/*
|
|
||||||
if (data["subsonic-response"].podcasts.channel !== undefined) {
|
|
||||||
}
|
|
||||||
deferred.resolve(podcasts);
|
|
||||||
*/
|
|
||||||
$.get(globals.BaseURL() + '/jukeboxControl.view?' + globals.BaseParams() + '&action=start');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
$rootScope.sendToJukebox = function (action) {
|
|
||||||
if (globals.settings.Debug) { console.log("SEND JUKEBOX " + action); }
|
|
||||||
$.ajax({
|
|
||||||
url: globals.BaseURL() + '/jukeboxControl.view?' + globals.BaseParams() + '&action=' + action,
|
|
||||||
method: 'GET',
|
|
||||||
dataType: globals.settings.Protocol,
|
|
||||||
timeout: globals.settings.Timeout,
|
|
||||||
success: function (data) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.toggleStar = function (item) {
|
$scope.toggleStar = function (item) {
|
||||||
subsonic.toggleStar(item).then(function (newStarred) {
|
subsonic.toggleStar(item).then(function (newStarred) {
|
||||||
item.starred = newStarred;
|
item.starred = newStarred;
|
||||||
|
|
|
@ -123,7 +123,7 @@ angular.module('jamstash.player.directive', ['jamstash.player.service', 'jamstas
|
||||||
$player.jPlayer('setMedia', media);
|
$player.jPlayer('setMedia', media);
|
||||||
if (globals.settings.Jukebox) {
|
if (globals.settings.Jukebox) {
|
||||||
$player.jPlayer('mute', true);
|
$player.jPlayer('mute', true);
|
||||||
scope.addToJukebox(newSong.id);
|
subsonic.addToJukebox(newSong);
|
||||||
}
|
}
|
||||||
if (playerService.loadSong === true || globals.settings.Jukebox) {
|
if (playerService.loadSong === true || globals.settings.Jukebox) {
|
||||||
// Do not play, only load
|
// Do not play, only load
|
||||||
|
@ -152,10 +152,9 @@ angular.module('jamstash.player.directive', ['jamstash.player.service', 'jamstas
|
||||||
scope.$watch(function () {
|
scope.$watch(function () {
|
||||||
return playerService.pauseSong;
|
return playerService.pauseSong;
|
||||||
}, function (newVal) {
|
}, function (newVal) {
|
||||||
if(newVal === true) {
|
$player.jPlayer(newVal ? 'pause' : 'play');
|
||||||
$player.jPlayer('pause');
|
if(globals.settings.Jukebox){
|
||||||
} else {
|
subsonic.sendToJukebox(newVal ? 'stop' : 'start');
|
||||||
$player.jPlayer('play');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -76,11 +76,12 @@ describe("jplayer directive", function () {
|
||||||
|
|
||||||
it("if the global setting Jukebox is true, it mutes jPlayer and adds the song to subsonic's Jukebox", function () {
|
it("if the global setting Jukebox is true, it mutes jPlayer and adds the song to subsonic's Jukebox", function () {
|
||||||
mockGlobals.settings.Jukebox = true;
|
mockGlobals.settings.Jukebox = true;
|
||||||
scope.addToJukebox = jasmine.createSpy("addToJukebox");
|
spyOn(subsonic, "addToJukebox")
|
||||||
|
|
||||||
scope.$apply();
|
scope.$apply();
|
||||||
expect($player.jPlayer).toHaveBeenCalledWith('mute', true);
|
expect($player.jPlayer).toHaveBeenCalledWith('mute', true);
|
||||||
expect(scope.addToJukebox).toHaveBeenCalledWith(playingSong.id);
|
expect(subsonic.addToJukebox).toHaveBeenCalledWith(
|
||||||
|
jasmine.objectContaining({ id: playingSong.id}))
|
||||||
});
|
});
|
||||||
|
|
||||||
it("if the player service's loadSong flag is true, it does not play the song, it displays the player controls and sets the player to the song's supplied position", function () {
|
it("if the player service's loadSong flag is true, it does not play the song, it displays the player controls and sets the player to the song's supplied position", function () {
|
||||||
|
@ -142,6 +143,7 @@ describe("jplayer directive", function () {
|
||||||
describe("", function () {
|
describe("", function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
$.fn.jPlayer.and.stub();
|
$.fn.jPlayer.and.stub();
|
||||||
|
spyOn(subsonic, "sendToJukebox")
|
||||||
});
|
});
|
||||||
|
|
||||||
it("When the player service's restartSong flag is true, it restarts the current song, resets the restart flag to false and resets the scrobbled flag to false", function () {
|
it("When the player service's restartSong flag is true, it restarts the current song, resets the restart flag to false and resets the scrobbled flag to false", function () {
|
||||||
|
@ -170,6 +172,25 @@ describe("jplayer directive", function () {
|
||||||
expect($player.jPlayer).toHaveBeenCalledWith('play');
|
expect($player.jPlayer).toHaveBeenCalledWith('play');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("When the player service's pauseSong is true and jukebox is enabled, 'stop' is sent to the jukebox", function () {
|
||||||
|
mockGlobals.settings.Jukebox = true;
|
||||||
|
playerService.pauseSong = true;
|
||||||
|
scope.$apply();
|
||||||
|
|
||||||
|
expect(subsonic.sendToJukebox).toHaveBeenCalledWith('stop');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Given that the current song is paused and jukebox is enabled, 'start' is sent to the jukebox when it's unpaused", function () {
|
||||||
|
mockGlobals.settings.Jukebox = true;
|
||||||
|
|
||||||
|
playerService.pauseSong = true;
|
||||||
|
scope.$apply();
|
||||||
|
playerService.pauseSong = false;
|
||||||
|
scope.$apply();
|
||||||
|
|
||||||
|
expect(subsonic.sendToJukebox).toHaveBeenCalledWith('start');
|
||||||
|
});
|
||||||
|
|
||||||
it("When the player service's volume changes, it sets jPlayer's volume", function () {
|
it("When the player service's volume changes, it sets jPlayer's volume", function () {
|
||||||
playerService.getVolume.and.returnValue(0.2034);
|
playerService.getVolume.and.returnValue(0.2034);
|
||||||
scope.$apply();
|
scope.$apply();
|
||||||
|
|
|
@ -15,22 +15,8 @@ angular.module('jamstash.player.controller', ['jamstash.player.service', 'jamsta
|
||||||
$scope.settings = globals.settings;
|
$scope.settings = globals.settings;
|
||||||
$scope.playerSettings = player.settings;
|
$scope.playerSettings = player.settings;
|
||||||
|
|
||||||
$scope.play = function () {
|
$scope.play = player.togglePause;
|
||||||
if (globals.settings.Jukebox) {
|
$scope.pause = player.togglePause;
|
||||||
$scope.sendToJukebox('start');
|
|
||||||
} else {
|
|
||||||
player.togglePause();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.pause = function () {
|
|
||||||
if (globals.settings.Jukebox) {
|
|
||||||
$scope.sendToJukebox('stop');
|
|
||||||
} else {
|
|
||||||
player.togglePause();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.previousTrack = player.previousTrack;
|
$scope.previousTrack = player.previousTrack;
|
||||||
$scope.nextTrack = player.nextTrack;
|
$scope.nextTrack = player.nextTrack;
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -53,7 +53,9 @@ function subsonicService(
|
||||||
scrobble : scrobble,
|
scrobble : scrobble,
|
||||||
search : search,
|
search : search,
|
||||||
subsonicRequest : subsonicRequest,
|
subsonicRequest : subsonicRequest,
|
||||||
toggleStar : toggleStar
|
toggleStar : toggleStar,
|
||||||
|
addToJukebox : addToJukebox,
|
||||||
|
sendToJukebox : sendToJukebox
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: Hyz: Remove when refactored
|
// TODO: Hyz: Remove when refactored
|
||||||
|
@ -570,4 +572,27 @@ function subsonicService(
|
||||||
});
|
});
|
||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addToJukebox(song) {
|
||||||
|
if (globals.settings.Debug) { console.log("Load Jukebox"); }
|
||||||
|
var promise = self.subsonicRequest('jukeboxControl.view', {
|
||||||
|
params: {
|
||||||
|
action: 'set',
|
||||||
|
id: song.id
|
||||||
|
}
|
||||||
|
}).then(function () {
|
||||||
|
self.sendToJukebox('start');
|
||||||
|
});
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendToJukebox(action) {
|
||||||
|
if (globals.settings.Debug) { console.log("Send Jukebox " + action); }
|
||||||
|
var promise = self.subsonicRequest('jukeboxControl.view', {
|
||||||
|
params: {
|
||||||
|
action: action
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue