1.1
Browse files- campainha.html +22 -18
campainha.html
CHANGED
|
@@ -40,26 +40,28 @@
|
|
| 40 |
</div>
|
| 41 |
|
| 42 |
<script>
|
| 43 |
-
const servidor = "wss://
|
| 44 |
let ws, codigoSala;
|
| 45 |
|
| 46 |
function iniciarHost() {
|
| 47 |
document.getElementById("areaHost").style.display = "block";
|
| 48 |
document.getElementById("areaVisitante").style.display = "none";
|
| 49 |
|
| 50 |
-
codigoSala = "
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
ws = new WebSocket(servidor);
|
| 54 |
-
ws.onopen = () =>
|
| 55 |
-
ws.send(JSON.stringify({tipo:"entrar", sala:codigoSala}));
|
| 56 |
-
document.getElementById("statusHost").textContent = "Sala: " + codigoSala;
|
| 57 |
-
};
|
| 58 |
ws.onmessage = (msg) => {
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
| 63 |
};
|
| 64 |
}
|
| 65 |
|
|
@@ -68,9 +70,8 @@ function iniciarVisitante() {
|
|
| 68 |
document.getElementById("areaHost").style.display = "none";
|
| 69 |
|
| 70 |
const url = new URL(window.location.href);
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
}
|
| 74 |
}
|
| 75 |
|
| 76 |
function tocarCampainha() {
|
|
@@ -78,15 +79,18 @@ function tocarCampainha() {
|
|
| 78 |
if (!codigo) return alert("Digite o c贸digo da sala!");
|
| 79 |
ws = new WebSocket(servidor);
|
| 80 |
ws.onopen = () => {
|
| 81 |
-
ws.send("
|
| 82 |
document.getElementById("statusVisitante").textContent = "Campainha enviada!";
|
| 83 |
};
|
| 84 |
}
|
| 85 |
|
| 86 |
-
function
|
|
|
|
|
|
|
|
|
|
| 87 |
document.body.style.background = "#ffe4e4";
|
| 88 |
-
setTimeout(() => document.body.style.background = "#f4f4f4",
|
| 89 |
}
|
| 90 |
</script>
|
| 91 |
</body>
|
| 92 |
-
</html>
|
|
|
|
| 40 |
</div>
|
| 41 |
|
| 42 |
<script>
|
| 43 |
+
const servidor = "wss://ws.ifelse.io"; // WebSocket que aceita m煤ltiplos clientes
|
| 44 |
let ws, codigoSala;
|
| 45 |
|
| 46 |
function iniciarHost() {
|
| 47 |
document.getElementById("areaHost").style.display = "block";
|
| 48 |
document.getElementById("areaVisitante").style.display = "none";
|
| 49 |
|
| 50 |
+
codigoSala = "camp_" + Math.floor(Math.random() * 100000);
|
| 51 |
+
const link = window.location.origin + window.location.pathname + "?sala=" + codigoSala;
|
| 52 |
+
new QRCode(document.getElementById("qrcode"), link);
|
| 53 |
+
|
| 54 |
+
document.getElementById("statusHost").textContent = "Sala: " + codigoSala;
|
| 55 |
|
| 56 |
ws = new WebSocket(servidor);
|
| 57 |
+
ws.onopen = () => console.log("Host conectado");
|
|
|
|
|
|
|
|
|
|
| 58 |
ws.onmessage = (msg) => {
|
| 59 |
+
try {
|
| 60 |
+
const data = JSON.parse(msg.data);
|
| 61 |
+
if (data.sala === codigoSala && data.acao === "tocar") {
|
| 62 |
+
tocarSom();
|
| 63 |
+
}
|
| 64 |
+
} catch {}
|
| 65 |
};
|
| 66 |
}
|
| 67 |
|
|
|
|
| 70 |
document.getElementById("areaHost").style.display = "none";
|
| 71 |
|
| 72 |
const url = new URL(window.location.href);
|
| 73 |
+
const sala = url.searchParams.get("sala");
|
| 74 |
+
if (sala) document.getElementById("codigoInput").value = sala;
|
|
|
|
| 75 |
}
|
| 76 |
|
| 77 |
function tocarCampainha() {
|
|
|
|
| 79 |
if (!codigo) return alert("Digite o c贸digo da sala!");
|
| 80 |
ws = new WebSocket(servidor);
|
| 81 |
ws.onopen = () => {
|
| 82 |
+
ws.send(JSON.stringify({ sala: codigo, acao: "tocar" }));
|
| 83 |
document.getElementById("statusVisitante").textContent = "Campainha enviada!";
|
| 84 |
};
|
| 85 |
}
|
| 86 |
|
| 87 |
+
function tocarSom() {
|
| 88 |
+
const som = document.getElementById("som");
|
| 89 |
+
som.currentTime = 0;
|
| 90 |
+
som.play();
|
| 91 |
document.body.style.background = "#ffe4e4";
|
| 92 |
+
setTimeout(() => document.body.style.background = "#f4f4f4", 500);
|
| 93 |
}
|
| 94 |
</script>
|
| 95 |
</body>
|
| 96 |
+
</html>
|