-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
148 lines (133 loc) · 4.18 KB
/
index.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
<html>
<head>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0" />
<title>ChappieCast</title>
<style>
body {
padding: 0;
margin:0;
}
#frame {
width:100%;
height:100%;
position: relative;
overflow: hidden;
}
#video-container {
width:100%;
height:100%;
}
.id-container{
text-align: center;
width: 100%;
position: absolute;
height: 100%;
vertical-align: middle;
z-index: 200;
}
#device-id{
display: none;
z-index: 200;
color: white;
vertical-align: middle;
font-size: 8em;
font-weight: bold;
font-family: sans-serif;
-webkit-text-stroke: 3px black;
position: relative;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
video {
position: absolute;
transform-origin: top left;
transform:scale(2);
-webkit-transform-origin: top left;
-webkit-transform:scale(2);
}
</style>
<script>
var host = location.origin.replace(/^http/, 'ws');
var ws = new WebSocket(host);
var DEFAULT_SCALE = 2;
var state = {
id:null,
top:0,
left:0,
rotation:'0rad',
scale:DEFAULT_SCALE,
width: window.innerWidth,
height: window.innerHeight
};
ws.onmessage = function (event) {
var data = JSON.parse(event.data),
videoElement = document.querySelector('video'),
deviceIdText = document.getElementById('device-id');
if (data.newId) {
deviceIdText.innerHTML = data.newId;
state.id = data.newId;
if (data.video) { videoElement.src = 'uploads/' + data.video; }
if (data.showIds) {
deviceIdText.style.display = 'block';
} else {
deviceIdText.style.display = 'none';
}
} else if ((data.deviceId == state.id || data.deviceId =='all') && data.changes) {
if (data.changes.position) {
state.top = videoElement.style.top = (data.changes.position.top * state.scale);
state.left = videoElement.style.left = (data.changes.position.left * state.scale);
}
if (data.changes.rotation) {
var rotation = state.rotation = data.changes.rotation;
var parent = document.getElementById('video-container');
parent.style.transform = 'rotate(' + rotation + ')';
parent.style.webkitTransform = 'rotate(' + rotation + ')';
}
if (data.changes.scale) {
setVideoScale(data.changes.scale);
}
} else if (data == 'reset') {
videoElement.currentTime = 0;
} else if (data == 'pause') {
videoElement.pause();
} else if (data == 'resume') {
videoElement.play();
} else if (data == 'show ids') {
deviceIdText.style.display = 'block';
} else if (data == 'hide ids') {
deviceIdText.style.display = 'none';
} else if (data.video) {
videoElement.src = 'uploads/' + data.video;
setVideoScale(DEFAULT_SCALE)
}
function setVideoScale(scale) {
state.scale = scale;
var scaleString = 'scale(' + scale + ')';
videoElement.style.transform = scaleString;
videoElement.style.webkitTransform = scaleString;
}
};
ws.onopen = function(event) {
var videoElement = document.querySelector('video');
send({initialValues:{height: state.height, width: state.width}});
document.addEventListener('click', function(){ videoElement.play()} );
videoElement.load();
};
function send(data) {
ws.send(JSON.stringify(data))
}
</script>
</head>
<body>
<div id="frame">
<div id="video-container">
<div class="id-container">
<span id="device-id"></span>
</div>
<video muted autoplay loop></video>
</div>
</div>
</body>
</html>