diff --git a/webtorrent/index.d.ts b/webtorrent/index.d.ts index 074adccb74..207015f871 100644 --- a/webtorrent/index.d.ts +++ b/webtorrent/index.d.ts @@ -5,9 +5,10 @@ /// -import * as ParseTorrent from 'parse-torrent'; -import * as SimplePeer from 'simple-peer'; -import * as http from 'http'; +import { Instance as ParseTorrent } from 'parse-torrent'; +import { Instance as SimplePeer } from 'simple-peer'; +import { RequestOptions, Server } from 'http'; +import { Wire } from 'bittorrent-protocol'; declare const WebTorrent: WebTorrent.WebTorrent; @@ -32,14 +33,15 @@ declare namespace WebTorrent { maxWebConns?: number; path?: string; store?: (chunkLength: number, storeOpts: { length: number, files: File[], torrent: Torrent, }) => any; + name?: string; } export interface Instance extends NodeJS.EventEmitter { on(event: 'torrent', callback: (torrent: Torrent) => void): this; on(event: 'error', callback: (err: Error | string) => void): this; - add(torrent: string | Buffer | ParseTorrent.Instance, opts?: TorrentOptions, cb?: (torrent: Torrent) => any): Torrent; - add(torrent: string | Buffer | ParseTorrent.Instance, cb?: (torrent: Torrent) => any): Torrent; + add(torrent: string | Buffer | ParseTorrent, opts?: TorrentOptions, cb?: (torrent: Torrent) => any): Torrent; + add(torrent: string | Buffer | ParseTorrent, cb?: (torrent: Torrent) => any): Torrent; seed(input: string | string[] | File | File[] | FileList | Buffer | Buffer[] | NodeJS.ReadableStream | NodeJS.ReadableStream[], opts?: TorrentOptions, cb?: (torrent: Torrent) => any): Torrent; seed(input: string | string[] | File | File[] | FileList | Buffer | Buffer[] | NodeJS.ReadableStream | NodeJS.ReadableStream[], cb?: (torrent: Torrent) => any): Torrent; @@ -92,19 +94,23 @@ declare namespace WebTorrent { readonly path: string; + readonly ready: boolean; + + readonly name: string; + destroy(cb?: (err: Error | string) => void): void; - addPeer(peer: string | SimplePeer.Instance): boolean; + addPeer(peer: string | SimplePeer): boolean; addWebSeed(url: string): void; - removePeer(peer: string | SimplePeer.Instance): void; + removePeer(peer: string | SimplePeer): void; select(start: number, end: number, priority?: number, notify?: () => void): void; deselect(start: number, end: number, priority: number): void; - createServer(opts?: http.RequestOptions): http.Server; + createServer(opts?: RequestOptions): Server; pause(): void; @@ -112,13 +118,11 @@ declare namespace WebTorrent { on(event: 'infoHash' | 'metadata' | 'ready' | 'done', callback: () => void): this; - on(event: 'warning' | 'error', callback: (err: Error | string) => void): this; on(event: 'download' | 'upload', callback: (bytes: number) => void): this; - // TODO: wire is a bittorrent-protocol instance - on(event: 'wire', callback: (wire: any, addr?: string) => void): this; + on(event: 'wire', callback: (wire: Wire, addr?: string) => void): this; on(event: 'noPeers', callback: (announceType: 'tracker' | 'dht') => void): this; } diff --git a/webtorrent/webtorrent-tests.ts b/webtorrent/webtorrent-tests.ts index 895d734817..ba08944d58 100644 --- a/webtorrent/webtorrent-tests.ts +++ b/webtorrent/webtorrent-tests.ts @@ -52,7 +52,6 @@ client.add(magnetURI, {}, function(torrent) { torrent.on('wire', function(wire, addr) { console.log('connected to peer with address ' + addr); - wire.use(); }); });