-
Notifications
You must be signed in to change notification settings - Fork 0
/
sliders.js
44 lines (39 loc) · 1.92 KB
/
sliders.js
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
var webSocketCameraUrl = "ws:\/\/" + window.location.hostname + "/Camera";
var webSocketServoInputUrl = "ws:\/\/" + window.location.hostname + "/ServoInput";
var websocketCamera;
var websocketServoInput;
function initCameraWebSocket() {
websocketCamera = new WebSocket(webSocketCameraUrl);
websocketCamera.binaryType = 'blob';
websocketCamera.onopen = function (event) { };
websocketCamera.onclose = function (event) { setTimeout(initCameraWebSocket, 2000); };
websocketCamera.onmessage = function (event) {
var imageId = document.getElementById("cameraImage");
imageId.src = URL.createObjectURL(event.data);
};
}
function initServoInputWebSocket() {
websocketServoInput = new WebSocket(webSocketServoInputUrl);
websocketServoInput.onopen = function (event) {
var panButton = document.getElementById("Pan");
sendButtonInput("Pan", panButton.value);
var tiltButton = document.getElementById("Tilt");
sendButtonInput("Tilt", tiltButton.value);
var lightButton = document.getElementById("Light");
sendButtonInput("Light", lightButton.value);
};
websocketServoInput.onclose = function (event) { setTimeout(initServoInputWebSocket, 2000); };
websocketServoInput.onmessage = function (event) { };
}
function initWebSocket() {
initCameraWebSocket();
initServoInputWebSocket();
}
function sendButtonInput(key, value) {
var data = key + "," + value;
websocketServoInput.send(data);
}
window.onload = initWebSocket;
document.getElementById("mainTable").addEventListener("touchend", function (event) {
event.preventDefault()
});