-
Notifications
You must be signed in to change notification settings - Fork 1
/
control.html
383 lines (355 loc) · 13.1 KB
/
control.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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
.status {
padding: 7px 6px;
font-size: 14px;
color: green;
display: inline-block;
text-align: center;
background-color: gray;
border-radius: 5px;
}
hr {
margin: 0 0 8px 0;
}
</style>
</head>
<body>
<div class='panel panel-default display'>
<div class='panel-heading'>
Display placement / orientation
</div>
<div class='panel-body'>
<div class='row'>
<div class='col-md-8'>
<div class='row'>
<div class='col-md-2'>
<label>x1</label>
<input type='number' class='form-control x1'>
</div>
<div class='col-md-2'>
<label>y1</label>
<input type='number' class='form-control y1'>
</div>
<div class='col-md-2'>
<label>x2</label>
<input type='number' class='form-control x2'>
</div>
<div class='col-md-2'>
<label>y2</label>
<input type='number' class='form-control y2'>
</div>
<div class='col-md-4'>
<label>Apply template</label>
<select class="form-control template">
<option value="">Template</option>
<optgroup label="Fullscreen">
<option value='{"x1":0,"y1":0,"x2":100,"y2":100}'>Use full physical resolution</option>
</optgroup>
<optgroup label="Video wall processing">
<option value='{"x1":0,"y1":0,"x2":30,"y2":30}'>Crop top-left 30%</option>
</optgroup>
<optgroup label="Overscan compensation">
<option value='{"x1":2,"y1":2,"x2":98,"y2":98}'>2% overscan</option>
<option value='{"x1":5,"y1":5,"x2":95,"y2":95}'>5% overscan</option>
<option value='{"x1":6,"y1":6,"x2":94,"y2":94}'>6% overscan</option>
<option value='{"x1":10,"y1":10,"x2":90,"y2":90}'>10% overscan</option>
</optgroup>
</select>
</div>
</div>
</div>
<div class='col-md-4'>
<label>Clockwise rotation</label>
<select id='r' class="form-control">
<option value="0">
None
</option>
<option value="90">
90°
</option>
<option value="180">
180°
</option>
<option value="270">
270°
</option>
</select>
</div>
</div>
</div>
</div>
<div class='row'>
<div class='col-md-9' id='wall-config'>
<div class='panel panel-default wall'>
<div class='panel-heading'>
Wall content settings
</div>
<div class='panel-body'>
<div class='row'>
<div class='col-md-2'>
<label>Scaling</label>
<select class="form-control" id='scale_up'>
<option value='stretch'>Stretch</option>
<option value='aspect_up'>Upscale</option>
<option value='aspect_down'>Downscale</option>
</select>
</div>
<div class='col-md-2'>
<label>x1</label>
<input type='number' class='form-control x1'>
</div>
<div class='col-md-2'>
<label>y1</label>
<input type='number' class='form-control y1'>
</div>
<div class='col-md-2'>
<label>x2</label>
<input type='number' class='form-control x2'>
</div>
<div class='col-md-2'>
<label>y2</label>
<input type='number' class='form-control y2'>
</div>
<div class='col-md-2'>
<label>Apply template</label>
<select class="form-control template">
<option value="">Template</option>
<optgroup label="Single screen">
<option value='{"x1":0,"y1":0,"x2":100,"y2":100}'>Single display</option>
</optgroup>
<optgroup label="Two screen layouts">
<option value='{"x1":0,"y1":0,"x2":200,"y2":100}'>Left of two horizontal displays</option>
<option value='{"x1":-100,"y1":0,"x2":100,"y2":100}'>Right of two horizontal displays</option>
<option value='{"x1":0,"y1":0,"x2":100,"y2":200}'>Top of two vertical displays</option>
<option value='{"x1":0,"y1":-100,"x2":100,"y2":100}'>Bottom of two vertical displays</option>
</optgroup>
<optgroup label="2x2 Wall">
<option value='{"x1":0,"y1":0,"x2":200,"y2":200}'>Top left of 2x2 displays</option>
<option value='{"x1":-100,"y1":0,"x2":100,"y2":200}'>Top right of 2x2 displays</option>
<option value='{"x1":0,"y1":-100,"x2":200,"y2":100}'>Bottom left of 2x2 displays</option>
<option value='{"x1":-100,"y1":-100,"x2":100,"y2":100}'>Bottom right of 2x2 displays</option>
</optgroup>
</select>
</div>
</div>
</div>
</div>
</div>
<div class='col-md-3' id='fullscreen-config'>
<div class='panel panel-default'>
<div class='panel-heading'>
Fullscreen content settings
</div>
<div class='panel-body'>
<label>Preferred alternative (if available)</label>
<select id='alt' class="form-control">
<option value="default">None (play default content)</option>
<option value="1">Play alternative 1</option>
<option value="2">Play alternative 2</option>
<option value="3">Play alternative 3</option>
<option value="4">Play alternative 4</option>
<option value="5">Play alternative 5</option>
<option value="6">Play alternative 6</option>
<option value="7">Play alternative 7</option>
<option value="8">Play alternative 8</option>
</select>
</div>
</div>
</div>
</div>
<div class='row'>
<div class='col-md-4'>
<label>Synchronization status</label>
<div>
<div class='status' id='status'>Loading..</div>
<button class='btn btn-default' id='leader'>Loading..</button>
</div>
</div>
<div class='col-md-3 col-md-offset-1'>
<label>Debugging overlay</label>
<div>
<div class="btn-group">
<button id='debug-on' class='btn btn-default'>Show for 3 minutes</button>
<button id='debug-off' class='btn btn-default'>Hide</button>
</div>
</div>
</div>
<div class='col-md-4'>
<label> </label>
<div class='text-right'>
<div class="btn-group">
<button id='wipe' class='btn btn-default'>Reset to default</button>
<button id='save' class='btn btn-primary'>Save device customizations</button>
</div>
</div>
</div>
</div>
<div class='popup'></div>
<!-- Provides the interface to info-beamer hosted -->
<script src="hosted.js"></script>
<script>
"strict";
ib.setDefaultStyle()
function int_from_str(s) {
let i = parseInt(s)
if (isNaN(i)) {
throw `Invalid value '${s}'`
}
return i
}
function QuadEntry(base_e, source_obj) {
let e_x1 = base_e.querySelector('.x1'),
e_y1 = base_e.querySelector('.y1'),
e_x2 = base_e.querySelector('.x2'),
e_y2 = base_e.querySelector('.y2'),
e_tmpl = base_e.querySelector('.template')
e_x1.value = source_obj.x1 || 0
e_y1.value = source_obj.y1 || 0
e_x2.value = source_obj.x2 || 100
e_y2.value = source_obj.y2 || 100
let update = (x1, y1, x2, y2) => {
e_x1.value = x1
e_y1.value = y1
e_x2.value = x2
e_y2.value = y2
}
let reset = () => update(0, 0, 100, 100)
let as_obj = () => {
let obj = {
x1: int_from_str(e_x1.value),
y1: int_from_str(e_y1.value),
x2: int_from_str(e_x2.value),
y2: int_from_str(e_y2.value),
}
if (obj.x2 <= obj.x1) {
throw 'Invalid horizontal values: Negative or zero'
}
if (obj.y2 <= obj.y1) {
throw 'Invalid vertical values: Negative or zero'
}
return obj
}
e_tmpl && e_tmpl.addEventListener('change', e => {
let x1, y1, x2, y2
let tmpl = e.target.value
let selected_layout = e.target.options[e.target.selectedIndex].innerText
if (tmpl == '')
return
let pos = JSON.parse(tmpl)
update(pos.x1, pos.y1, pos.x2, pos.y2)
e_tmpl.value = ''
ib.notification.success(`Applied layout template: ${selected_layout}`)
})
return {update, reset, as_obj}
}
let e_r = document.getElementById('r'),
e_scale_up = document.getElementById('scale_up'),
e_alt = document.getElementById('alt'),
e_save = document.getElementById('save'),
e_wipe = document.getElementById('wipe'),
e_status = document.getElementById('status'),
e_leader = document.getElementById('leader'),
e_dbg_on = document.getElementById('debug-on'),
e_dbg_off = document.getElementById('debug-off')
let leader_id = null
async function update() {
let kv = await ib.device_kv([
'all_synced',
'is_leader',
'peers',
'leader_id',
])
let is_leader = kv.is_leader == '1'
let all_synced = kv.all_synced == '1'
let num_peers = parseInt(kv.peers) || 0
e_status.style.backgroundColor = '#90ee90'
e_status.innerText = `${num_peers} peers`
if (is_leader) {
e_leader.disabled = 'disable'
e_leader.innerText = "This is the leader device"
leader_id = null
} else {
e_leader.disabled = ''
e_leader.innerText = `Go to leader device ${kv.leader_id}..`
leader_id = kv.leader_id
}
}
function has_fullscreen_content(playlist) {
for (let item of playlist) {
if (Number.isInteger(item)) // playlist
return true
if (item.slot_type == "fullscreen")
return true
}
return false
}
function has_wall_content(playlist) {
for (let item of playlist) {
if (Number.isInteger(item)) // playlist
continue
if (item.slot_type == "wall")
return true
}
return false
}
ib.ready.then(async () => {
if (!has_fullscreen_content(ib.config.playlist)) {
document.getElementById('fullscreen-config').style.opacity = 0.5;
}
if (!has_wall_content(ib.config.playlist)) {
document.getElementById('wall-config').style.opacity = 0.5;
}
update()
setInterval(update, 5000)
let dd = await ib.device_data()
let wall_pos = QuadEntry(document.querySelector(".wall"), dd.wall || {})
let display_pos = QuadEntry(document.querySelector(".display"), dd.display || {})
e_r.value = dd.rotation || 0
e_scale_up.value = dd.wall && dd.wall.scale_up || 'stretch'
e_alt.value = dd.alternative_idx || 'default'
e_leader.addEventListener('click', e => {
if (leader_id != null) {
ib.open.device(leader_id)
}
})
e_dbg_on.addEventListener('click', e => {
ib.node_command("debug/show", 180)
})
e_dbg_off.addEventListener('click', e => {
ib.node_command("debug/show", 0)
})
e_wipe.addEventListener('click', e => {
wall_pos.reset()
display_pos.reset()
e_r.value = 0
e_scale_up.value = 'stretch'
e_alt.value = 'default'
})
e_save.addEventListener('click', async e => {
try {
let dd = {
wall: {
...wall_pos.as_obj(),
scale_up: e_scale_up.value,
},
display: display_pos.as_obj(),
rotation: int_from_str(e_r.value),
}
if (e_alt.value != "default") {
dd.alternative_idx = parseInt(e_alt.value)
}
await ib.device_data(dd)
ib.notification.success("Saved. Changes will be applied to the device now.")
} catch (ex) {
ib.notification.error(`Cannot set device data: ${ex}`)
}
})
})
</script>
</script>
</body>
</html>