mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-12 03:56:15 -08:00
fix: replace deprecated substr() and fix MPV IPC timeout handling
- Use manual time calculation instead of fragile toISOString().substr() - Explicitly resolve null on MPV IPC timeout to prevent hanging promises - Clear timeout handle in all event paths to prevent races Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9cd278256b
commit
1df371b163
2 files changed
+17
-17
No files matched your search
@@ -87,15 +87,20 @@ async function getMpvProperty(
|
||||
client.write(request);
|
||||
});
|
||||
|
||||
const timeoutHandle = setTimeout(() => {
|
||||
client.destroy();
|
||||
resolve(null);
|
||||
}, 2000);
|
||||
|
||||
client.on('data', (chunk) => {
|
||||
data += chunk.toString();
|
||||
if (data.includes('\n')) {
|
||||
clearTimeout(timeoutHandle);
|
||||
try {
|
||||
const lines = data.split('\n');
|
||||
for (const line of lines) {
|
||||
if (!line.trim()) continue;
|
||||
const response = JSON.parse(line);
|
||||
// console.log('[PlayerEvents] MPV IPC response:', response);
|
||||
if (response.data !== undefined) {
|
||||
client.destroy();
|
||||
resolve(response.data);
|
||||
@@ -103,17 +108,17 @@ async function getMpvProperty(
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// console.error('[PlayerEvents] MPV IPC parse error:', e, data);
|
||||
// ignore parse errors
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
client.on('end', () => {
|
||||
clearTimeout(timeoutHandle);
|
||||
// Fallback if no newline was detected but connection closed
|
||||
if (data && !data.includes('\n')) {
|
||||
try {
|
||||
try {
|
||||
const response = JSON.parse(data);
|
||||
// console.log('[PlayerEvents] MPV IPC response (end):', response);
|
||||
resolve(response.data ?? null);
|
||||
} catch (e) {
|
||||
resolve(null);
|
||||
@@ -122,15 +127,9 @@ async function getMpvProperty(
|
||||
});
|
||||
|
||||
client.on('error', (err) => {
|
||||
// console.error('[PlayerEvents] MPV IPC error:', err.message);
|
||||
clearTimeout(timeoutHandle);
|
||||
resolve(null);
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
client.destroy();
|
||||
// Don't resolve null here immediately, let the logic handle it or just timeout
|
||||
// resolving null here might race with successful data
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -112,12 +112,13 @@ export class SeasonContainerComponent {
|
||||
suffix = ' left';
|
||||
}
|
||||
|
||||
const date = new Date(0);
|
||||
date.setSeconds(seconds);
|
||||
const timeString = date.toISOString().substr(11, 8);
|
||||
const formatted = timeString.startsWith('00:')
|
||||
? timeString.substr(3)
|
||||
: timeString;
|
||||
const hours = Math.floor(seconds / 3600);
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
const secs = seconds % 60;
|
||||
const formatted = [hours, minutes, secs]
|
||||
.map((n) => String(n).padStart(2, '0'))
|
||||
.filter((v, i) => (i === 0 ? v !== '00' : true))
|
||||
.join(':');
|
||||
return `${formatted}${suffix}`;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user