From 5a1e852204023a4027259065348da69752459afa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20=C5=81aziuk?= Date: Tue, 7 Feb 2017 10:32:18 +0100 Subject: [PATCH 1/2] add undocumented properties --- webtorrent/index.d.ts | 26 +++++++++++++++----------- webtorrent/webtorrent-tests.ts | 1 - 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/webtorrent/index.d.ts b/webtorrent/index.d.ts index 074adccb74..554094421e 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; @@ -59,6 +61,8 @@ declare namespace WebTorrent { readonly progress: number; readonly ratio: number; + + readonly name: string; } export interface Torrent extends NodeJS.EventEmitter { @@ -92,19 +96,21 @@ declare namespace WebTorrent { readonly path: string; + readonly ready: boolean; + 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(); }); }); From a8aab5614bb014c0302982d88185deaf59dcc5f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20=C5=81aziuk?= Date: Tue, 7 Feb 2017 10:58:02 +0100 Subject: [PATCH 2/2] fix --- webtorrent/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webtorrent/index.d.ts b/webtorrent/index.d.ts index 554094421e..207015f871 100644 --- a/webtorrent/index.d.ts +++ b/webtorrent/index.d.ts @@ -61,8 +61,6 @@ declare namespace WebTorrent { readonly progress: number; readonly ratio: number; - - readonly name: string; } export interface Torrent extends NodeJS.EventEmitter { @@ -98,6 +96,8 @@ declare namespace WebTorrent { readonly ready: boolean; + readonly name: string; + destroy(cb?: (err: Error | string) => void): void; addPeer(peer: string | SimplePeer): boolean;