Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for testing #7

Merged
merged 1 commit into from Mar 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/fake-video.html
Expand Up @@ -13,7 +13,7 @@
const chunksDone = {}
const manifestName = 'manifest.m3u8'
const manifestURL = 'http://127.0.0.1:8008/'
const chunksLocation = 'https://live.computer/'
const chunksLocation = ''

const dlManifest = async () => {
const m = await fetch(manifestURL + manifestName)
Expand Down
17 changes: 6 additions & 11 deletions lib/wtManifest.js
Expand Up @@ -17,6 +17,7 @@ function wtManifest (fullManifestPath = '', makeFromFolder = '', delay, loop = f

// Torrent from local folder
if (this.isLocalStream) {
this.chunksLoc = ''
this.localPath = addTrailingSlash(makeFromFolder)
this.sm = makeFromFolder ? new StreamMaker(makeFromFolder, delay, loop) : null
} else {
Expand All @@ -42,7 +43,7 @@ wtManifest.prototype.computeMagnet = function (file, cn) {
createTorrent(file, { announceList: this.announceList }, (err, t) => {
if (err) return console.log(err)
const magnet = parseTorrent.toMagnetURI(parseTorrent(t))
resolve('###' + magnet + '\n')
resolve(magnet)
})
})
}
Expand All @@ -54,19 +55,13 @@ wtManifest.prototype.makeMagnet = async function (f) {
if (self.fileToMagnet[cn]) return

// Fetch payload and compute magnet
let payload
if (self.isLocalStream) {
payload = await fs.readFile(self.localPath + f)
} else {
// Use url if one's been provided. Otherwise use chunksLoc
const url = isUrl(f) ? f : self.chunksLoc + removeDanglingSlash(f)
payload = await request(url, { encoding: null })
}
const url = isUrl(f) ? f : self.chunksLoc + removeDanglingSlash(f)
const payload = self.isLocalStream ? await fs.readFile(self.localPath + f) : await request(url, { encoding: null })

const magnet = await self.computeMagnet(payload, cn)

// Store magnet computed
self.fileToMagnet[cn] = magnet
self.fileToMagnet[cn] = '###' + magnet + '\n' + url
self.magnetsOrder.push(cn)

if (self.magnetsOrder.length > 10) {
Expand Down Expand Up @@ -97,7 +92,7 @@ wtManifest.prototype.makeManifest = async function (manifest) {
await self.makeAllMagnets(files)

// Pop manifest back, inject magnet links alongside TS files
self.manifest = split.map(l => l.includes('.ts') ? self.fileToMagnet[chunkName(l)] + l : l).join('\n')
self.manifest = split.map(l => l.includes('.ts') ? self.fileToMagnet[chunkName(l)] : l).join('\n')
self.sequence = sequence
return self.manifest
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "live-torrent",
"version": "0.0.4",
"version": "0.0.5",
"description": "",
"main": "index.js",
"scripts": {
Expand Down