From 35df090d171f376cb5e3d9ba0bf60d2b492c1dba Mon Sep 17 00:00:00 2001 From: Bronwen Date: Wed, 18 Nov 2020 12:02:58 -0500 Subject: [PATCH] forward events from STP --- lib/STP.js | 2 ++ relay/index.js | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/STP.js b/lib/STP.js index c27dd96..08630cc 100644 --- a/lib/STP.js +++ b/lib/STP.js @@ -63,6 +63,8 @@ class STPSocket extends EventEmitter { else this.tcpSocket.on('connect', this.handshake.bind(this)); this.tcpSocket.on('data', this.data.bind(this)); + this.tcpSocket.on('error', (...args) => this.emit('error', ...args)); + this.tcpSocket.on('close', (...args) => this.emit('close', ...args)); } data(evt) { diff --git a/relay/index.js b/relay/index.js index 92f1018..3ff22bf 100644 --- a/relay/index.js +++ b/relay/index.js @@ -22,6 +22,11 @@ let client = null; client = null; setTimeout(tryConnect, 1000); }); + client.on('close', () => { + log.error(`connection closed on ${config.addresses.relay}`) + client = null; + setTimeout(tryConnect, 1000); + }); client.on('data', (data) => { log.debug(data.toString()); }) @@ -55,10 +60,12 @@ app.get('/', (req, res) => {
${client.remoteAddress}
${client.remoteIdentity}
- `)} + `).join('')} `); -}) +}); + +// app.post app.listen(9999);