|
|
@ -1,3 +1,4 @@ |
|
|
|
import { InternalService } from "@autoplex/microservice"; |
|
|
|
import assert from "assert"; |
|
|
|
import MagnetUri from "magnet-uri"; |
|
|
|
import WebTorrent from "webtorrent-hybrid"; |
|
|
@ -6,7 +7,7 @@ import { extname, join, sep } from "path"; |
|
|
|
import Torrent from "../database/entities/Torrent"; |
|
|
|
import rimraf from "rimraf"; |
|
|
|
import { ISerializedTorrent, TorrentState } from "../common"; |
|
|
|
import { EventEmitter } from "events"; |
|
|
|
import { Database } from "."; |
|
|
|
|
|
|
|
interface IAddOptions { |
|
|
|
downloadPath?: string; |
|
|
@ -32,7 +33,7 @@ export declare interface TorrentClient { |
|
|
|
): this; |
|
|
|
} |
|
|
|
|
|
|
|
export class TorrentClient extends EventEmitter |
|
|
|
export class TorrentClient extends InternalService |
|
|
|
{ |
|
|
|
/** |
|
|
|
* The current WebTorrent instance (available after boot) |
|
|
@ -41,6 +42,16 @@ export class TorrentClient extends EventEmitter |
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/** |
|
|
|
* The service name |
|
|
|
*/ |
|
|
|
public get name() { |
|
|
|
return "Torrent Client" |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Boot the service |
|
|
|
*/ |
|
|
|
public async boot() { |
|
|
|
this.__webtorrent = new WebTorrent(); |
|
|
|
|
|
|
@ -53,8 +64,14 @@ export class TorrentClient extends EventEmitter |
|
|
|
torrent.on("noPeers", (...args) => this.onTorrentNoPeers(torrent, ...args)); |
|
|
|
torrent.on("wire", (...args) => this.onTorrentWire(torrent, ...args)); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
await this.loadTorrents(); |
|
|
|
/** |
|
|
|
* @TODO really this is kinda bad putting this here... |
|
|
|
* Start the torrent client |
|
|
|
*/ |
|
|
|
public start() { |
|
|
|
this.loadTorrents(); |
|
|
|
} |
|
|
|
|
|
|
|
// Event Handling ------------------------------------------------------------------------------
|
|
|
|