From 70131428edce8d7c6476a902d015b30b78e5f862 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 3 Dec 2022 16:12:14 +0100 Subject: Version 1.1: Added QR Code --- html/whiteboard.js | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'html/whiteboard.js') diff --git a/html/whiteboard.js b/html/whiteboard.js index d9f0904..c6fb657 100644 --- a/html/whiteboard.js +++ b/html/whiteboard.js @@ -62,6 +62,16 @@ class AdjustingTimer { var timer = new AdjustingTimer(); +function showQRWindow() +{ + document.getElementById("qrwindow").style.display = 'block'; +} + +function hideQRWindow() +{ + document.getElementById("qrwindow").style.display = 'none'; +} + function init_board() { var xhr = new XMLHttpRequest(); @@ -124,6 +134,16 @@ function init_board() { xhr.send(xmlDocument); //set_status("Please wait while server prepares " + filename + " ..."); + + document.getElementById("qrwindow").onclick = function() { + hideQRWindow(); + } + + document.onkeydown = function(evt) { + if (evt.key == "Escape") { + hideQRWindow(); + } + } } function get_id() @@ -300,3 +320,51 @@ function checkupdate() { //set_status("Please wait while server prepares " + filename + " ..."); } +function on_qrcode() +{ + var xhr = new XMLHttpRequest(); + + // run on data received back + xhr.onreadystatechange = function() { + if (this.readyState == 3) { + //set_status("Please wait while downloading " + filename + " ..."); + return; + } + if (this.readyState != 4) { + return; + } + if (this.status != 200) { + //set_status("Server Error while retrieving " + filename + ", status: " + this.status + " " + this.statusText); + return; + } + + if (this.getResponseHeader("Content-Type") == "image/png") { + var blob = new Blob([this.response], {type: 'image/png'}); + var url = URL.createObjectURL(blob); + var img = document.getElementById("qrcode"); + img.src = url; + showQRWindow(); + } + + //set_status(""); // OK + } + + var parser = new DOMParser(); + var xmlDocument = parser.parseFromString("", "text/xml"); + + var requestElement = xmlDocument.getElementsByTagName("request")[0]; + + var commandElement = xmlDocument.createElement("command"); + commandElement.appendChild(document.createTextNode("qrcode")); + requestElement.appendChild(commandElement); + + var idElement = xmlDocument.createElement("url"); + idElement.appendChild(document.createTextNode(document.location)); + requestElement.appendChild(idElement); + + xhr.open("POST", "whiteboard.fcgi", true); + xhr.setRequestHeader("Content-type", "text/xml"); + xhr.responseType = 'blob'; + xhr.send(xmlDocument); +} + -- cgit v1.2.3