session bug fix

This commit is contained in:
lockbitchat
2025-10-13 11:13:11 -04:00
parent 45de8ce285
commit d292c84829
16 changed files with 3819 additions and 58 deletions

180
dist/app.js vendored
View File

@@ -710,6 +710,17 @@ var EnhancedConnectionSetup = ({
}),
"Scan QR Code"
])
// React.createElement('button', {
// key: 'bluetooth-btn',
// onClick: () => { try { document.dispatchEvent(new CustomEvent('open-bluetooth-transfer', { detail: { role: 'responder' } })); } catch {} },
// className: "px-4 py-2 bg-blue-500/10 hover:bg-blue-500/20 text-blue-400 border border-blue-500/20 rounded text-sm font-medium transition-all duration-200"
// }, [
// React.createElement('i', {
// key: 'icon',
// className: 'fas fa-bluetooth mr-2'
// }),
// 'Bluetooth'
// ])
]),
React.createElement("textarea", {
key: "input",
@@ -819,6 +830,17 @@ var EnhancedConnectionSetup = ({
}),
"Scan QR Code"
]),
// React.createElement('button', {
// key: 'bluetooth-btn',
// onClick: () => { try { document.dispatchEvent(new CustomEvent('open-bluetooth-transfer', { detail: { role: 'initiator' } })); } catch {} },
// className: "px-4 py-2 bg-blue-500/10 hover:bg-blue-500/20 text-blue-400 border border-blue-500/20 rounded text-sm font-medium transition-all duration-200"
// }, [
// React.createElement('i', {
// key: 'icon',
// className: 'fas fa-bluetooth mr-2'
// }),
// 'Bluetooth'
// ]),
React.createElement("button", {
key: "process-btn",
onClick: onCreateAnswer,
@@ -1332,6 +1354,21 @@ var EnhancedSecureP2PChat = () => {
const [qrCodeUrl, setQrCodeUrl] = React.useState("");
const [showQRScanner, setShowQRScanner] = React.useState(false);
const [showQRScannerModal, setShowQRScannerModal] = React.useState(false);
const [showBluetoothTransfer, setShowBluetoothTransfer] = React.useState(false);
const [bluetoothAutoRole, setBluetoothAutoRole] = React.useState(null);
React.useEffect(() => {
const openBt = (e2) => {
try {
const role = e2?.detail?.role || null;
setBluetoothAutoRole(role);
setShowBluetoothTransfer(true);
} catch {
}
};
document.addEventListener("open-bluetooth-transfer", openBt);
return () => document.removeEventListener("open-bluetooth-transfer", openBt);
}, []);
const [bluetoothManager, setBluetoothManager] = React.useState(null);
const [isVerified, setIsVerified] = React.useState(false);
const [securityLevel, setSecurityLevel] = React.useState(null);
const [localVerificationConfirmed, setLocalVerificationConfirmed] = React.useState(false);
@@ -1462,12 +1499,6 @@ var EnhancedSecureP2PChat = () => {
}, 2e3);
}
}, []);
React.useEffect(() => {
const timer = setInterval(() => {
setSessionTimeLeft(0);
}, 1e3);
return () => clearInterval(timer);
}, []);
const chatMessagesRef = React.useRef(null);
const scrollToBottom = createScrollToBottomFunction(chatMessagesRef);
React.useEffect(() => {
@@ -2413,6 +2444,128 @@ var EnhancedSecureP2PChat = () => {
return true;
}
};
const handleBluetoothKeyReceived = async (keyData, deviceId) => {
try {
console.log("Bluetooth key received from device:", deviceId);
const keyString = JSON.stringify(keyData, null, 2);
if (showOfferStep) {
setAnswerInput(keyString);
} else {
setOfferInput(keyString);
}
setMessages((prev) => [...prev, {
message: "\u{1F535} Bluetooth key received successfully!",
type: "success"
}]);
setShowBluetoothTransfer(false);
} catch (error) {
console.error("Failed to process Bluetooth key:", error);
setMessages((prev) => [...prev, {
message: "Failed to process Bluetooth key: " + error.message,
type: "error"
}]);
}
};
const handleBluetoothStatusChange = (statusType, data) => {
console.log("Bluetooth status change:", statusType, data);
switch (statusType) {
case "bluetooth_ready":
setMessages((prev) => [...prev, {
message: "\u{1F535} Bluetooth ready for key exchange",
type: "info"
}]);
break;
case "connected":
setMessages((prev) => [...prev, {
message: `\u{1F535} Connected to device: ${data.deviceName}`,
type: "success"
}]);
break;
case "key_sent":
setMessages((prev) => [...prev, {
message: "\u{1F535} Public key sent via Bluetooth",
type: "success"
}]);
break;
case "key_received":
setMessages((prev) => [...prev, {
message: "\u{1F535} Public key received via Bluetooth",
type: "success"
}]);
break;
case "auto_connection_starting":
setMessages((prev) => [...prev, {
message: "\u{1F535} Starting automatic connection...",
type: "info"
}]);
break;
case "creating_offer":
setMessages((prev) => [...prev, {
message: "\u{1F535} Creating secure offer...",
type: "info"
}]);
break;
case "offer_sent":
setMessages((prev) => [...prev, {
message: "\u{1F535} Offer sent, waiting for answer...",
type: "info"
}]);
break;
case "waiting_for_answer":
setMessages((prev) => [...prev, {
message: "\u{1F535} Waiting for answer...",
type: "info"
}]);
break;
case "processing_answer":
setMessages((prev) => [...prev, {
message: "\u{1F535} Processing answer...",
type: "info"
}]);
break;
case "waiting_for_verification":
setMessages((prev) => [...prev, {
message: "\u{1F535} Waiting for verification...",
type: "info"
}]);
break;
case "auto_connection_complete":
setMessages((prev) => [...prev, {
message: "\u{1F535} Automatic connection completed!",
type: "success"
}]);
break;
case "auto_connection_failed":
setMessages((prev) => [...prev, {
message: "\u{1F535} Automatic connection failed: " + (data.error || "Unknown error"),
type: "error"
}]);
break;
}
};
const handleBluetoothError = (error) => {
console.error("Bluetooth error:", error);
setMessages((prev) => [...prev, {
message: "Bluetooth error: " + error.message,
type: "error"
}]);
};
const handleBluetoothAutoConnection = async (connectionData) => {
try {
console.log("Bluetooth auto connection completed:", connectionData);
setMessages((prev) => [...prev, {
message: "\u{1F535} Bluetooth auto connection completed successfully!",
type: "success"
}]);
setShowBluetoothTransfer(false);
} catch (error) {
console.error("Failed to process auto connection:", error);
setMessages((prev) => [...prev, {
message: "Failed to process auto connection: " + error.message,
type: "error"
}]);
}
};
const handleCreateOffer = async () => {
try {
setOfferData("");
@@ -3011,7 +3164,7 @@ var EnhancedSecureP2PChat = () => {
return React.createElement("div", {
className: "minimal-bg min-h-screen"
}, [
React.createElement(EnhancedMinimalHeader, {
window.EnhancedMinimalHeader && React.createElement(window.EnhancedMinimalHeader, {
key: "header",
status: connectionStatus,
fingerprint: keyFingerprint,
@@ -3153,7 +3306,18 @@ var EnhancedSecureP2PChat = () => {
])
])
])
])
]),
// Bluetooth Key Transfer Modal
showBluetoothTransfer && window.BluetoothKeyTransfer && React.createElement(window.BluetoothKeyTransfer, {
key: "bluetooth-transfer-modal",
webrtcManager: webrtcManagerRef.current,
onKeyReceived: handleBluetoothKeyReceived,
onStatusChange: handleBluetoothStatusChange,
onError: handleBluetoothError,
onAutoConnection: handleBluetoothAutoConnection,
isVisible: showBluetoothTransfer,
onClose: () => setShowBluetoothTransfer(false)
})
]);
};
function initializeApp() {