Skip to content

Commit 07f8878

Browse files
authored
Update main.js
1 parent 77789ee commit 07f8878

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

main.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"id": "liveserver",
1414
"name": "Live Server",
1515
"main": "main.js",
16-
"version": "2.0.0",
16+
"version": "2.0.1",
1717
"readme": "readme.md",
1818
"icon": "icon.png",
1919
"files": [],
@@ -362,7 +362,7 @@
362362
jsonData.fileName = fileName;
363363
if (!jsonData.port) {
364364
(async () => {
365-
let livePort = await getLivePortIfAvailable();
365+
let livePort = await getLivePortIfAvilable();
366366
if (livePort) {
367367
console.log(`live port gotten its ${livePort}`)
368368
jsonData.port = livePort;
@@ -547,34 +547,36 @@
547547
}
548548
}
549549

550-
async function getLivePortIfAvailable(timeout = 1000) {
551-
const portList = [1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034];
552-
553-
for (const port of portList) {
550+
async function getLivePortIfAvilable(timeout = 1000) {
551+
let portList = [1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034];
552+
for (let port of portList) {
554553
const controller = new AbortController();
555554
const signal = controller.signal;
556555

557-
// Set timeout to abort fetch
558-
const timer = setTimeout(() => controller.abort(), timeout);
556+
// Set a timeout to abort the fetch
557+
const timer = setTimeout(() => {
558+
controller.abort();
559+
}, timeout);
559560

560561
try {
561562
const response = await fetch(`http://localhost:${port}/check`, {
562563
method: 'GET',
563564
signal: signal
564565
});
566+
clearTimeout(timer);
565567

566-
clearTimeout(timer); // Clear timer on success/failure
567568
if (response.ok) {
568-
this.isServerOnline = true;
569-
return port; // Return live port
569+
return port;
570570
}
571571
} catch (err) {
572-
clearTimeout(timer); //clear timer
572+
clearTimeout(timer);
573+
// console.log(`Port ${port} failed or timed out:`, err.message);
574+
// console.clear()
573575
}
574576
}
575-
576-
return null; // No live port found
577+
return null;
577578
}
579+
578580

579581

580582
////////////////////))/))////ll/)//////////////
@@ -668,4 +670,4 @@
668670
i.destroy();
669671
});
670672
}
671-
})();
673+
})();

0 commit comments

Comments
 (0)