Added support for multi single command handler and implemented the new music song list method

canary
WolverinDEV 2020-04-04 12:03:48 +02:00
parent 15bacdc9d6
commit 67d1c909ac
4 changed files with 42 additions and 25 deletions

View File

@ -497,7 +497,7 @@ namespace server {
let php: string;
let options: Options;
const use_https = true;
const use_https = false;
export async function launch(_files: ProjectResource[], options_: Options) {
options = options_;
files = _files;

View File

@ -58,6 +58,8 @@ export abstract class AbstractCommandHandlerBoss {
register_single_handler(handler: SingleCommandHandler) {
if(typeof handler.command === "string")
handler.command = [handler.command];
this.single_command_handler.push(handler);
}
@ -82,7 +84,8 @@ export abstract class AbstractCommandHandlerBoss {
}
for(const handler of [...this.single_command_handler]) {
if(handler.command && handler.command != command.command)
// We already know that handler.command must be an array (It will be converted within the register single handler methode)
if(handler.command && (handler.command as string[]).findIndex(e => e === command.command) == -1)
continue;
try {

View File

@ -263,39 +263,53 @@ export class CommandHelper extends AbstractCommandHandler {
}
request_playlist_songs(playlist_id: number) : Promise<PlaylistSong[]> {
//FIXME: notifyplaylistsonglistfinish for the result!
let bulked_response = false;
let bulk_index = 0;
const result: PlaylistSong[] = [];
return new Promise((resolve, reject) => {
const single_handler: SingleCommandHandler = {
command: "notifyplaylistsonglist",
command: ["notifyplaylistsonglist", "notifyplaylistsonglistfinished"],
function: command => {
const json = command.arguments;
if(json[0]["playlist_id"] != playlist_id) {
log.error(LogCategory.NETWORKING, tr("Received invalid notification for playlist songs"));
return false;
if(bulk_index === 0) {
/* we're sending the response as bulk */
bulked_response = parseInt(json[0]["version"]) >= 2;
}
const result: PlaylistSong[] = [];
if(parseInt(json[0]["playlist_id"]) !== playlist_id)
return false; /* not our request */
for(const entry of json) {
try {
result.push({
song_id: parseInt(entry["song_id"]),
song_invoker: entry["song_invoker"],
song_previous_song_id: parseInt(entry["song_previous_song_id"]),
song_url: entry["song_url"],
song_url_loader: entry["song_url_loader"],
if(command.command === "notifyplaylistsonglistfinished") {
resolve(result);
return true;
} else {
for(const entry of json) {
try {
result.push({
song_id: parseInt(entry["song_id"]),
song_invoker: entry["song_invoker"],
song_previous_song_id: parseInt(entry["song_previous_song_id"]),
song_url: entry["song_url"],
song_url_loader: entry["song_url_loader"],
song_loaded: entry["song_loaded"] == true || entry["song_loaded"] == "1",
song_metadata: entry["song_metadata"]
});
} catch(error) {
log.error(LogCategory.NETWORKING, tr("Failed to parse playlist song entry: %o"), error);
song_loaded: entry["song_loaded"] == true || entry["song_loaded"] == "1",
song_metadata: entry["song_metadata"]
});
} catch(error) {
log.error(LogCategory.NETWORKING, tr("Failed to parse playlist song entry: %o"), error);
}
}
if(bulked_response) {
bulk_index++;
return false;
} else {
resolve(result);
return true;
}
}
resolve(result);
return true;
}
};
this.handler_boss.register_single_handler(single_handler);

View File

@ -121,7 +121,7 @@ export class ServerCommand {
export interface SingleCommandHandler {
name?: string;
command?: string;
command?: string | string[];
timeout?: number;
/* if the return is true then the command handler will be removed */