mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-12-08 20:48:48 +00:00
Better colorthief handling
- Moved colorthief handling to api, making it easier to controll where the requests comes from
This commit is contained in:
@@ -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});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user