|
3 | 3 | <head> |
4 | 4 | <meta charset="UTF-8"> |
5 | 5 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
6 | | - <title>Document</title> |
| 6 | + <title>Aura Session Tester</title> |
| 7 | + <script src="https://cdn.socket.io/4.7.4/socket.io.min.js"></script> |
7 | 8 | </head> |
8 | | -<body> |
9 | | - |
| 9 | +<body style="font-family: monospace; padding: 20px; background-color: #1a1a1a; color: #00ff00;"> |
| 10 | + |
| 11 | + <h2>🚀 AURA SESSION TESTER (LOCAL)</h2> |
| 12 | + <hr> |
| 13 | + |
| 14 | + <div> |
| 15 | + <label>Enter Phone Number (with Country Code):</label><br> |
| 16 | + <input type="text" id="phone" placeholder="9477xxxxxxx" style="padding: 10px; font-size: 16px; width: 300px;"> |
| 17 | + <br><br> |
| 18 | + <button onclick="startPairing()" style="padding: 10px 20px; font-size: 16px; cursor: pointer; background: green; color: white; border: none;"> |
| 19 | + GET PAIRING CODE |
| 20 | + </button> |
| 21 | + </div> |
| 22 | + |
| 23 | + <hr> |
| 24 | + |
| 25 | + <h3>📡 STATUS LOGS:</h3> |
| 26 | + <div id="logs" style="border: 1px solid #555; padding: 10px; height: 150px; overflow-y: scroll; background: #000;"> |
| 27 | + Waiting for connection... |
| 28 | + </div> |
| 29 | + |
| 30 | + <hr> |
| 31 | + |
| 32 | + <h3>🔢 PAIRING CODE:</h3> |
| 33 | + <div id="pairing-code" style="font-size: 40px; font-weight: bold; color: yellow; border: 2px dashed yellow; padding: 20px; text-align: center;"> |
| 34 | + WAITING... |
| 35 | + </div> |
| 36 | + |
| 37 | + <hr> |
| 38 | + |
| 39 | + <h3>✅ SESSION ID:</h3> |
| 40 | + <div id="session-id" style="background: #222; padding: 15px; border: 1px solid lime; word-wrap: break-word; color: cyan;"> |
| 41 | + Not Connected Yet |
| 42 | + </div> |
| 43 | + |
| 44 | + <script> |
| 45 | + // 1. Backend එකට Connect වෙනවා (Port 8000) |
| 46 | + const socket = io("http://localhost:8000"); |
| 47 | + |
| 48 | + const logBox = document.getElementById("logs"); |
| 49 | + const codeBox = document.getElementById("pairing-code"); |
| 50 | + const sessionBox = document.getElementById("session-id"); |
| 51 | + |
| 52 | + function addLog(msg) { |
| 53 | + const time = new Date().toLocaleTimeString(); |
| 54 | + logBox.innerHTML += `<div>[${time}] ${msg}</div>`; |
| 55 | + logBox.scrollTop = logBox.scrollHeight; |
| 56 | + } |
| 57 | + |
| 58 | + // Connection Status |
| 59 | + socket.on("connect", () => { |
| 60 | + addLog("🟢 Connected to Backend Server!"); |
| 61 | + }); |
| 62 | + |
| 63 | + socket.on("disconnect", () => { |
| 64 | + addLog("🔴 Disconnected from Server."); |
| 65 | + }); |
| 66 | + |
| 67 | + // Error Handling |
| 68 | + socket.on("error", (data) => { |
| 69 | + addLog("❌ ERROR: " + data.message); |
| 70 | + alert("Error: " + data.message); |
| 71 | + }); |
| 72 | + |
| 73 | + // 2. Pairing Code එක ආවම මෙතනට වැටෙනවා |
| 74 | + socket.on("pairing-code", (data) => { |
| 75 | + addLog("📩 Pairing Code Received!"); |
| 76 | + codeBox.innerText = data.code; |
| 77 | + // Code එක ආපු ගමන් Copy කරගන්න ලේසි වෙන්න |
| 78 | + navigator.clipboard.writeText(data.code); |
| 79 | + alert("Code: " + data.code + " (Copied to Clipboard!)"); |
| 80 | + }); |
| 81 | + |
| 82 | + // 3. Session එක හරි ගියාම මෙතනට එනවා |
| 83 | + socket.on("session-success", (data) => { |
| 84 | + addLog("✅ SESSION SUCCESSFUL!"); |
| 85 | + codeBox.innerText = "CONNECTED ✅"; |
| 86 | + codeBox.style.color = "lime"; |
| 87 | + codeBox.style.borderColor = "lime"; |
| 88 | + |
| 89 | + sessionBox.innerText = data.id; |
| 90 | + addLog("🔑 Session ID: " + data.id); |
| 91 | + }); |
| 92 | + |
| 93 | + // Button Click Function |
| 94 | + function startPairing() { |
| 95 | + const phoneNumber = document.getElementById("phone").value; |
| 96 | + |
| 97 | + if (!phoneNumber) { |
| 98 | + alert("Please enter a phone number!"); |
| 99 | + return; |
| 100 | + } |
| 101 | + |
| 102 | + addLog("⏳ Requesting Code for " + phoneNumber + "..."); |
| 103 | + codeBox.innerText = "LOADING..."; |
| 104 | + |
| 105 | + // Backend එකට මැසේජ් එක යවනවා |
| 106 | + socket.emit('start-session', { |
| 107 | + phoneNumber: phoneNumber, |
| 108 | + usePairingCode: true |
| 109 | + }); |
| 110 | + } |
| 111 | + </script> |
| 112 | + |
10 | 113 | </body> |
11 | 114 | </html> |
0 commit comments