-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
66 lines (54 loc) · 1.48 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require("dotenv").config();
const { Sonos } = require("sonos");
const express = require("express");
const path = require("path");
const app = express();
var http = require("http").Server(app);
const io = require("socket.io")(http);
const ip = process.env.SONOS_IP;
console.log("Use sonos IP ", ip);
const device = new Sonos(ip);
const getImage = require("./getImage");
app.get("/giphy/", async (req, res) => {
const str = req.query.s;
const image = await getImage(str);
io.emit("show-image", { image, text: str });
res.send(`sent ${str} -> ${image}`);
});
app.use("/", express.static("public"));
const getTrack = async () => {
try {
const track = await device.currentTrack();
if (track.uri && track.uri.includes("spotify")) {
return {
...track,
dj: " Null ",
isFridaySong: false
};
}
// "x-sonos-vli:RINCON_949F3E50938801400:1,airplay:d9d8916f85d85c6408e4fc55a78af190"
if (track.uri && track.uri.includes("airplay")) {
return {
...track,
dj: " Null ",
isFridaySong: false,
airplay: "Kirill"
};
}
return {
...track,
dj: "....",
isFridaySong: false
};
} catch (error) {
console.error("Error getting track ", error);
}
};
io.on("connection", function(socket) {
console.info("a user connected");
});
setInterval(async () => {
const t = await getTrack();
io.emit("track-update", t);
}, 1000);
http.listen(3000, () => console.log("listening on port 3000!"));