-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathwebsocketexample.html
More file actions
42 lines (33 loc) · 865 Bytes
/
Copy pathwebsocketexample.html
File metadata and controls
42 lines (33 loc) · 865 Bytes
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
<html>
<head>
<title>mjpeg-relay example</title>
</head>
<body>
<canvas id="canvas" width="350" height="225"></canvas>
<script>
//--CONFIGURATION--
var websocketAddress = "ws://localhost:54018";
//--END OF CONFIGURATION--
var c = document.getElementById("canvas");
var ctx = c.getContext("2d");
var websocket = new WebSocket(websocketAddress);
websocket.onopen = function () {
console.log("mjpeg-relay connected");
};
websocket.onclose = function () {
console.log("mjpeg-relay disconnected");
};
websocket.onmessage = function (evt) {
var image = new Image();
image.onload = function () {
ctx.drawImage(image, 0, 0);
};
image.src = evt.data;
};
websocket.onerror = function (evt) {
console.log('error: ' + evt.data);
websocket.close();
};
</script>
</body>
</html>