Skip to content

Commit 7d9ae95

Browse files
author
Joonas Haaparanta
committed
Silence screen
1 parent 1ee3b6e commit 7d9ae95

File tree

6 files changed

+230
-220
lines changed

6 files changed

+230
-220
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
run.sh
2+
13
# Logs
24
logs
35
*.log

main.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ app.get("/giphy/", async (req, res) => {
2222
res.send(`sent ${str} -> ${image}`);
2323
});
2424

25-
app.get("/", (_, res) => res.sendFile(path.join(__dirname, "index.html")));
25+
app.use("/", express.static("public"));
2626

2727
const getTrack = async () => {
2828
try {
2929
const track = await device.currentTrack();
3030

31-
if (track.uri.includes("spotify")) {
31+
if (track.uri && track.uri.includes("spotify")) {
3232
return {
3333
...track,
3434
dj: " Null ",

public/.gitignore

Whitespace-only changes.

index.html renamed to public/index.html

+54-218
Original file line numberDiff line numberDiff line change
@@ -8,185 +8,20 @@
88
href="https://fonts.googleapis.com/css?family=Fira+Mono"
99
rel="stylesheet"
1010
/>
11+
<link rel="stylesheet" href="./main.css" />
1112
<title>Musacorneri</title>
12-
<style>
13-
html,
14-
body {
15-
margin: 0;
16-
padding: 0;
17-
font-family: "Fira Mono", monospace;
18-
}
19-
20-
body {
21-
display: flex;
22-
flex-direction: column;
23-
align-items: center;
24-
height: 100vh;
25-
background: black;
26-
overflow: hidden;
27-
cursor: none;
28-
}
29-
30-
h1 {
31-
width: 100%;
32-
padding: 30px;
33-
margin: 0;
34-
text-align: center;
35-
/* background: #292929; */
36-
background: rgba(0, 0, 0, 0.5);
37-
color: #1ed760;
38-
font-size: 90px;
39-
text-transform: uppercase;
40-
}
41-
42-
.trackinfo {
43-
display: flex;
44-
flex-direction: column;
45-
width: 100%;
46-
flex: 1;
47-
justify-content: center;
48-
align-items: center;
49-
color: white;
50-
}
51-
52-
.artist {
53-
/* margin-top: 20px; */
54-
font-size: 56px;
55-
}
56-
57-
.track {
58-
font-size: 36px;
59-
margin-bottom: 20px;
60-
}
61-
62-
.albumart {
63-
height: 500px;
64-
width: 500px;
65-
border: 15px solid #292929;
66-
}
67-
68-
.timebar {
69-
width: 500px;
70-
margin-left: 10px;
71-
margin-right: 10px;
72-
height: 10px;
73-
background: #999;
74-
border-radius: 5px;
75-
overflow: hidden;
76-
}
77-
78-
.timehead {
79-
width: 0%;
80-
height: 10px;
81-
background: #1ed760;
82-
}
83-
84-
.timeContainer {
85-
display: flex;
86-
align-items: center;
87-
}
88-
89-
.dj {
90-
text-align: right;
91-
align-self: flex-end;
92-
color: #777777;
93-
padding: 5px 15px;
94-
}
95-
96-
.party {
97-
background: rgb(224, 9, 189);
98-
background: linear-gradient(
99-
45deg,
100-
rgba(224, 9, 189, 1) 0%,
101-
rgba(0, 212, 255, 1) 100%
102-
);
103-
}
104-
105-
.parrot {
106-
height: 60px;
107-
}
108-
109-
.eqcontainer {
110-
position: absolute;
111-
top: 30%;
112-
bottom: 0;
113-
left: 0;
114-
right: 0;
115-
z-index: -1;
116-
opacity: .7;
117-
}
118-
119-
svg {
120-
display: block;
121-
width: 100%;
122-
height: 100%;
123-
padding: 0;
124-
margin: 0;
125-
position: absolute;
126-
}
127-
128-
path {
129-
stroke-linecap: square;
130-
stroke: white;
131-
stroke-width: 0.5px;
132-
}
133-
134-
.bgBlurri {
135-
position: absolute;
136-
top: -480px;
137-
bottom: 0;
138-
left: 0;
139-
right: 0;
140-
width: 100%;
141-
height: auto;
142-
opacity: 0.9;
143-
border: none;
144-
filter: blur(20px);
145-
z-index: 0;
146-
}
147-
148-
.c {
149-
z-index: 1;
150-
position: absolute;
151-
top: 0;
152-
left: 0;
153-
right: 0;
154-
bottom: 0;
155-
156-
display: flex;
157-
flex-direction: column;
158-
}
159-
160-
.juttu {
161-
position: fixed;
162-
bottom: 0;
163-
background: rgba(0,0,0,.5);
164-
left: 0;
165-
right: 0;
166-
display: flex;
167-
flex-direction: inherit;
168-
align-items: center;
169-
padding: 20px;
170-
}
171-
172-
.beercontainer {
173-
color: white;
174-
font-size: 40px;
175-
padding-top: 20px;
176-
text-align: center;
177-
}
178-
179-
180-
</style>
18113
</head>
18214

18315
<body>
18416
<div class="c">
185-
<div class="beercontainer">
186-
Kaljat ~<span id="beertemp" />
187-
</div>
17+
<div class="beercontainer">Kaljat ~<span id="beertemp" /></div>
18+
<div class="silence" style="display: none;">🙉</div>
18819
<div class="trackinfo">
189-
<img class="albumart" src="https://giphy.com/embed/5nsiFjdgylfK3csZ5T" alt="" />
20+
<img
21+
class="albumart"
22+
src="https://giphy.com/embed/5nsiFjdgylfK3csZ5T"
23+
alt=""
24+
/>
19025
<div class="juttu">
19126
<div class="artist"></div>
19227
<div class="track"></div>
@@ -198,7 +33,6 @@
19833
</div>
19934
</div>
20035
</div>
201-
20236
</div>
20337
<!-- EQ no work with raspberry... -->
20438
<div class="eqcontainer">
@@ -234,6 +68,8 @@
23468

23569
<script>
23670
const e = {
71+
trackinfo: document.querySelector(".trackinfo"),
72+
silence: document.querySelector(".silence"),
23773
track: document.querySelector(".track"),
23874
artist: document.querySelector(".artist"),
23975
albumart: document.querySelectorAll(".albumart"),
@@ -245,50 +81,45 @@
24581
beertemp: document.querySelector("#beertemp")
24682
};
24783

248-
async function getBeerTemp(){
249-
const res = await fetch("https://zclvxxpogl.execute-api.eu-west-1.amazonaws.com/dev/isbeercold");
250-
const json = await res.json();
84+
async function getBeerTemp() {
85+
const res = await fetch(
86+
"https://zclvxxpogl.execute-api.eu-west-1.amazonaws.com/dev/isbeercold"
87+
);
88+
const json = await res.json();
25189

252-
e.beertemp.innerHTML = json.values[json.values.length -1] + " °C"
90+
e.beertemp.innerHTML = json.values[json.values.length - 1] + " °C";
25391

254-
json.values[json.values.length - 1]
255-
92+
json.values[json.values.length - 1];
25693
}
25794

25895
getBeerTemp();
25996
setInterval(async () => {
26097
getBeerTemp();
261-
}, 1000 * 60)
98+
}, 1000 * 60);
26299

263100
const socket = io();
264101

102+
socket.on("show-image", function({ image, text }) {
103+
if (!image) return;
265104

266-
267-
socket.on("show-image", function({image, text}){
268-
if(!image) return;
269-
270-
console.log("got image", {image, text});
271-
272-
const ifrm = document.createElement("iframe");
105+
const ifrm = document.createElement("iframe");
273106
ifrm.setAttribute("src", image);
274107
ifrm.setAttribute("id", "giphy");
275108

276109
const dim = Math.min(window.innerHeight, window.innerWidth) - 200;
277110

278111
ifrm.style.width = `${dim}px`;
279112
ifrm.style.height = `${dim}px`;
280-
281113

282-
ifrm.style.zIndex = 100
114+
ifrm.style.zIndex = 100;
283115
ifrm.style.border = "none";
284-
ifrm.style.margin = "auto"
285-
286-
ifrm.style.bottom = 0
287-
ifrm.style.top = 0
288-
ifrm.style.left = 0
289-
ifrm.style.right = 0
290-
291-
116+
ifrm.style.margin = "auto";
117+
118+
ifrm.style.bottom = 0;
119+
ifrm.style.top = 0;
120+
ifrm.style.left = 0;
121+
ifrm.style.right = 0;
122+
292123
const gText = document.createElement("div");
293124
gText.setAttribute("id", "gText");
294125
gText.innerText = text;
@@ -297,24 +128,19 @@
297128
gText.style.background = "black";
298129
gText.style.fontSize = "100px";
299130
gText.style.zIndex = 101;
300-
gText.style.padding = "40px"
131+
gText.style.padding = "40px";
301132

302-
303-
document.body.appendChild(gText)
304-
document.body.appendChild(ifrm)
133+
document.body.appendChild(gText);
134+
document.body.appendChild(ifrm);
305135

306136
setTimeout(() => {
307-
308-
document.body.removeChild(document.getElementById("giphy"))
309-
document.body.removeChild(document.getElementById("gText"))
310-
}, 10000)
311-
312-
})
313-
314-
137+
document.body.removeChild(document.getElementById("giphy"));
138+
document.body.removeChild(document.getElementById("gText"));
139+
}, 10000);
140+
});
315141

316142
socket.on("track-update", function(track) {
317-
updateTrackData(e, track);
143+
updateTrackData(e, track);
318144
});
319145

320146
function secondsToTime(s) {
@@ -342,7 +168,18 @@
342168
const parrot = `<img class="parrot" src="https://cultofthepartyparrot.com/parrots/parrot.gif" />`;
343169

344170
function updateTrackData(e, track) {
345-
if (currentUri !== track.uri || currentTitle !== track.title) {
171+
if (track.position === null && track.duration === null) {
172+
// Undefined track!
173+
174+
e.trackinfo.style.display = "none";
175+
e.silence.style.display = "flex";
176+
177+
e.albumart.forEach(x => {
178+
x.src = "/jungle.jpg";
179+
});
180+
} else if (currentUri !== track.uri || currentTitle !== track.title) {
181+
e.trackinfo.style.display = "flex";
182+
e.silence.style.display = "none";
346183
currentUri = track.uri;
347184
currentTitle = track.title;
348185
e.track.innerHTML = track.title;
@@ -351,7 +188,6 @@
351188
x.src = track.albumArtURL;
352189
});
353190
e.totalTime.innerHTML = secondsToTime(track.duration);
354-
355191

356192
// Friday
357193
if (track.isFridaySong) {
@@ -377,7 +213,6 @@
377213
var report = 0;
378214

379215
var soundAllowed = function(stream) {
380-
console.log("Sound");
381216
//Audio stops listening in FF without // window.persistAudioStream = stream;
382217
//https://bugzilla.mozilla.org/show_bug.cgi?id=965483
383218
//https://support.mozilla.org/en-US/questions/984179
@@ -422,10 +257,11 @@
422257
h.innerHTML = "You must allow your microphone.";
423258
console.log(error);
424259
};
425-
navigator.getUserMedia = ( navigator.getUserMedia ||
426-
navigator.webkitGetUserMedia ||
427-
navigator.mozGetUserMedia ||
428-
navigator.msGetUserMedia);
260+
navigator.getUserMedia =
261+
navigator.getUserMedia ||
262+
navigator.webkitGetUserMedia ||
263+
navigator.mozGetUserMedia ||
264+
navigator.msGetUserMedia;
429265

430266
navigator.getUserMedia({ audio: true }, soundAllowed, soundNotAllowed);
431267
};

public/jungle.jpg

5.82 MB
Loading

0 commit comments

Comments
 (0)