mirror of
https://github.com/smittix/intercept.git
synced 2026-07-20 07:18:11 -07:00
Add debug logging to Bluetooth frontend
This commit is contained in:
@@ -22,6 +22,8 @@ const BluetoothMode = (function() {
|
|||||||
* Initialize the Bluetooth mode
|
* Initialize the Bluetooth mode
|
||||||
*/
|
*/
|
||||||
function init() {
|
function init() {
|
||||||
|
console.log('[BT] Initializing BluetoothMode');
|
||||||
|
|
||||||
// Cache DOM elements
|
// Cache DOM elements
|
||||||
startBtn = document.getElementById('startBtBtn');
|
startBtn = document.getElementById('startBtBtn');
|
||||||
stopBtn = document.getElementById('stopBtBtn');
|
stopBtn = document.getElementById('stopBtBtn');
|
||||||
@@ -35,6 +37,13 @@ const BluetoothMode = (function() {
|
|||||||
baselineStatusEl = document.getElementById('btBaselineStatus');
|
baselineStatusEl = document.getElementById('btBaselineStatus');
|
||||||
capabilityStatusEl = document.getElementById('btCapabilityStatus');
|
capabilityStatusEl = document.getElementById('btCapabilityStatus');
|
||||||
|
|
||||||
|
console.log('[BT] DOM elements:', {
|
||||||
|
startBtn: !!startBtn,
|
||||||
|
stopBtn: !!stopBtn,
|
||||||
|
deviceContainer: !!deviceContainer,
|
||||||
|
adapterSelect: !!adapterSelect
|
||||||
|
});
|
||||||
|
|
||||||
// Check capabilities on load
|
// Check capabilities on load
|
||||||
checkCapabilities();
|
checkCapabilities();
|
||||||
|
|
||||||
@@ -218,8 +227,10 @@ const BluetoothMode = (function() {
|
|||||||
if (eventSource) eventSource.close();
|
if (eventSource) eventSource.close();
|
||||||
|
|
||||||
eventSource = new EventSource('/api/bluetooth/stream');
|
eventSource = new EventSource('/api/bluetooth/stream');
|
||||||
|
console.log('[BT] SSE stream connected');
|
||||||
|
|
||||||
eventSource.addEventListener('device_update', (e) => {
|
eventSource.addEventListener('device_update', (e) => {
|
||||||
|
console.log('[BT] SSE device_update event:', e.data);
|
||||||
try {
|
try {
|
||||||
const device = JSON.parse(e.data);
|
const device = JSON.parse(e.data);
|
||||||
handleDeviceUpdate(device);
|
handleDeviceUpdate(device);
|
||||||
@@ -228,6 +239,11 @@ const BluetoothMode = (function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Also listen for generic messages as fallback
|
||||||
|
eventSource.onmessage = (e) => {
|
||||||
|
console.log('[BT] SSE generic message:', e.data);
|
||||||
|
};
|
||||||
|
|
||||||
eventSource.addEventListener('scan_started', (e) => {
|
eventSource.addEventListener('scan_started', (e) => {
|
||||||
const data = JSON.parse(e.data);
|
const data = JSON.parse(e.data);
|
||||||
setScanning(true);
|
setScanning(true);
|
||||||
@@ -269,6 +285,7 @@ const BluetoothMode = (function() {
|
|||||||
* Handle device update from SSE
|
* Handle device update from SSE
|
||||||
*/
|
*/
|
||||||
function handleDeviceUpdate(device) {
|
function handleDeviceUpdate(device) {
|
||||||
|
console.log('[BT] Device update received:', device);
|
||||||
devices.set(device.device_id, device);
|
devices.set(device.device_id, device);
|
||||||
renderDevice(device);
|
renderDevice(device);
|
||||||
}
|
}
|
||||||
@@ -277,7 +294,16 @@ const BluetoothMode = (function() {
|
|||||||
* Render a device card
|
* Render a device card
|
||||||
*/
|
*/
|
||||||
function renderDevice(device) {
|
function renderDevice(device) {
|
||||||
if (!deviceContainer) return;
|
console.log('[BT] Rendering device:', device.device_id, 'Container:', deviceContainer);
|
||||||
|
if (!deviceContainer) {
|
||||||
|
console.warn('[BT] No device container found!');
|
||||||
|
// Try to find it again
|
||||||
|
deviceContainer = document.getElementById('output');
|
||||||
|
if (!deviceContainer) {
|
||||||
|
console.error('[BT] Still no container - cannot render');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const existingCard = deviceContainer.querySelector(`[data-device-id="${device.device_id}"]`);
|
const existingCard = deviceContainer.querySelector(`[data-device-id="${device.device_id}"]`);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user