<!DOCTYPE html>
<html lang="pt">
<head>
<meta charset="UTF-8">
<title>P2P Global</title>
<style>
body { background: #0a0a0a; color: #00ff41; font-family: 'Courier New', monospace; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; }
.caixa { background: #111; padding: 20px; border: 1px solid #00ff41; width: 90%; max-width: 450px; box-shadow: 0 0 15px rgba(0,255,65,0.2); }
textarea { width: 100%; height: 80px; background: #000; color: #00ff41; border: 1px solid #00ff41; margin: 5px 0; font-size: 9px; resize: none; }
input { width: 100%; padding: 10px; margin: 10px 0; background: #000; border: 1px solid #00ff41; color: #fff; box-sizing: border-box; }
button { width: 100%; padding: 10px; background: #00ff41; border: none; color: #000; font-weight: bold; cursor: pointer; margin-top: 5px; }
#chat { height: 150px; overflow-y: auto; border: 1px solid #333; padding: 10px; margin-bottom: 10px; font-size: 13px; }
.hidden { display: none; }
</style>
</head>
<body>
<div id="setup" class="caixa">
<h2 style="margin:0 0 15px 0">ACRESO_P2P_GLOBAL</h2>
<input type="password" id="pass" placeholder="Senha cegonha...">
<button onclick="boot()">INICIALIZAR</button>
</div>
<div id="p2p-area" class="caixa hidden">
<div id="chat"><i>Aguardando link...</i></div>
<input type="text" id="msg" placeholder="Escrever..." disabled>
<div style="font-size: 10px; color: #888;">TEU CÓDIGO (COPIAR):</div>
<textarea id="localSdp" readonly onclick="this.select()"></textarea>
<div style="font-size: 10px; color: #888;">CÓDIGO REMOTO (COLAR):</div>
<textarea id="remoteSdp"></textarea>
<button onclick="connect()" style="background:#fff">LIGAR DISPOSITIVOS</button>
</div>
<script>
const SENHA_KEY = "cegonha";
let pc = new RTCPeerConnection({
iceServers: [
{ urls: 'stun:stun.l.google.com:19302' },
{ urls: 'stun:stun1.l.google.com:19302' },
{ urls: 'stun:stun2.l.google.com:19302' },
{ urls: 'stun:global.stun.twilio.com:3478?transport=udp' }
]
});
let dc;
function boot() {
const input = document.getElementById('pass').value;
if (input.toLowerCase() === SENHA_KEY) {
document.getElementById('setup').classList.add('hidden');
document.getElementById('p2p-area').classList.remove('hidden');
startSignaling();
} else {
alert("ACESSO NEGADO");
}
}
async function startSignaling() {
dc = pc.createDataChannel("chat");
setupDC(dc);
pc.onicecandidate = e => {
if (!e.candidate && pc.localDescription) {
document.getElementById('localSdp').value = btoa(JSON.stringify(pc.localDescription));
}
};
pc.ondatachannel = e => setupDC(e.channel);
const offer = await pc.createOffer();
await pc.setLocalDescription(offer);
}
function setupDC(chan) {
dc = chan;
dc.onopen = () => {
document.getElementById('msg').disabled = false;
log("SISTEMA ONLINE");
};
dc.onmessage = e => log("REMOTO: " + e.data, "#00ff41");
}
async function connect() {
const raw = document.getElementById('remoteSdp').value.trim();
if (!raw) return;
const desc = new RTCSessionDescription(JSON.parse(atob(raw)));
await pc.setRemoteDescription(desc);
if (desc.type === "offer") {
const ans = await pc.createAnswer();
await pc.setLocalDescription(ans);
}
}
function log(m, cor = "#eee") {
const c = document.getElementById('chat');
c.innerHTML += `<div style="color:${cor}">> ${m}</div>`;
c.scrollTop = c.scrollHeight;
}
</script>
</body>
</html>