Websocket fix 2
This commit is contained in:
@@ -313,6 +313,29 @@ req.on('upgrade', (res, socket, head) => {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function createTextFrame(text) {
|
||||
const payload = Buffer.from(text, 'utf8');
|
||||
const payloadLength = payload.length;
|
||||
|
||||
let frame;
|
||||
if (payloadLength < 126) {
|
||||
frame = Buffer.allocUnsafe(2 + payloadLength);
|
||||
frame[0] = 0x81; // Text frame, FIN=1
|
||||
frame[1] = payloadLength;
|
||||
payload.copy(frame, 2);
|
||||
} else if (payloadLength < 65536) {
|
||||
frame = Buffer.allocUnsafe(4 + payloadLength);
|
||||
frame[0] = 0x81;
|
||||
frame[1] = 126;
|
||||
frame.writeUInt16BE(payloadLength, 2);
|
||||
payload.copy(frame, 4);
|
||||
} else {
|
||||
throw new Error('Payload too large');
|
||||
}
|
||||
|
||||
return frame;
|
||||
}
|
||||
|
||||
// Enhanced message processing function
|
||||
function processTrainingMessage(message, timestamp) {
|
||||
@@ -443,13 +466,15 @@ req.on('upgrade', (res, socket, head) => {
|
||||
const pingInterval = setInterval(() => {
|
||||
if (socket.writable && !jobCompleted) {
|
||||
try {
|
||||
const pingFrame = Buffer.from([0x89, 0x00]);
|
||||
socket.write(pingFrame);
|
||||
// Send JSON ping message instead of binary frame
|
||||
const pingMessage = JSON.stringify({ type: 'ping' });
|
||||
const textFrame = createTextFrame(pingMessage);
|
||||
socket.write(textFrame);
|
||||
} catch (e) {
|
||||
// Ignore ping errors
|
||||
}
|
||||
}
|
||||
}, 5000); // Ping every 5 seconds
|
||||
}, 5000);
|
||||
|
||||
// Heartbeat check - ensure we're still receiving messages
|
||||
const heartbeatInterval = setInterval(() => {
|
||||
|
||||
Reference in New Issue
Block a user