Skip to content

Commit 0d1ce2c

Browse files
committed
Fixed unsharing an item
Signed-off-by: Robert Gogete <[email protected]>
1 parent 4001472 commit 0d1ce2c

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

src/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class FileClient extends EventEmitter implements IFileClient {
5454
super(); // Call EventEmitter constructor
5555

5656
// Increase max listeners to prevent warnings during testing/multiple usage
57-
this.setMaxListeners(20);
57+
this.setMaxListeners(0);
5858

5959
this.options = {
6060
peers: options.peers || ["http://dig-relay-prod.eba-2cmanxbe.us-east-1.elasticbeanstalk.com/gun"],
@@ -322,7 +322,7 @@ export class FileClient extends EventEmitter implements IFileClient {
322322
this.webTorrentClient = new WebTorrent();
323323

324324
// Increase max listeners for the WebTorrent client to prevent warnings
325-
this.webTorrentClient.setMaxListeners(20);
325+
this.webTorrentClient.setMaxListeners(0);
326326

327327
// Log client status (using safe property access)
328328
this.logger.debug(`🔧 WebTorrent client created:`, {

src/host.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -628,11 +628,7 @@ export class FileHost implements IFileHost {
628628
if (this.webTorrentClient && this.magnetUris.has(filename)) {
629629
try {
630630
const magnetURI = this.magnetUris.get(filename);
631-
const torrent = this.webTorrentClient.get(magnetURI!);
632-
if (torrent && typeof torrent === "object" && "destroy" in torrent) {
633-
(torrent as { destroy(): void }).destroy();
634-
this.logger.debug(`🧲 Stopped WebTorrent seeding for ${filename}`);
635-
}
631+
this.webTorrentClient.remove(magnetURI!);
636632
this.magnetUris.delete(filename);
637633
} catch (error) {
638634
this.logger.warn(`⚠️ Error stopping WebTorrent seeding:`, error);

tests/host.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ const mockWebTorrentInstance = {
4444
get: jest.fn(),
4545
destroy: jest.fn(),
4646
on: jest.fn(),
47-
setMaxListeners: jest.fn()
47+
setMaxListeners: jest.fn(),
48+
add: jest.fn(),
49+
remove: jest.fn()
4850
};
4951

5052
// Mock torrent
@@ -432,8 +434,7 @@ describe('FileHost', () => {
432434

433435
host.unshareFile(filename);
434436

435-
expect(mockWebTorrentInstance.get).toHaveBeenCalledWith(mockTorrent.magnetURI);
436-
expect(mockTorrentInstance.destroy).toHaveBeenCalled();
437+
expect(mockWebTorrentInstance.remove).toHaveBeenCalled();
437438
}, 10000);
438439
});
439440

0 commit comments

Comments
 (0)