1 import * as WebTorrent from 'webtorrent'
3 let webtorrent = new WebTorrent()
5 function immutableAssign <T, U> (target: T, source: U) {
6 return Object.assign<{}, T, U>({}, target, source)
9 // Default interval -> 5 minutes
10 function dateIsValid (dateString: string, interval = 300000) {
11 const dateToCheck = new Date(dateString)
12 const now = new Date()
14 return Math.abs(now.getTime() - dateToCheck.getTime()) <= interval
17 function wait (milliseconds: number) {
18 return new Promise(resolve => setTimeout(resolve, milliseconds))
21 function webtorrentAdd (torrent: string, refreshWebTorrent = false) {
22 if (refreshWebTorrent === true) webtorrent = new WebTorrent()
24 return new Promise<WebTorrent.Torrent>(res => webtorrent.add(torrent, res))
27 // ---------------------------------------------------------------------------