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 php: string;
let options: Options; let options: Options;
const use_https = true; const use_https = false;
export async function launch(_files: ProjectResource[], options_: Options) { export async function launch(_files: ProjectResource[], options_: Options) {
options = options_; options = options_;
files = _files; files = _files;

View File

@ -58,6 +58,8 @@ export abstract class AbstractCommandHandlerBoss {
register_single_handler(handler: SingleCommandHandler) { register_single_handler(handler: SingleCommandHandler) {
if(typeof handler.command === "string")
handler.command = [handler.command];
this.single_command_handler.push(handler); this.single_command_handler.push(handler);
} }
@ -82,7 +84,8 @@ export abstract class AbstractCommandHandlerBoss {
} }
for(const handler of [...this.single_command_handler]) { 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; continue;
try { try {

View File

@ -263,20 +263,28 @@ export class CommandHelper extends AbstractCommandHandler {
} }
request_playlist_songs(playlist_id: number) : Promise<PlaylistSong[]> { 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) => { return new Promise((resolve, reject) => {
const single_handler: SingleCommandHandler = { const single_handler: SingleCommandHandler = {
command: "notifyplaylistsonglist", command: ["notifyplaylistsonglist", "notifyplaylistsonglistfinished"],
function: command => { function: command => {
const json = command.arguments; const json = command.arguments;
if(json[0]["playlist_id"] != playlist_id) { if(bulk_index === 0) {
log.error(LogCategory.NETWORKING, tr("Received invalid notification for playlist songs")); /* we're sending the response as bulk */
return false; bulked_response = parseInt(json[0]["version"]) >= 2;
} }
const result: PlaylistSong[] = []; if(parseInt(json[0]["playlist_id"]) !== playlist_id)
return false; /* not our request */
if(command.command === "notifyplaylistsonglistfinished") {
resolve(result);
return true;
} else {
for(const entry of json) { for(const entry of json) {
try { try {
result.push({ result.push({
@ -294,9 +302,15 @@ export class CommandHelper extends AbstractCommandHandler {
} }
} }
if(bulked_response) {
bulk_index++;
return false;
} else {
resolve(result); resolve(result);
return true; return true;
} }
}
}
}; };
this.handler_boss.register_single_handler(single_handler); this.handler_boss.register_single_handler(single_handler);

View File

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