✨ 支持自定义客户端端口

This commit is contained in:
chaos-zhu
2024-10-13 23:38:59 +08:00
parent e784092c1a
commit da36ed9d1b
6 changed files with 19 additions and 21 deletions
+3 -3
View File
@@ -1,7 +1,7 @@
const { Server: ServerIO } = require('socket.io')
const { io: ClientIO } = require('socket.io-client')
const { readHostList } = require('../utils/storage')
const { clientPort } = require('../config')
const { clientDefaultPort } = require('../config')
const { verifyAuthSync } = require('../utils/verify-auth')
const { isAllowedIp } = require('../utils/tools')
@@ -15,9 +15,9 @@ async function getClientsInfo(clientSockets) {
if (!hostList.some(item => item.host === clientItem.host)) clientItem.close && clientItem.close()
})
hostList
.map(({ host, name }) => {
.map(({ host, name, clientPort }) => {
if (clientSockets.some(item => item.host === host)) return { name, isIo: true } // 已经建立io连接(无论是否连接成功)的host不再重复建立连接,因为存在多次(reconnectionAttempts)的重试机制
let clientSocket = ClientIO(`http://${ host }:${ clientPort }`, {
let clientSocket = ClientIO(`http://${ host }:${ clientPort || clientDefaultPort }`, {
path: '/client/os-info',
forceNew: true,
timeout: 5000,