Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Old buzzeur #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added buzzer/.tmp_locker
Empty file.
43 changes: 43 additions & 0 deletions buzzer/buzz.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="UTF-8">
<style>

</style>
<script src="ressources/jquery-3.1.1.min.js"></script>
<script src="ressources/popper.min.js"></script>
<script src="ressources/bootstrap.min.js"></script>
<link rel="stylesheet" href="ressources/bootstrap.min.css">
</head>
<body>
<div class="container" style="text-align: center; font-size: 40px">
Date: <span id="date"></span><br>
Équipe: <span id="pseudo"></span>
</div>
<br><br><br><br>
<div class="container">
Historique:<br>
<ul id="history">

</ul>
</div>

<script>

var old_resp = "";
function update(){
$.get("buzz.php?status", function(data){
if(data != "" && data != old_resp)
$("#history").prepend("<li>"+(new Date()).toGMTString() + " "+data+"</li>");
$("#pseudo").text(data);
$("#date").text((new Date()).toGMTString());
old_resp = data;
});
}
setInterval(update, 300);
update();
</script>
</body>
</html>
44 changes: 44 additions & 0 deletions buzzer/buzz.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

$buzz_delay = 4; //4 secondes pour parler après le buzz.

if(isset($_GET["reset"]) && $_GET["reset"]=="true") {
$data = array(
"buzz_time" => 0,
"equipe" => ""
);
file_put_contents("data.json", json_encode($data));
echo "buzzer reset!";
exit();
} else if(isset($_GET["pseudo"])) {
$file = fopen(".tmp_locker", "a+");
if(flock($file, LOCK_EX)) {
$data = json_decode(file_get_contents("data.json"), true);
if(time() - $data["buzz_time"] >= 5) {
$data["buzz_time"] = time();
$data["equipe"] = $_GET["pseudo"];
file_put_contents("data.json", json_encode($data));
echo "OK";
exit();
} else {
echo $data["buzz_time"];
exit();
}
} else {
echo "not locked wtf";
}
exit();
} else if(isset($_GET["status"])) {
$data = json_decode(file_get_contents("data.json"), true);
if(time() - $data["buzz_time"] >= 5) {
exit();
} else {
echo $data["equipe"];
exit();
}
} else {
echo "error";
exit();
}


1 change: 1 addition & 0 deletions buzzer/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"buzz_time":1554213832,"equipe":"gauche !"}
142 changes: 142 additions & 0 deletions buzzer/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no">

<style>

</style>
<script src="ressources/jquery-3.1.1.min.js"></script>
<script src="ressources/popper.min.js"></script>
<script src="ressources/bootstrap.min.js"></script>
<link rel="stylesheet" href="ressources/bootstrap.min.css">
</head>
<body>
<div style="display: none">
<audio src="ressources/beep.mp3" id="beep"/>
</div>

<button id="reset" type="button" class="btn btn-danger btn-sm" style="">Reset nom équipe</button>
<br><br><br><br><br>

<div class="container" style="text-align: center;">

<div id="nom_equipe_show" style="display: none;">
Équipe: <span id="nom_equipe_data"></span>
</div>

<div id="div_buzzer" style="display: none;">
<button id="buzzer" type="button" class="btn btn-primary btn-lg" style="font-size: 50px;">Buzz!</button>
<p id="buzzer_time_left"></p>
</div>

<div id="ask_pseudo" style="display: none;">

<div class="form-group">
<label for="exampleInputEmail1">Équipe:</label>
<input type="text" class="form-control" id="pseudo">
</div>
<button type="submit" class="btn btn-primary" id="send_pseudo">Submit</button>
</div>
</div>

<script>
var const_reload_time = 5; //5 secondes
var buzz_time = 4; //5 secondes
var beep = $("#beep").get(0);

var pseudo_equipe = null;
if(localStorage.getItem("pseudo_equipe")!=null) {
pseudo_equipe = localStorage.getItem("pseudo_equipe");
$("#div_buzzer").show();
$("#nom_equipe_show").show().children("span").text(pseudo_equipe);
} else {
$("#ask_pseudo").show();
}
$("#send_pseudo").click(function(){
var val = $("#pseudo").val();
if(val.length<3) {
alert("Nom trop court");
return;
}
if(confirm("Confirmer le nom de l'équipe: "+val)) {
window.pseudo_equie = val;
$("#ask_pseudo").hide();
$("#div_buzzer").show();
$("#nom_equipe_show").show().children("span").text(val);
localStorage.setItem("pseudo_equipe", val);
}
});
$("#reset").click(function(){
if(confirm("Reset du nom de l'équipe ?")) {
localStorage.removeItem("pseudo_equipe");
window.location.reload();
}
});

var status = "waiting"; // waiting, speaking, reloading
var time_left = 0;

setInterval(function(){
$("#buzzer_time_left").show().text("Temps restant: "+(parseInt(time_left)+1));
if(time_left<=0) {
time_left = 0;
$("#buzzer_time_left").hide();
} else {
time_left -= 0.1;

if(time_left<0.05) {
time_left = 0;
if(status=="speaking") {
status = "reloading";
time_left = const_reload_time;
$("#buzzer")
.removeClass("btn-warning").removeClass("btn-primary")
.addClass("btn-secondary");
$("html, body").css("background-color", "#6c757d");
beep.play();
} else { //reloading
status = "waiting";
$("#buzzer")
.removeClass("btn-warning").removeClass("btn-secondary")
.addClass("btn-primary");
$("html, body").css("background-color", "#fff");
}
}
}
}, 100);

function buzz() {
$("#buzzer").removeClass("btn-primary").removeClass("brn-secondary").addClass("btn-warning");
$("html, body").css("background-color", "#e0a800");
time_left = parseFloat(buzz_time);
status = "speaking";
}

//Buzz!
$("#buzzer").click(function(){
if(status != "waiting")
return;
$.get("buzz.php?pseudo="+encodeURIComponent(window.pseudo_equipe), function(rep){
if(rep=="OK") {
buzz();
beep.play();
} else {
time_left = (1000*(buzz_time+1) - (Date.now() - parseInt(rep)*1000))/1000;
if(time_left>0.05) {
status = "reloading";
$("#buzzer")
.removeClass("btn-warning").removeClass("btn-primary")
.addClass("btn-secondary");
$("html, body").css("background-color", "#6c757d");
}
}
});
});

</script>

</body>
</html>
Binary file added buzzer/ressources/beep.mp3
Binary file not shown.
7 changes: 7 additions & 0 deletions buzzer/ressources/bootstrap.min.css

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions buzzer/ressources/bootstrap.min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions buzzer/ressources/jquery-3.1.1.min.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions buzzer/ressources/popper.min.js

Large diffs are not rendered by default.