Skip to content

Instantly share code, notes, and snippets.

@MickaelCruzDB
Created March 29, 2022 12:27
Show Gist options
  • Save MickaelCruzDB/33c4c5076e94d0d133234bfa93369947 to your computer and use it in GitHub Desktop.
Save MickaelCruzDB/33c4c5076e94d0d133234bfa93369947 to your computer and use it in GitHub Desktop.
<!DOCTYPE HTML>
<html>
<head>
<script type = "text/javascript">
if ("WebSocket" in window) {
console.log("WebSocket is supported by the Browser!");
// Let us open a web socket
var ws = new WebSocket("ws://192.168.1.10:2401");
ws.onopen = function() {
// Web Socket is connected, send data using send()
console.log("Hello server!");
};
ws.onmessage = function (event) {
var bytearray = new Uint8Array(event.data);
console.log(bytearray);
document.getElementById("ItemPreview").src = "data:image/png;base64," + bytearray;
};
ws.onclose = function() {
// websocket is closed.
console.log("Connection is closed...");
};
} else {
// The browser doesn't support WebSocket
console.log("WebSocket NOT supported by your Browser!");
}
</script>
</head>
<body>
<img id="ItemPreview" src="">
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment