Reference Source
import {Peercat} from './assets/peercat.js'
public class | source

Peercat

Peercat Main Class

This class acts like a singleton most of the time. There is no need to initialize it more than once.

Static Method Summary

Static Public Methods
public static

decrypt(data: string, password: string): string

Decrypt a given string using a given password

public static

encrypt(data: JSON, password: string): string

Encrypt a given string using a given password

public static

generateShareUrl(torrent: Torrent): string

Generate a share URL for other people to download this torrent

public static

Generate a random 256 bytes long password using a buffer

public static

requestDownload(fileName: string, blobUrl: string)

Try to download the file using a newly created anchor tag.

Constructor Summary

Public Constructor
public

Initializing Peercat

Member Summary

Public Members
public

client: WebTorrent

WebTorrent Instance

public

File Uploader Instance

public

Current downloading torrent filename

public

Current downloading torrent identifier

public

Timeout for when a connection to a torrent server could not be made.

Method Summary

Public Methods
public

Build a magnet uri on the current downloading torrent file

public

Load the torrent and add it to the download queue

public

downloadBlob(infoHash: string)

Request to download the blob of a given torrent and try to download it using @see requestDownload

public

onTorrentDownload(torrent: Torrent)

Called when a torrent was added to download queue via URL

public

onTorrentSeed(torrent: Torrent)

Called when a torrent was uploaded through the file dialog

public

Prepares the UI to download a torrent instead of offering one.

public

remove(infoHash: string)

Remove a torrent from peercat This immediately stops sharing a file to torrents and disconnects with all peers.

public

run()

Init peer cat and all UI features

public

showShareModal(torrentIdentifier: Torrent | string): boolean

Show the share modal view and populate it with data

public

update(downloadSide: *)

Update views, progressbars etc.

Static Public Methods

public static decrypt(data: string, password: string): string source

Decrypt a given string using a given password

Params:

NameTypeAttributeDescription
data string

The AES sequence to decrypt

password string

The password to decrypt

Return:

string

The decrypted string

public static encrypt(data: JSON, password: string): string source

Encrypt a given string using a given password

Params:

NameTypeAttributeDescription
data JSON

JSON payload to encrypt

password string

The password used to encrypt

Return:

string

The encrypted string

public static generateShareUrl(torrent: Torrent): string source

Generate a share URL for other people to download this torrent

Params:

NameTypeAttributeDescription
torrent Torrent

the torrent to generate a share url for

Return:

string

The share url for the given torrent

public static randomPassword(): string source

Generate a random 256 bytes long password using a buffer

Return:

string

A sha512 string built by using a randombuffer of 256

public static requestDownload(fileName: string, blobUrl: string) source

Try to download the file using a newly created anchor tag. This may or may not work depending on how long the user waits for his actions. I usually just call this and if the browser blocks it I'm okay with it

Params:

NameTypeAttributeDescription
fileName string
blobUrl string

Public Constructors

public constructor() source

Initializing Peercat

Public Members

public client: WebTorrent source

WebTorrent Instance

public fileUploader: FileUploader source

File Uploader Instance

public filename: string source

Current downloading torrent filename

public infoHash: string source

Current downloading torrent identifier

public torrentTimeout: number source

Timeout for when a connection to a torrent server could not be made.

Public Methods

public buildMagnetUri(): string source

Build a magnet uri on the current downloading torrent file

Return:

string

public download() source

Load the torrent and add it to the download queue

public downloadBlob(infoHash: string) source

Request to download the blob of a given torrent and try to download it using @see requestDownload

Params:

NameTypeAttributeDescription
infoHash string

public onTorrentDownload(torrent: Torrent) source

Called when a torrent was added to download queue via URL

Params:

NameTypeAttributeDescription
torrent Torrent

The torrent that gets downloaded

public onTorrentSeed(torrent: Torrent) source

Called when a torrent was uploaded through the file dialog

Params:

NameTypeAttributeDescription
torrent Torrent

The torrent that gets uploaded

public prepareDownload() source

Prepares the UI to download a torrent instead of offering one.

public remove(infoHash: string) source

Remove a torrent from peercat This immediately stops sharing a file to torrents and disconnects with all peers.

Params:

NameTypeAttributeDescription
infoHash string

The torrents infoHash

public run() source

Init peer cat and all UI features

public showShareModal(torrentIdentifier: Torrent | string): boolean source

Show the share modal view and populate it with data

Params:

NameTypeAttributeDescription
torrentIdentifier Torrent | string

The infohash of the torrent you want to share

Return:

boolean

public update(downloadSide: *) source

Update views, progressbars etc.

Params:

NameTypeAttributeDescription
downloadSide *