Update app.py
This commit is contained in:
112
app.py
112
app.py
@@ -4210,6 +4210,118 @@ def robots_txt():
|
||||
)
|
||||
return content, 200, {"Content-Type": "text/plain"}
|
||||
|
||||
@app.route('/debug-socket')
|
||||
@login_required # opcjonalnie
|
||||
def debug_socket():
|
||||
return render_template_string('''
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Socket Debug</title>
|
||||
<script src="https://cdn.socket.io/4.7.5/socket.io.min.js"></script>
|
||||
<style>
|
||||
body { font-family: monospace; background: #1e1e1e; color: #fff; padding: 20px; }
|
||||
#log { height: 400px; overflow-y: scroll; background: #2d2d2d; padding: 15px; border-radius: 8px; margin: 10px 0; white-space: pre-wrap; }
|
||||
button { background: #007bff; color: white; border: none; padding: 10px 20px; margin: 5px; border-radius: 5px; cursor: pointer; }
|
||||
button:hover { background: #0056b3; }
|
||||
.status { font-size: 18px; font-weight: bold; margin: 10px 0; }
|
||||
.connected { color: #28a745; }
|
||||
.disconnected { color: #dc3545; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Socket.IO Debug Tool</h1>
|
||||
|
||||
<div id="status" class="status disconnected">Rozlaczony</div>
|
||||
<div id="info">
|
||||
Transport: <span id="transport">-</span> |
|
||||
Ping: <span id="ping">-</span>ms |
|
||||
SID: <span id="sid">-</span>
|
||||
</div>
|
||||
|
||||
<button onclick="connect()">Polacz</button>
|
||||
<button onclick="disconnect()">Rozlacz</button>
|
||||
<button onclick="emitTest()">Emit Test</button>
|
||||
<button onclick="simulateBackground()">Symuluj background (30s)</button>
|
||||
|
||||
<h3>Logi:</h3>
|
||||
<div id="log"></div>
|
||||
|
||||
<script>
|
||||
let socket;
|
||||
let logLines = 0;
|
||||
|
||||
function log(msg, color = '#fff') {
|
||||
const logEl = document.getElementById('log');
|
||||
logEl.innerHTML += `[${new Date().toLocaleTimeString()}] ${msg}\n`;
|
||||
logEl.scrollTop = logEl.scrollHeight;
|
||||
logLines++;
|
||||
if (logLines > 100) logEl.innerHTML = logEl.innerHTML.split('\\n').slice(-100).join('\\n');
|
||||
}
|
||||
|
||||
function updateStatus(connected) {
|
||||
const status = document.getElementById('status');
|
||||
status.textContent = connected ? 'Polaczony' : 'Rozlaczony';
|
||||
status.className = `status ${connected ? 'connected' : 'disconnected'}`;
|
||||
}
|
||||
|
||||
function connect() {
|
||||
if (socket) socket.disconnect();
|
||||
|
||||
socket = io('', {
|
||||
transports: ['websocket', 'polling'],
|
||||
timeout: 20000,
|
||||
autoConnect: false
|
||||
});
|
||||
|
||||
socket.on('connect', () => {
|
||||
log('CONNECTED', '#28a745');
|
||||
updateStatus(true);
|
||||
document.getElementById('transport').textContent = socket.io.engine.transport.name;
|
||||
document.getElementById('sid').textContent = socket.id?.slice(0,8) + '...';
|
||||
socket.emit('requestfulllist', {listid: window.LISTID || 1});
|
||||
});
|
||||
|
||||
socket.on('disconnect', (reason) => {
|
||||
log(`DISCONNECTED: ${reason}`, '#dc3545');
|
||||
updateStatus(false);
|
||||
});
|
||||
|
||||
socket.on('connect_error', (err) => {
|
||||
log(`CONNECT ERROR: ${err.message}`, '#ffc107');
|
||||
});
|
||||
|
||||
socket.onAny((event, ...args) => {
|
||||
log(`RECEIVED: ${event} ${JSON.stringify(args)}`);
|
||||
});
|
||||
|
||||
socket.connect();
|
||||
}
|
||||
|
||||
function disconnect() {
|
||||
if (socket) socket.disconnect();
|
||||
}
|
||||
|
||||
function emitTest() {
|
||||
if (!socket?.connected) return log('Niepolaczony!', '#dc3545');
|
||||
socket.emit('additem', {listid: 1, name: 'TEST ITEM', quantity: 1});
|
||||
log('SENT: additem test');
|
||||
}
|
||||
|
||||
function simulateBackground() {
|
||||
log('Symulacja backgroundu... (zamknij/otworz karte za 30s)');
|
||||
setTimeout(() => {
|
||||
if (socket?.connected) log('Przetrwal symulacje!');
|
||||
else log('Disconnect po symulacji!');
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
connect();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
''')
|
||||
|
||||
|
||||
# =========================================================================================
|
||||
# SOCKET.IO
|
||||
|
||||
Reference in New Issue
Block a user