Skip to content

Commit d8d3e7a

Browse files
committed
Increased maximum number of emitters to allow multiple torrents
Signed-off-by: Robert Gogete <[email protected]>
1 parent 548dbe6 commit d8d3e7a

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

examples/test-host.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,20 @@ async function runExample() {
8484

8585
// Re-announce all files every 5 seconds
8686
let announceCount = 0;
87-
const announceInterval = setInterval(async () => {
88-
try {
89-
announceCount++;
90-
console.log(`📢 Re-announcing ${sharedFiles.length} files #${announceCount} at ${new Date().toLocaleTimeString()}`);
87+
// const announceInterval = setInterval(async () => {
88+
// try {
89+
// announceCount++;
90+
// console.log(`📢 Re-announcing ${sharedFiles.length} files #${announceCount} at ${new Date().toLocaleTimeString()}`);
9191

92-
// Re-share all files to trigger re-announcement
93-
for (const fileInfo of sharedFiles) {
94-
await host.shareFile(fileInfo.path);
95-
}
96-
console.log(`✅ All ${sharedFiles.length} files re-announced`);
97-
} catch (error) {
98-
console.error('❌ Error re-announcing files:', error.message);
99-
}
100-
}, 5000); // Every 5 seconds
92+
// // Re-share all files to trigger re-announcement
93+
// for (const fileInfo of sharedFiles) {
94+
// await host.shareFile(fileInfo.path);
95+
// }
96+
// console.log(`✅ All ${sharedFiles.length} files re-announced`);
97+
// } catch (error) {
98+
// console.error('❌ Error re-announcing files:', error.message);
99+
// }
100+
// }, 5000); // Every 5 seconds
101101

102102
// Handle graceful shutdown
103103
process.on('SIGINT', async () => {

src/host.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@ export class FileHost implements IFileHost {
337337
this.logger.debug(`🔄 Initializing WebTorrent client...`);
338338
this.webTorrentClient = new WebTorrent();
339339

340+
// Fix EventEmitter warning when seeding multiple torrents
341+
// WebTorrent reuses a single DHT instance, causing listener count to exceed default limit
342+
this.webTorrentClient.setMaxListeners(0); // Disable limit
343+
this.logger.debug(`🔧 Set WebTorrent maxListeners to unlimited for multiple torrents`);
344+
340345
// Add error handling for the WebTorrent client
341346
this.webTorrentClient.on("error", (err: string | Error) => {
342347
this.logger.error("❌ WebTorrent client error:", err);

0 commit comments

Comments
 (0)