diff --git a/types/webtorrent/index.d.ts b/types/webtorrent/index.d.ts index 4ad92f297f..01770e7aa7 100644 --- a/types/webtorrent/index.d.ts +++ b/types/webtorrent/index.d.ts @@ -1,6 +1,8 @@ -// Type definitions for WebTorrent 0.98 +// Type definitions for WebTorrent 0.107 // Project: https://github.com/feross/webtorrent, https://webtorrent.io -// Definitions by: Bazyli Brzóska , Tomasz Łaziuk +// Definitions by: Bazyli Brzóska +// Tomasz Łaziuk +// Gabriel Juchault // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -74,6 +76,10 @@ declare namespace WebTorrent { readonly files: TorrentFile[]; + readonly announce: string[]; + + readonly pieces: Array; + readonly timeRemaining: number; readonly received: number; @@ -90,14 +96,32 @@ declare namespace WebTorrent { readonly ratio: number; + readonly length: number; + + readonly pieceLength: number; + + readonly lastPieceLength: number; + readonly numPeers: number; readonly path: string; readonly ready: boolean; + readonly paused: boolean; + + readonly done: boolean; + readonly name: string; + readonly created: Date; + + readonly createdBy: string; + + readonly comment: string; + + readonly maxWebConns: number; + destroy(cb?: (err: Error | string) => void): void; addPeer(peer: string | SimplePeer): boolean; @@ -160,6 +184,12 @@ declare namespace WebTorrent { getBlobURL(callback: (err: string | Error | undefined, blobURL?: string) => void): void; } + + interface TorrentPiece { + readonly length: number; + + readonly missing: number; + } } export = WebTorrent; diff --git a/types/webtorrent/webtorrent-tests.ts b/types/webtorrent/webtorrent-tests.ts index 63a9647902..f7f4ca0872 100644 --- a/types/webtorrent/webtorrent-tests.ts +++ b/types/webtorrent/webtorrent-tests.ts @@ -8,6 +8,32 @@ client.add(magnetURI, {}, torrent => { // Got torrent metadata! console.log('Client is downloading:', torrent.infoHash); + console.log( + torrent.maxWebConns, + torrent.ready, + torrent.paused, + torrent.done, + torrent.created, + torrent.createdBy, + torrent.comment, + ); + + torrent.announce.forEach(announce => console.log(announce)); + + console.log(torrent.length, torrent.pieceLength, torrent.lastPieceLength); + console.log( + torrent.pieces.reduce( + (acc, piece) => acc + (piece ? piece.length : 0), + 0, + ), + ); + console.log( + torrent.pieces.reduce( + (acc, piece) => acc + (piece ? piece.missing : 0), + 0, + ), + ); + torrent.files.forEach(file => { // Display the file by appending it to the DOM. Supports video, audio, images, and // more. Specify a container element (CSS selector or reference to DOM node).