Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 8a23d282 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

Some other commands

parent 56be3dff
Aucune branche associée trouvée
Aucune étiquette associée trouvée
2 requêtes de fusion!3Dev kubat,!1Create basic lib
......@@ -109,6 +109,41 @@ class LktClient {
};
return __getResult(client);
}
/* Arguments:
* - command: The command to execute
* Result:
* - Returns the status of the command */
static __execSimple(command) {
var client = new this();
var once = false;
var result = {};
function __getResult(client) {
return new Promise(resolv => {
client.m_socket.on("data", (data) => {
if (!once) {
client.m_socket.write(`${command}\n`);
once = true;
return null;
} else {
client.close();
result = __mpdStatusToBool(data);
resolv(result);
}
});
})
};
return __getResult(client);
}
static commandPlay() { return LktClient.__execSimple("play") };
static commandPlay() { return LktClient.__execSimple("stop") };
static commandPrev() { return LktClient.__execSimple("previous") };
static commandNext() { return LktClient.__execSimple("next") };
static commandShuffle() { return LktClient.__execSimple("shuffle") };
static commandQueueAddId(id) { return LktClient.__execSimple(`add id ${id}`); }
static commandQueueDelId(id) { return LktClient.__execSimple(`deleteid ${id}`); }
}
function __mpdToObject(string) {
......@@ -124,4 +159,10 @@ function __mpdToObject(string) {
return ret;
}
function __mpdStatusToBool(string) {
string = string.split("\n");
string = string[string.length - 1];
return string.split(/ /) == "OK" ? true : false;
}
module.exports = LktClient;
......@@ -6,3 +6,9 @@ lkt
.then( (res) => {
console.log(res);
})
lkt
.commandPlay()
.then( (res) => {
console.log(res);
});
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter