1
0
Fork 0
mirror of https://gitlab.com/futo-org/fcast.git synced 2025-06-24 21:25:23 +00:00

Receivers: Fixed connection monitor heartbeat

This commit is contained in:
Michael Hollister 2025-05-01 14:22:43 -05:00
parent e8be1a5735
commit 2776bc398e
2 changed files with 6 additions and 4 deletions

View file

@ -41,12 +41,13 @@ export class ConnectionMonitor {
setInterval(() => {
if (ConnectionMonitor.backendConnections.size > 0) {
for (const sessionId in ConnectionMonitor.backendConnections) {
for (const sessionId of ConnectionMonitor.backendConnections.keys()) {
if (ConnectionMonitor.heartbeatRetries.get(sessionId) > 3) {
ConnectionMonitor.logger.warn(`Could not ping device with connection id ${sessionId}. Disconnecting...`);
ConnectionMonitor.backendConnections.get(sessionId).disconnect(sessionId);
}
ConnectionMonitor.logger.debug(`Pinging session ${sessionId} with ${ConnectionMonitor.heartbeatRetries.get(sessionId)} retries left`);
ConnectionMonitor.backendConnections.get(sessionId).send(Opcode.Ping, null);
ConnectionMonitor.heartbeatRetries.set(sessionId, ConnectionMonitor.heartbeatRetries.get(sessionId) === undefined ? 1 : ConnectionMonitor.heartbeatRetries.get(sessionId) + 1);
}
@ -58,7 +59,8 @@ export class ConnectionMonitor {
}
public static onPingPong(value: any) {
ConnectionMonitor.heartbeatRetries[value.sessionId] = 0;
ConnectionMonitor.logger.debug(`Received response from ${value.sessionId}`);
ConnectionMonitor.heartbeatRetries.set(value.sessionId, 0);
}
public static onConnect(listener: any, value: any) {

View file

@ -35,7 +35,7 @@ export class FCastSession {
send(opcode: number, message = null) {
const json = message ? JSON.stringify(message) : null;
logger.info(`send (opcode: ${opcode}, body: ${json})`);
logger.info(`send: (session: ${this.sessionId}, opcode: ${opcode}, body: ${json})`);
let data: Uint8Array;
if (json) {
@ -164,7 +164,7 @@ export class FCastSession {
}
private handlePacket(opcode: number, body: string | undefined) {
logger.info(`handlePacket (opcode: ${opcode}, body: ${body})`);
logger.info(`handlePacket: (session: ${this.sessionId}, opcode: ${opcode}, body: ${body})`);
try {
switch (opcode) {