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

Receivers: Fixed disconnection notification on connection

This commit is contained in:
Michael Hollister 2025-04-25 09:57:49 -05:00
parent a5fc61fd85
commit 55355a3c57
2 changed files with 9 additions and 4 deletions

View file

@ -53,7 +53,7 @@ export class TcpListenerService {
}
private handleConnection(socket: net.Socket) {
Main.logger.info(`new connection from ${socket.remoteAddress}:${socket.remotePort}`);
Main.logger.info(`New connection from ${socket.remoteAddress}:${socket.remotePort}`);
const session = new FCastSession(socket, (data) => socket.write(data));
session.bindEvents(this.emitter);
@ -97,11 +97,16 @@ export class TcpListenerService {
if (index != -1) {
this.sessions.splice(index, 1);
}
this.emitter.emit('disconnect', { id: connectionId, type: 'tcp', data: { address: socket.remoteAddress, port: socket.remotePort }});
if (!this.sessions.some(e => e.socket.remoteAddress === socket.remoteAddress)) {
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 }});
// Sometimes the sender may reconnect under a different port, so suppress connect/disconnect event emission
if (!this.sessions.some(e => e.socket.remoteAddress === socket.remoteAddress)) {
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 });

View file

@ -16,7 +16,7 @@ window.addEventListener('resize', (event) => calculateQRCodeWidth());
// Window might be re-created while devices are still connected
window.targetAPI.onPing((_event, value: any) => {
if (value && connections.length === 0) {
if (value && !connections.includes(value.id)) {
connections.push(value.id);
onConnect(value.id);
}