Skip to content

Commit

Permalink
Limit to one connection, other corrections, touch #456.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulDalek committed Jun 13, 2024
1 parent 8f88732 commit f1262ec
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 28 deletions.
4 changes: 2 additions & 2 deletions dist/index.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.esm.js.map

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions lib/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import multer from 'multer';

import errorHandler from './error.js';
import rateLimit from './rate_limit.js';
import webSocket from './web_socket.js';
import { init as webSocketInit } from './web_socket.js';
import { log, logWithStack } from '../logger.js';
import { __dirname } from '../utils.js';

Expand Down Expand Up @@ -118,8 +118,10 @@ export const startServer = async (serverConfig) => {
`[server] Started HTTP server on ${serverConfig.host}:${serverConfig.port}.`
);

// Start a WebSocket connection
webSocket.init({ ...httpServer.address(), protocol: 'http' });
if (activeServers.size === 1) {
// Start a WebSocket connection
webSocketInit({ ...httpServer.address(), protocol: 'http' });
}
});
}

Expand Down Expand Up @@ -164,8 +166,10 @@ export const startServer = async (serverConfig) => {
`[server] Started HTTPS server on ${serverConfig.host}:${serverConfig.ssl.port}.`
);

// Start a WebSocket connection
webSocket.init({ ...httpsServer.address(), protocol: 'https' });
if (activeServers.size === 1) {
// Start a WebSocket connection
webSocketInit({ ...httpsServer.address(), protocol: 'https' });
}
});
}
}
Expand Down
7 changes: 2 additions & 5 deletions lib/server/web_socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const webSocketClients = new Map();
* @param {object} address - Object that contains, address and port of enabled
* HTTP or HTTPS server.
*/
function init(address) {
export function init(address) {
webSocketOptions = getOptions().webSocket;
if (webSocketOptions.enable === true) {
// Options for the WebSocket connection
Expand All @@ -55,7 +55,7 @@ function init(address) {
// Options for the WebSocket client
const clientOptions = {
id: uuid(),
reconnect: false,
reconnect: webSocketOptions.reconnect,
reconnectTry: 0,
reconnectInterval: null,
pingTimeout: null
Expand Down Expand Up @@ -156,9 +156,6 @@ function connect(webSocketUrl, connectionOptions, clientOptions) {
reconnect(webSocketUrl, connectionOptions, clientOptions);
}
}, webSocketOptions.pingTimeout);

// Register timeout for the later clearing
addTimer(clientOptions.pingTimeout);
});
}

Expand Down
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"eslint-plugin-prettier": "^5.1.3",
"husky": "^9.0.11",
"jest": "^29.7.0",
"lint-staged": "^15.2.6",
"lint-staged": "^15.2.7",
"nodemon": "^3.1.3",
"prettier": "^3.3.2",
"rollup": "^4.18.0"
Expand Down

0 comments on commit f1262ec

Please sign in to comment.