Make the ping interval configurable

This commit is contained in:
Jonas Lochmann 2020-03-09 01:00:00 +01:00
parent 0ecb7e4830
commit 2ccdbfdd87
No known key found for this signature in database
GPG key ID: 8B8C9AEE10FA5B36
3 changed files with 10 additions and 4 deletions

View file

@ -68,6 +68,8 @@ This fixes the causes of lint warnings (where possible).
- DISABLE_SIGNUP - DISABLE_SIGNUP
- ``yes`` or ``no`` (default: no) - ``yes`` or ``no`` (default: no)
- disables creating new families if ``yes`` is selected - disables creating new families if ``yes`` is selected
- PING_INTERVAL_SEC
- ping interval at the websocket in seconds
## HTTPS ## HTTPS

View file

@ -15,10 +15,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
// note: soem configuration parameters are read directly at the location where they are used // note: some configuration parameters are read directly at the location where they are used
interface Config { interface Config {
mailWhitelist: Array<string> mailWhitelist: Array<string>
disableSignup: boolean disableSignup: boolean
pingInterval: number
} }
function parseYesNo (value: string) { function parseYesNo (value: string) {
@ -33,5 +34,6 @@ function parseYesNo (value: string) {
export const config: Config = { export const config: Config = {
mailWhitelist: (process.env.MAIL_WHITELIST || '').split(',').map((item) => item.trim()).filter((item) => item.length > 0), mailWhitelist: (process.env.MAIL_WHITELIST || '').split(',').map((item) => item.trim()).filter((item) => item.length > 0),
disableSignup: parseYesNo(process.env.DISABLE_SIGNUP || 'no') disableSignup: parseYesNo(process.env.DISABLE_SIGNUP || 'no'),
pingInterval: parseInt(process.env.PING_INTERVAL_SEC || '25', 10) * 1000
} }

View file

@ -1,6 +1,6 @@
/* /*
* server component for the TimeLimit App * server component for the TimeLimit App
* Copyright (C) 2019 Jonas Lochmann * Copyright (C) 2019 - 2020 Jonas Lochmann
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
@ -17,6 +17,7 @@
import { Server } from 'http' import { Server } from 'http'
import { createApi } from './api' import { createApi } from './api'
import { config } from './config'
import { VisibleConnectedDevicesManager } from './connected-devices' import { VisibleConnectedDevicesManager } from './connected-devices'
import { defaultDatabase, defaultUmzug } from './database' import { defaultDatabase, defaultUmzug } from './database'
import { EventHandler } from './monitoring/eventhandler' import { EventHandler } from './monitoring/eventhandler'
@ -53,7 +54,8 @@ async function main () {
const server = new Server(api) const server = new Server(api)
websocketServer.attach(server, { websocketServer.attach(server, {
serveClient: false serveClient: false,
pingInterval: config.pingInterval
}) })
server.listen(process.env.PORT || 8080) server.listen(process.env.PORT || 8080)