Skip to content

Commit

Permalink
simulate affected app
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-codes committed Dec 28, 2023
1 parent e43c5b1 commit 3dc4576
Showing 1 changed file with 29 additions and 30 deletions.
59 changes: 29 additions & 30 deletions apps/game-db-updater/src/mqttClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,39 @@ import createDebugger from 'debug'
let mqttClient: AsyncMqttClient

type MqttConnectionOptions = {
host?: string
port?: number
username?: string
password?: string
host?: string
port?: number
username?: string
password?: string
}

const getMqttClient = async (
connectionOptions?: MqttConnectionOptions,
connectionOptions?: MqttConnectionOptions,
): Promise<AsyncMqttClient> => {
const debug = createDebugger('game-db-updater/mqttClient')

if (!mqttClient) {
const host =
connectionOptions?.host ?? process.env.MQTT_HOST ?? 'localhost'
const port =
connectionOptions?.port ??
parseInt(process.env.MQTT_PORT ?? '1883', 10)
const username =
connectionOptions?.username ?? process.env.MQTT_USERNAME ?? ''
const password =
connectionOptions?.password ?? process.env.MQTT_PASSWORD ?? ''

debug(
`Existing MQTT client not found; creating one with the following options: host=${host}, port=${port}, username=${username}`,
)
mqttClient = await connectAsync(`tcp://${host}`, {
password,
port,
username,
})
}

debug('Returning MQTT client')
return mqttClient
const debug = createDebugger('game-db-updater/mqttClient')

if (!mqttClient) {
const host = connectionOptions?.host ?? process.env.MQTT_HOST ?? 'localhost'
const port =
connectionOptions?.port ?? parseInt(process.env.MQTT_PORT ?? '1883', 10)
const username =
connectionOptions?.username ?? process.env.MQTT_USERNAME ?? ''
const password =
connectionOptions?.password ?? process.env.MQTT_PASSWORD ?? ''

debug(
`Existing MQTT client not found; creating one with the following options: host=${host}, port=${port}, username=${username}`,
)
mqttClient = await connectAsync(`tcp://${host}`, {
password,
port,
username,
})
}

debug('Returning MQTT client')

return mqttClient
}

export { getMqttClient }

0 comments on commit 3dc4576

Please sign in to comment.