-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.html
284 lines (261 loc) · 8.66 KB
/
client.html
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Cyberscreen Client</title>
<style>
/* Fullscreen Video */
html,
body {
height: 100%;
margin: 0;
padding: 0;
background-color: black;
}
div {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
position: relative;
}
video,
img {
position: absolute;
width: 100%;
height: 100%;
object-fit: cover;
aspect-ratio: 16 / 9;
}
video {
z-index: 1;
}
/* Ignore overflow */
body {
overflow: hidden;
}
/* Button styles from server.html */
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700&display=swap');
#startButton {
position: absolute;
z-index: 3;
background-color: transparent;
color: black;
border: 3px solid #00ff00; /* Increased border size */
border-radius: 5px;
padding: 25px; /* Increased padding */
font-size: 24px; /* Increased font size */
font-family: 'Orbitron', sans-serif;
cursor: pointer;
transition: all 0.3s;
text-shadow: 0 0 5px #00ff00;
background-color: #00ff00;
box-shadow: 0 0 15px rgba(0, 255, 0, 0.5);
}
#startButton:hover {
background-color: rgba(0, 255, 0, 0.5);
box-shadow: 0 0 15px rgba(0, 255, 0, 0.75);
}
#startButton:active {
transform: scale(0.95);
background-color: rgba(0, 255, 0, 0.5);
}
</style>
</head>
<body>
<div>
<video id="liveVideo" autoplay muted></video>
<video id="clipVideo" autoplay muted></video>
<img src="/files/imgs/Static.png" alt="Static" id="img" />
<!-- Button for user interaction -->
<button id="startButton">Click to Start</button>
</div>
<script src="socket.io.js"></script>
<script>
const socket = io(
location.protocol + '//' + document.domain + ':' + location.port
)
let clips = []
let userHasInteracted = false
let clipsActive = false // Track whether the "Clips" case is active
document
.getElementById('startButton')
.addEventListener('click', function () {
userHasInteracted = true
this.style.display = 'none' // Hide the button after interaction
})
socket.on('connect', () => {
console.log('connected')
// Fetch clip list
})
// get website hash
const hash = window.location.hash.substr(1)
if (hash && (hash === 'mute' || hash === 'muted')) {
document.getElementById('liveVideo').muted = true
document.getElementById('clipVideo').muted = true
// Set volume to 0 for all videos
document.getElementById('liveVideo').volume = 0
document.getElementById('clipVideo').volume = 0
}
socket.on('status', (status) => {
if (!userHasInteracted) {
console.warn(
'User interaction required before status update handling'
)
return
}
console.log('status: ' + status)
const liveVideo = document.getElementById('liveVideo')
const clipVideo = document.getElementById('clipVideo')
const img = document.getElementById('img')
img.src = '/files/imgs/Static.png'
switch (status) {
case 'Clips':
clipsActive = true
img.style['z-index'] = -1
liveVideo.style['z-index'] = -1
clipVideo.style['z-index'] = 2
// play random clip
playClip(0)
break
case 'Live':
clipsActive = false
liveVideo.style['z-index'] = 2
clipVideo.style['z-index'] = -1
img.style['z-index'] = -1
startLiveStream()
break
case 'Sewer':
clipsActive = false
liveVideo.pause()
clipVideo.pause()
img.style['z-index'] = 2
img.src = '/files/imgs/sewer.webp'
break
case 'Sunset':
clipsActive = false
liveVideo.pause()
clipVideo.pause()
img.style['z-index'] = 2
img.src = '/files/imgs/sunset.webp'
break
case 'Stopped':
clipsActive = false
liveVideo.pause()
clipVideo.pause()
img.style['z-index'] = 2
break
case 'AI':
clipsActive = false
liveVideo.pause()
clipVideo.pause()
img.style['z-index'] = 2
img.src = '/files/imgs/AI.png'
break
default:
clipsActive = false
if (status.startsWith('AI')) {
liveVideo.pause()
clipVideo.pause()
img.style['z-index'] = -1
clipVideo.style['z-index'] = 2
liveVideo.style['z-index'] = -1
clipVideo.src = '/files/takes/' + status + '.mp4'
clipVideo.muted = false // Ensure sound is on for 'takes' folder videos
clipVideo.play()
const louisBG = ['AI23_5', 'AI23_6', 'AI23_7']
// onend switch
clipVideo.addEventListener('ended', () => {
img.style['z-index'] = 2
clipVideo.style['z-index'] = -1
img.src = louisBG.includes(status)
? '/files/imgs/louis.jpg'
: '/files/imgs/AI.png'
if (status === 'AI23_7') {
img.src = '/files/imgs/Static.png'
}
}) // Ensure the event listener is removed after execution
} else {
// Einspieler
liveVideo.pause()
clipVideo.pause()
img.style['z-index'] = -1
clipVideo.style['z-index'] = 2
liveVideo.style['z-index'] = -1
clipVideo.src = '/files/takes/' + status + '.mp4'
clipVideo.muted = false // Ensure sound is on for 'takes' folder videos
clipVideo.play()
// onend switch to static
clipVideo.addEventListener('ended', () => {
img.style['z-index'] = 2
clipVideo.style['z-index'] = -1
img.src = '/files/imgs/Static.png'
})
}
}
})
socket.on('disconnect', () => {
console.log('disconnected')
})
fetch('files/clips')
.then((res) => {
return res.json()
})
.then((data) => {
data = data.filter((clip) => !clip.includes('filter_'))
clips = data.sort(() => Math.random() - 0.5)
console.log(clips)
})
function playClip(i) {
if (!clipsActive) return // Exit if "Clips" is not active
if (clips.length === 0) {
setTimeout(() => {
console.log('No clips found, retrying in 1s')
playClip(i)
}, 1000)
return
} else {
const clip = clips[i % clips.length]
const clipVideo = document.getElementById('clipVideo')
const img = document.getElementById('img')
// Play the clip
clipVideo.src = 'files/clip/' + clip
clipVideo.muted = true // Ensure advertisement clips are muted
clipVideo.style['z-index'] = 2
img.style['z-index'] = -1
clipVideo.play()
clipVideo.addEventListener(
'ended',
function handleEnded() {
// Exit if "Clips" is not active
if (!clipsActive) return
// After the clip ends, show the static image for 5 seconds
clipVideo.style['z-index'] = -1
img.style['z-index'] = 2
img.src = '/files/imgs/Static.png'
setTimeout(() => {
// After 5 seconds, play the next ad clip
playClip(i + 1)
}, 5000) // 5000 milliseconds = 5 seconds
},
{ once: true } // Ensures the event listener is removed after execution
)
}
}
function startLiveStream() {
const liveVideo = document.getElementById('liveVideo')
navigator.mediaDevices
.getUserMedia({ video: true })
.then((stream) => {
liveVideo.srcObject = stream
liveVideo.play()
})
.catch((err) => {
console.error('Error accessing live webcam: ', err)
})
}
</script>
</body>
</html>