mirror of
https://github.com/jetkvm/cloud-api.git
synced 2025-09-16 08:38:15 +00:00
Add more logging (#32)
* Add more logging * Refactor logging in WebRTC signaling to remove "WS" prefix for consistency
This commit is contained in:
parent
27755874af
commit
dc5aed27e8
@ -75,7 +75,7 @@ async function handleDeviceSocketRequest(
|
||||
// Inflight means that the device has connected, a client has connected to that device via HTTP, and they're now doing the signaling dance
|
||||
if (inFlight.has(device.id)) {
|
||||
console.log(
|
||||
`[Device WS] Device ${device.id} already has an inflight client connection.`,
|
||||
`[Device] Device ${device.id} already has an inflight client connection.`,
|
||||
);
|
||||
return socket.destroy();
|
||||
}
|
||||
@ -83,7 +83,7 @@ async function handleDeviceSocketRequest(
|
||||
// Handle existing connections for this device
|
||||
if (activeConnections.has(device.id)) {
|
||||
console.log(
|
||||
`[Device WS] Device ${device.id} already connected. Terminating existing connection.`,
|
||||
`[Device] Device ${device.id} already connected. Terminating existing connection.`,
|
||||
);
|
||||
activeConnections.get(device.id)?.[0]?.terminate();
|
||||
activeConnections.delete(device.id);
|
||||
@ -107,26 +107,26 @@ async function authenticateDeviceRequest(req: IncomingMessage) {
|
||||
const secretToken = authHeader?.split(" ")?.[1];
|
||||
|
||||
if (!secretToken) {
|
||||
console.log("[Device WS] No authorization header provided.");
|
||||
console.log("[Device] No authorization header provided.");
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const device = await prisma.device.findFirst({ where: { secretToken } });
|
||||
if (!device) {
|
||||
console.log("[Device WS] Invalid secret token provided.");
|
||||
console.log("[Device] Invalid secret token provided.");
|
||||
return null;
|
||||
}
|
||||
|
||||
const id = req.headers["x-device-id"] as string;
|
||||
if (!id || id !== device.id) {
|
||||
console.log("[Device WS] Invalid device ID or ID/token mismatch.");
|
||||
console.log("[Device] Invalid device ID or ID/token mismatch.");
|
||||
return null;
|
||||
}
|
||||
|
||||
return device;
|
||||
} catch (error) {
|
||||
console.error("[Device WS] Error authenticating device:", error);
|
||||
console.error("[Device] Error authenticating device:", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -143,7 +143,7 @@ function setupDeviceWebSocket(deviceWs: WebSocket, device: Device, req: Incoming
|
||||
// Store the connection
|
||||
activeConnections.set(id, [deviceWs, `${ip}`, deviceVersion || null]);
|
||||
console.log(
|
||||
`[Device WS] New connection for device ${id}, with version ${deviceVersion || "unknown"}`,
|
||||
`[Device] New connection for device ${id}, with version ${deviceVersion || "unknown"}`,
|
||||
);
|
||||
|
||||
// Setup ping/pong for connection health checks
|
||||
@ -157,7 +157,7 @@ function setupDeviceWebSocket(deviceWs: WebSocket, device: Device, req: Incoming
|
||||
const checkAliveInterval = setInterval(function checkAlive() {
|
||||
// @ts-ignore
|
||||
if (deviceWs.isAlive === false) {
|
||||
console.log("[Device WS] WS is not alive. Terminating connection.");
|
||||
console.log(`[Device] ${id} is not alive. Terminating connection.`);
|
||||
return deviceWs.terminate();
|
||||
}
|
||||
// @ts-ignore
|
||||
|
||||
@ -71,6 +71,7 @@ export const CreateSession = async (req: express.Request, res: express.Response)
|
||||
);
|
||||
});
|
||||
|
||||
console.log("[CreateSession] got response from device", id);
|
||||
return res.json(JSON.parse(resp.data));
|
||||
} catch (e) {
|
||||
console.log(`Error sending data to kvm with ${id}`, e);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user