Skip to content

Commit a5527a6

Browse files
committed
Waited for torrent to be created before storeing in gunjs
Signed-off-by: Robert Gogete <gogeterobert@yahoo.com>
1 parent ebc8a6d commit a5527a6

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

examples/test-client.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ async function startClient() {
104104
} else {
105105
console.log(`❌ Direct HTTP not available`);
106106
// Check if there are any magnet URIs to extract file hashes from
107+
console.log(capabilities);
107108
if (capabilities.webTorrent?.magnetUris && capabilities.webTorrent.magnetUris.length > 0) {
108109
const magnetUri = capabilities.webTorrent.magnetUris[0];
109110
console.log('🧲 Found magnet URI:', magnetUri);

src/host.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -477,28 +477,28 @@ export class FileHost implements IFileHost {
477477
reject(new Error('WebTorrent seeding timeout'));
478478
}, 30000); // 30 second timeout for seeding
479479

480-
this.webTorrentClient!.seed(hash, (torrent) => {
480+
this.webTorrentClient!.seed(hash, async (torrent) => {
481481
clearTimeout(seedTimeout);
482482
const magnetURI = torrent.magnetURI;
483483
this.magnetUris.set(hash, magnetURI);
484484
console.log(`🧲 WebTorrent seeding started for ${hash}`);
485485
console.log(` Magnet URI: ${magnetURI}`);
486+
487+
// Update capabilities in Gun.js registry with new magnet URI
488+
if (this.gunRegistry && this.capabilities) {
489+
console.log(`🔄 Updating Gun.js registry with new magnet URI...`);
490+
491+
// Update the current capabilities with the new magnet URI
492+
if (this.capabilities.webTorrent) {
493+
this.capabilities.webTorrent.magnetUris = Array.from(this.magnetUris.values());
494+
}
495+
496+
await this.gunRegistry.register(this.capabilities);
497+
console.log(`✅ Updated Gun.js registry with magnet URI for ${hash}`);
498+
}
486499
resolve();
487500
});
488501
});
489-
490-
// Update capabilities in Gun.js registry with new magnet URI
491-
if (this.gunRegistry && this.capabilities) {
492-
console.log(`🔄 Updating Gun.js registry with new magnet URI...`);
493-
494-
// Update the current capabilities with the new magnet URI
495-
if (this.capabilities.webTorrent) {
496-
this.capabilities.webTorrent.magnetUris = Array.from(this.magnetUris.values());
497-
}
498-
499-
await this.gunRegistry.register(this.capabilities);
500-
console.log(`✅ Updated Gun.js registry with magnet URI for ${hash}`);
501-
}
502502
} catch (error) {
503503
console.warn(`⚠️ Failed to seed file via WebTorrent:`, error);
504504
}

0 commit comments

Comments
 (0)