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:
parent
e8be1a5735
commit
2776bc398e
2 changed files with 6 additions and 4 deletions
|
@ -41,12 +41,13 @@ export class ConnectionMonitor {
|
||||||
|
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
if (ConnectionMonitor.backendConnections.size > 0) {
|
if (ConnectionMonitor.backendConnections.size > 0) {
|
||||||
for (const sessionId in ConnectionMonitor.backendConnections) {
|
for (const sessionId of ConnectionMonitor.backendConnections.keys()) {
|
||||||
if (ConnectionMonitor.heartbeatRetries.get(sessionId) > 3) {
|
if (ConnectionMonitor.heartbeatRetries.get(sessionId) > 3) {
|
||||||
ConnectionMonitor.logger.warn(`Could not ping device with connection id ${sessionId}. Disconnecting...`);
|
ConnectionMonitor.logger.warn(`Could not ping device with connection id ${sessionId}. Disconnecting...`);
|
||||||
ConnectionMonitor.backendConnections.get(sessionId).disconnect(sessionId);
|
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.backendConnections.get(sessionId).send(Opcode.Ping, null);
|
||||||
ConnectionMonitor.heartbeatRetries.set(sessionId, ConnectionMonitor.heartbeatRetries.get(sessionId) === undefined ? 1 : ConnectionMonitor.heartbeatRetries.get(sessionId) + 1);
|
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) {
|
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) {
|
public static onConnect(listener: any, value: any) {
|
||||||
|
|
|
@ -35,7 +35,7 @@ export class FCastSession {
|
||||||
|
|
||||||
send(opcode: number, message = null) {
|
send(opcode: number, message = null) {
|
||||||
const json = message ? JSON.stringify(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;
|
let data: Uint8Array;
|
||||||
if (json) {
|
if (json) {
|
||||||
|
@ -164,7 +164,7 @@ export class FCastSession {
|
||||||
}
|
}
|
||||||
|
|
||||||
private handlePacket(opcode: number, body: string | undefined) {
|
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 {
|
try {
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue