Skip to content

Commit

Permalink
feat: Add keep-alive agent for HTTP requests
Browse files Browse the repository at this point in the history
  • Loading branch information
KieraDOG committed Aug 9, 2024
1 parent ba4d861 commit b6f21f4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/CGDGarageDoor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Logging } from 'homebridge';
import http from 'http';
import retry from './retry';

const httpAgent = new http.Agent({ keepAlive: true });

interface Status {
lamp: 'on' | 'off';
door: string;
Expand Down Expand Up @@ -61,7 +64,12 @@ export class CGDGarageDoor {
this.log.debug(`Running command: ${cmd}=${value}`);

const { deviceHostname, deviceLocalKey } = this.config;
const response = await fetch(`http://${deviceHostname}/api?key=${deviceLocalKey}&${cmd}=${value}`);
const response = await fetch(`http://${deviceHostname}/api?key=${deviceLocalKey}&${cmd}=${value}`, {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
agent: httpAgent,
});

const data = await response.json();

const level = response.ok ? 'debug' : 'error';
Expand Down

0 comments on commit b6f21f4

Please sign in to comment.