Skip to content

Commit 06bd4d0

Browse files
committed
fix: add loops to restart
1 parent 6b3ff14 commit 06bd4d0

File tree

3 files changed

+31
-33
lines changed

3 files changed

+31
-33
lines changed

eslint.config.mjs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,32 @@ export default [
2121
...compat.extends('plugin:@typescript-eslint/recommended'),
2222
...compat.extends('airbnb-base/legacy'),
2323
{
24-
plugins: {
25-
'@typescript-eslint': typescriptEslint,
26-
},
24+
plugins: {
25+
'@typescript-eslint': typescriptEslint,
26+
},
2727

28-
languageOptions: {
28+
languageOptions: {
2929
globals: {
30-
...globals.browser,
31-
...Object.fromEntries(Object.entries(globals.commonjs).map(([key]) => [key, 'off'])),
30+
...globals.browser,
31+
...Object.fromEntries(Object.entries(globals.commonjs).map(([key]) => [key, 'off'])),
3232
},
3333

3434
parser: tsParser,
3535
ecmaVersion: 2025,
3636
sourceType: 'module',
3737

3838
parserOptions: {
39-
requireConfigFile: false,
40-
babelOptions: { plugins: ['@typescript-eslint/eslint-plugin'] },
39+
requireConfigFile: false,
40+
babelOptions: { plugins: ['@typescript-eslint/eslint-plugin'] },
4141
},
42-
},
42+
},
4343

44-
rules: {
44+
rules: {
4545
strict: ['error', 'global'],
4646

4747
quotes: ['error', 'single', {
48-
allowTemplateLiterals: true,
49-
avoidEscape: true,
48+
allowTemplateLiterals: true,
49+
avoidEscape: true,
5050
}],
5151

5252
'no-eval': 'off',
@@ -55,7 +55,7 @@ export default [
5555
'no-plusplus': 'off',
5656

5757
'no-unused-vars': ['error', {
58-
argsIgnorePattern: 'client|msg',
58+
argsIgnorePattern: 'client|msg',
5959
}],
6060

6161
'no-await-in-loop': 'off',
@@ -95,7 +95,8 @@ export default [
9595
exports: 'always-multiline',
9696
functions: 'always-multiline',
9797
}],
98+
},
99+
}, {
100+
files: ['tests/**/*', '**/*.d.ts'],
98101
},
99-
}, {
100-
files: ['tests/**/*', '**/*.d.ts'],
101-
}];
102+
];

src/broker.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ export class NatsClient {
5656
throw new Error('NATS client not initialized');
5757
}
5858

59+
setInterval(() => this.page?.reload(), 10 * 60 * 60 * 1000);
60+
5961
return this.#client;
6062
}
6163

@@ -137,23 +139,6 @@ export class NatsClient {
137139
return id;
138140
}
139141

140-
private async toString(something: any): Promise<string> {
141-
if (something instanceof Error) {
142-
return something.constructor.name + ': ' + something.message;
143-
}
144-
if (something instanceof Promise) {
145-
return something.then(toString);
146-
}
147-
if (Array.isArray(something)) {
148-
return something.map(this.toString).join(', ');
149-
}
150-
if (typeof something === 'function' || typeof something === 'symbol') {
151-
return something.toString();
152-
}
153-
154-
return JSON.stringify(something);
155-
}
156-
157142
public parseMessage<T = any>(data: Uint8Array): T {
158143
let message: any;
159144
try {

src/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class Streamer {
2424

2525
private restarting = false;
2626

27+
private restartLoop: NodeJS.Timeout | undefined;
28+
2729
private restartCount = 0;
2830

2931
private clientListener: CDPSession | undefined;
@@ -175,6 +177,16 @@ class Streamer {
175177
Logger.error('FFmpeg error:', (err as Error).message);
176178
});
177179

180+
if (this.restartLoop) {
181+
clearInterval(this.restartLoop);
182+
}
183+
184+
this.restartLoop = setInterval(() => {
185+
this.restartStream().catch((err) => {
186+
Logger.error('Error during restart loop:', (err as Error).message);
187+
});
188+
}, 48 * 60 * 60 * 1000); // Restart every 2 days.
189+
178190
return ffmpeg;
179191
}
180192

0 commit comments

Comments
 (0)