Files
TheChaseBuzzer/pages/play.html
T
2022-12-29 09:20:58 +11:00

111 lines
2.7 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<title>The cooler buzzer website</title>
<link rel="stylesheet" href="styleMain.css">
<!-- <link rel="preload" href="Twoson.woff2" as="font" type="font/woff2" crossorigin> -->
<script src="browserFunctions.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="http:/socket.io/socket.io.js"></script>
<script>
$(document).ready(function() {
var socket = io();
let buzzInTime;//for ping check
let queryString = new URL(location.href);
let userName = queryString.searchParams.get("user");
$("#message").html("hi "+userName+" :]")
let teamName = queryString.searchParams.get("team");
let buzzerOptions = setupBuzzerOptions();
let buzzerSound = new Audio(buzzerOptions[0]+".wav");
$("#buzzer").attr("src", buzzerOptions[0]+".png" );
$("#buzzer").css("opacity", "0.2");
let buzzable = false;
socket.emit("registerUser", userName, teamName);
socket.on("userInfoToClient", (userInfo) => {
userInfoToClient(userInfo);
});
socket.on("gameStateToClient", (currentTeam, currentScore) => {
gameStateToClient(currentTeam, currentScore);
});
socket.on("clearBuzzers", (currentTeam) => {
if (currentTeam == teamName) {
buzzable = true;
$("#buzzer").css("opacity", "1");
} else {
buzzable = false;
$("#buzzer").css("opacity", "0.2");
}
$("#firstBuzz").html("");
});
socket.on("buzzInfoToClient", (buzzInfo) => {
buzzInfoToClient(buzzInfo, buzzerSound);
});
socket.on("pingClient", (timeStamp) => {
const ping = new Date().getTime() - timeStamp;
console.log("ping: "+ping);
});
$(document).keydown(function(e) {
if(e.which == 32) {
buzzIn();
}
});
$("#buzzer").mousedown(function() {
buzzIn();
});
function buzzIn() {
if (buzzable) {
buzzable = false;
$("#buzzer").css("opacity", "0.2");
buzzInTime = new Date().getTime();
socket.emit("buzzerPressed", userName, buzzInTime);
socket.emit("pingServer", new Date().getTime());
}
}
$("#buzzerOptions").contents().mousedown(function() {
buzzerSound = selectBuzzer($(this).attr("id"));
});
});
</script>
</head>
<body>
<p id="message"></p>
<div id="interface">
<p id="currentTeam"></p>
Progress:
<p id="currentScore"></p>
<br>
<img id="buzzer" alt="The buzzer" style="width: 200px">
<br>
<p id="firstBuzz"></p>
</div>
<div id="userListPanel">
<div id="PlayersList">
Players:
<ul></ul>
</div>
<div id="ChasersList">
Chasers:
<ul></ul>
</div>
</div>
<div id="buzzerOptions">
</div>
</body>
</html>