KEXEL commited on
Commit
2108c2f
verified
1 Parent(s): 2ef0b05
Files changed (1) hide show
  1. campainha.html +92 -0
campainha.html ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="pt-BR">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Campainha Virtual</title>
7
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
8
+ <style>
9
+ body { font-family: Arial; text-align: center; margin: 40px; background: #f4f4f4; }
10
+ #app { background: #fff; padding: 20px; border-radius: 12px; display: inline-block; box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
11
+ button { margin: 10px; padding: 10px 18px; font-size: 16px; border: none; border-radius: 8px; cursor: pointer; }
12
+ .host { background: #2563eb; color: #fff; }
13
+ .guest { background: #10b981; color: #fff; }
14
+ </style>
15
+ </head>
16
+ <body>
17
+
18
+ <div id="app">
19
+ <h1>馃敂 Campainha Virtual</h1>
20
+ <p>Escolha o modo:</p>
21
+ <button class="host" onclick="iniciarHost()">Sou o anfitri茫o</button>
22
+ <button class="guest" onclick="iniciarVisitante()">Sou o visitante</button>
23
+
24
+ <div id="areaHost" style="display:none;">
25
+ <h2>Modo Anfitri茫o</h2>
26
+ <p>Escaneie este QR em outro aparelho:</p>
27
+ <div id="qrcode"></div>
28
+ <audio id="som" src="https://actions.google.com/sounds/v1/alarms/digital_watch_alarm_long.ogg"></audio>
29
+ <p><strong>Status:</strong> <span id="statusHost">Aguardando...</span></p>
30
+ </div>
31
+
32
+ <div id="areaVisitante" style="display:none;">
33
+ <h2>Modo Visitante</h2>
34
+ <p>Insira o c贸digo do anfitri茫o:</p>
35
+ <input id="codigoInput" placeholder="Ex: sala123" />
36
+ <br>
37
+ <button onclick="tocarCampainha()">馃敂 Tocar Campainha</button>
38
+ <p id="statusVisitante"></p>
39
+ </div>
40
+ </div>
41
+
42
+ <script>
43
+ const servidor = "wss://echo.websocket.events"; // servidor p煤blico de teste
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 = "campainha_" + Math.floor(Math.random() * 100000);
51
+ new QRCode(document.getElementById("qrcode"), window.location.origin + "?sala=" + codigoSala);
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
+ if (msg.data.includes("TOCAR")) {
60
+ document.getElementById("som").play();
61
+ piscarTela();
62
+ }
63
+ };
64
+ }
65
+
66
+ function iniciarVisitante() {
67
+ document.getElementById("areaVisitante").style.display = "block";
68
+ document.getElementById("areaHost").style.display = "none";
69
+
70
+ const url = new URL(window.location.href);
71
+ if (url.searchParams.get("sala")) {
72
+ document.getElementById("codigoInput").value = url.searchParams.get("sala");
73
+ }
74
+ }
75
+
76
+ function tocarCampainha() {
77
+ const codigo = document.getElementById("codigoInput").value.trim();
78
+ if (!codigo) return alert("Digite o c贸digo da sala!");
79
+ ws = new WebSocket(servidor);
80
+ ws.onopen = () => {
81
+ ws.send("TOCAR_" + codigo);
82
+ document.getElementById("statusVisitante").textContent = "Campainha enviada!";
83
+ };
84
+ }
85
+
86
+ function piscarTela() {
87
+ document.body.style.background = "#ffe4e4";
88
+ setTimeout(() => document.body.style.background = "#f4f4f4", 400);
89
+ }
90
+ </script>
91
+ </body>
92
+ </html>