mirror of
https://gitlab.com/futo-org/fcast.git
synced 2025-06-24 21:25:23 +00:00
Changed ping handler handling
This commit is contained in:
parent
9a7924ebce
commit
0d444239f0
3 changed files with 15 additions and 3 deletions
|
@ -70,7 +70,6 @@ export class TcpListenerService {
|
|||
|
||||
heartbeatRetries += 1;
|
||||
session.send(Opcode.Ping);
|
||||
this.emitter.emit('ping', { id: connectionId });
|
||||
} catch (e) {
|
||||
Main.logger.warn(`Error while pinging sender device ${socket.remoteAddress}:${socket.remotePort}.`, e);
|
||||
socket.destroy();
|
||||
|
@ -98,9 +97,16 @@ export class TcpListenerService {
|
|||
this.sessions.splice(index, 1);
|
||||
}
|
||||
this.emitter.emit('disconnect', { id: connectionId, type: 'tcp', data: { address: socket.remoteAddress, port: socket.remotePort }});
|
||||
this.emitter.removeListener('ping', pingListener);
|
||||
});
|
||||
|
||||
this.emitter.emit('connect', { id: connectionId, type: 'tcp', data: { address: socket.remoteAddress, port: socket.remotePort }});
|
||||
const pingListener = (message: any) => {
|
||||
if (!message) {
|
||||
this.emitter.emit('ping', { id: connectionId });
|
||||
}
|
||||
}
|
||||
this.emitter.prependListener('ping', pingListener);
|
||||
|
||||
try {
|
||||
Main.logger.info('Sending version');
|
||||
|
|
|
@ -68,7 +68,6 @@ export class WebSocketListenerService {
|
|||
|
||||
heartbeatRetries += 1;
|
||||
session.send(Opcode.Ping);
|
||||
this.emitter.emit('ping', { id: connectionId });
|
||||
} catch (e) {
|
||||
Main.logger.warn(`Error while pinging sender device ${socket.remoteAddress}:${socket.remotePort}.`, e);
|
||||
socket.destroy();
|
||||
|
@ -102,9 +101,16 @@ export class WebSocketListenerService {
|
|||
this.sessions.splice(index, 1);
|
||||
}
|
||||
this.emitter.emit('disconnect', { id: connectionId, type: 'ws', data: { url: socket.url() }});
|
||||
this.emitter.removeListener('ping', pingListener);
|
||||
});
|
||||
|
||||
this.emitter.emit('connect', { id: connectionId, type: 'ws', data: { url: socket.url() }});
|
||||
const pingListener = (message: any) => {
|
||||
if (!message) {
|
||||
this.emitter.emit('ping', { id: connectionId });
|
||||
}
|
||||
}
|
||||
this.emitter.prependListener('ping', pingListener);
|
||||
|
||||
try {
|
||||
Main.logger.info('Sending version');
|
||||
|
|
|
@ -10,7 +10,7 @@ let connections = [];
|
|||
|
||||
// Window might be re-created while devices are still connected
|
||||
window.targetAPI.onPing((_event, value: any) => {
|
||||
if (connections.length === 0) {
|
||||
if (value && connections.length === 0) {
|
||||
connections.push(value.id);
|
||||
onConnect(value.id);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue