Improve browser compatibility

This commit is contained in:
Marcus Noble 2020-12-11 08:21:11 +00:00
parent bcda8f8a4f
commit 45ee87b6eb
2 changed files with 7 additions and 8 deletions

View File

@ -29,8 +29,7 @@
<script> <script>
document.querySelector('form').addEventListener('submit', function(event) { document.querySelector('form').addEventListener('submit', function(event) {
event.preventDefault(); event.preventDefault();
let roomId = document.getElementById('roomId').value; window.location = '//' + window.location.host + '/' + document.getElementById('roomId').value;
window.location = `//${window.location.host}/${roomId}`;
}); });
</script> </script>
</body> </body>

View File

@ -26,8 +26,8 @@
</div> </div>
<script> <script>
let proto = location.protocol == 'http:' ? 'ws' : 'wss' var proto = location.protocol == 'http:' ? 'ws' : 'wss'
let socket = new WebSocket(`${proto}://${window.location.hostname}:${window.location.port}/{{room}}`); var socket = new WebSocket(proto + '://' + window.location.hostname + ':' + window.location.port + '/{{room}}');
socket.onopen = function(e) { socket.onopen = function(e) {
socket.send(JSON.stringify({ socket.send(JSON.stringify({
@ -40,7 +40,7 @@
}; };
socket.onmessage = function(event) { socket.onmessage = function(event) {
let msg = JSON.parse(event.data); var msg = JSON.parse(event.data);
if (msg.type === "buzz") { if (msg.type === "buzz") {
showMessage(msg.msg); showMessage(msg.msg);
} else if (msg.type === "reset") { } else if (msg.type === "reset") {
@ -71,7 +71,7 @@
function showMessage(msg) { function showMessage(msg) {
window.navigator.vibrate(500); window.navigator.vibrate(500);
document.getElementById('buzzer').disabled = true; document.getElementById('buzzer').disabled = true;
let mb = document.getElementById('messageBox'); var mb = document.getElementById('messageBox');
mb.innerHTML = msg; mb.innerHTML = msg;
mb.classList.remove('hide'); mb.classList.remove('hide');
} }
@ -79,13 +79,13 @@
function reset() { function reset() {
document.getElementById('buzzer').disabled = false; document.getElementById('buzzer').disabled = false;
document.getElementById('buzzer').classList.remove('active'); document.getElementById('buzzer').classList.remove('active');
let mb = document.getElementById('messageBox'); var mb = document.getElementById('messageBox');
mb.classList.add('hide'); mb.classList.add('hide');
} }
function roomClosed() { function roomClosed() {
document.getElementById('buzzer').disabled = true; document.getElementById('buzzer').disabled = true;
let mb = document.getElementById('messageBox'); var mb = document.getElementById('messageBox');
mb.innerHTML = "Room closed"; mb.innerHTML = "Room closed";
mb.classList.remove('hide'); mb.classList.remove('hide');
} }