From 1449c51d43fc6d63b90e11be990e8a804c92637a Mon Sep 17 00:00:00 2001 From: Zhao Xiaohong Date: Tue, 12 Mar 2024 14:14:20 +0800 Subject: [PATCH] optional chaining --- local.js | 14 +++++--------- server.js | 8 ++------ 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/local.js b/local.js index b23f779..b46d916 100644 --- a/local.js +++ b/local.js @@ -251,9 +251,8 @@ var server = net.createServer(function (connection) { connection.on('end', function () { console.log('local disconnected'); - if (ws) { - ws.terminate(); - } + ws?.terminate(); + server.getConnections(function (err, count) { console.log('concurrent connections:', count); }); @@ -261,9 +260,8 @@ var server = net.createServer(function (connection) { connection.on('error', function (e) { console.log(`local error: ${e}`); - if (ws) { - ws.terminate(); - } + ws?.terminate(); + server.getConnections(function (err, count) { console.log('concurrent connections:', count); }); @@ -272,9 +270,7 @@ var server = net.createServer(function (connection) { connection.setTimeout(timeout, function () { console.log('local timeout'); connection.destroy(); - if (ws) { - ws.terminate(); - } + ws?.terminate(); }); }); diff --git a/server.js b/server.js index ede36be..42d9b90 100644 --- a/server.js +++ b/server.js @@ -170,17 +170,13 @@ wss.on('connection', function (ws) { ws.on('close', function () { console.log('server disconnected'); console.log('concurrent connections:', wss.clients.size); - if (remote) { - remote.destroy(); - } + remote?.destroy(); }); ws.on('error', function (e) { console.warn(`server: ${e}`); console.log('concurrent connections:', wss.clients.size); - if (remote) { - remote.destroy(); - } + remote?.destroy(); }); });