forked from srobo/srcomp-screens
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharena.html
117 lines (100 loc) · 4.49 KB
/
arena.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>SR Arena Screen</title>
<script src="bower_components/webcomponentsjs/webcomponents.js"></script>
<link rel="import" href="components/sr-comp/component.html" />
<link rel="import" href="components/sr-corner-clock/component.html" />
<link rel="import" href="components/sr-arena/component.html" />
<link rel="import" href="components/sr-arena-picker/component.html" />
<style>
body {
position: fixed;
width: 100%;
height: 100%;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: 0;
padding: 0;
font-family: 'Open Sans', sans-serif;
background: black;
color: white;
font-size: 85%;
}
#arena {
width: 100%;
height: 100%;
overflow: auto;
}
</style>
</head>
<body>
<sr-comp id="comp">
<sr-corner-clock id="error-clock"></sr-corner-clock>
</sr-comp>
<sr-arena-picker id="picker" hidden includecorners="true"></sr-arena-picker>
<sr-arena id="arena" hidden></sr-arena>
<script>
var parseArguments = function() {
var fragment = window.location.search;
var tokens = fragment.substr(1).split(',');
return {arena: tokens[0], corner: tokens[1]};
};
var setUpNormal = function(args, comp, numCorners) {
var arena = document.querySelector('#arena');
var errorClock = document.querySelector('#error-clock');
arena.showOtherCorners = numCorners == 4;
arena.hidden = false;
arena.arena = args.arena;
arena.maincorner = args.corner;
arena.comp = comp;
arena.$.corner0.addEventListener('match', function(e) {
errorClock.match = e.detail;
});
};
document.addEventListener('sr-ready', function() {
var args = parseArguments();
var comp = document.querySelector('#comp');
if (args.arena == null || args.corner == null) {
var picker = document.querySelector('#picker');
picker.hidden = false;
picker.comp = comp;
comp.stream.load();
} else {
comp.api.getArena(args.arena, function(compArena) {
comp.api.getCorners(function(compCorners) {
if (compArena && compCorners[args.corner]) {
var numCorners = Object.keys(compCorners).length;
setUpNormal(args, comp, numCorners);
} else {
var picker = document.querySelector('#picker');
picker.hidden = false;
picker.comp = comp;
}
/* Work around an issue with Firefox. When the
arena fields above are set, the changed callback
should get called immediately giving time for
listeners to be registered on the stream before
it is loaded below. However, in Firefox, the
changed callbacks happen *after* this call
below. Therefore, we wrap it in a 'setTimeout'
to ensure it happens in the next tick, after
the changed callbacks.
Rather concerningly, using a value of 0ms in the
'setTimeout' doesn't solve the problem.
Therefore the 500ms as it is currently might
have to be increased for the Raspberry Pis which
have a lower processing speed than my laptop. */
setTimeout(function() {
comp.stream.load();
}, 500);
});
});
}
});
</script>
</body>
</html>