Better colorthief handling

- Moved colorthief handling to api, making it easier to controll where the requests comes from
This commit is contained in:
Kasper Rynning-Tønnesen
2018-04-03 16:40:34 +02:00
parent 02667f4348
commit 72f204825e
6 changed files with 46 additions and 14 deletions

View File

@@ -633,7 +633,7 @@ function send_play(coll, socket, broadcast) {
});
}
function sendColor(coll, socket, id) {
function sendColor(coll, socket, id, ajax, res) {
if(coll != undefined && typeof(coll) == "string") {
coll = coll.replace(/ /g,'');
}
@@ -641,10 +641,16 @@ function sendColor(coll, socket, id) {
Jimp.read(url).then(function (image) {
var c = ColorThief.getColor(image);
if(socket) {
socket.emit("color", {color: c, only: true});
if(ajax) {
res.header({"Content-Type": "application/json"});
res.status(200).send(c);
return;
} else {
io.to(coll).emit("color", {color: c, only: false});
if(socket) {
socket.emit("color", {color: c, only: true});
} else {
io.to(coll).emit("color", {color: c, only: false});
}
}
});
}