Gestionnaire de fichiers - Editer - /home/pack/assets/js/beacon.js
Arrière
// ===================================================== // 🔵 1) Flutter → Web (รับ Event จาก Flutter) // ===================================================== window.addEventListener("flutter_beacon", function (e) { const data = e.detail || {}; console.log("🔥 [Web] Receive Event from Flutter:", data); // แสดง Alert บนหน้า WebApp if (data.message) { alert("📡 Beacon Detected:\n" + data.message); } // ถ้าต้องการส่งกลับไป logic เดิม if (typeof notifyBeaconDetected === "function") { notifyBeaconDetected(data.uuid, data.major, data.minor); } }); // ===================================================== // 🔵 2) Web → Flutter (ผ่าน window.PackBeacon.postMessage) // ===================================================== function sendToFlutter(data) { try { if (window.PackBeacon && window.PackBeacon.postMessage) { const jsonStr = JSON.stringify(data); window.PackBeacon.postMessage(jsonStr); console.log("📤 [Web → Flutter] Sent:", jsonStr); } else { console.warn("⚠ Flutter channel missing — run inside mobile app only"); } } catch (err) { console.error("❌ Error sending to Flutter:", err); } } // ===================================================== // 🔵 3) ฟังก์ชันเรียกจาก Dashboard // ===================================================== // เริ่มสแกน Beacon (เว็บจะเรียก Flutter ให้ไป handle) function startBeaconScan() { sendToFlutter({ type: "start_scan", }); } // ทดสอบส่ง Notification จากเว็บ function testNotify() { sendToFlutter({ type: "manual_notify", title: "ทดสอบแจ้งเตือนจาก Web", body: "ข้อความนี้ส่งไปที่ Flutter" }); } // ส่งข้อมูลว่าพบ Beacon (ถ้าต้องการ) function notifyBeaconDetected(uuid, major, minor) { sendToFlutter({ type: "beacon_detected", uuid: uuid, major: Number(major), minor: Number(minor), }); } // ===================================================== // 🔵 4) กดปุ่มใน Dashboard // ===================================================== window.BeaconApp = { start: startBeaconScan, testNotify: testNotify }; let scanStatus = "idle"; // idle | scanning function updateScanUI() { const el = document.getElementById("scan-status"); if (!el) return; if (scanStatus === "scanning") { el.innerHTML = "🟢 กำลังสแกน Beacon"; el.style.color = "green"; } else { el.innerHTML = "⚪ หยุดสแกน"; el.style.color = "gray"; } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Génération de la page: 0.1 |
proxy
|
phpinfo
|
Réglages