Permalink
Browse files

Simple p2p test

  • Loading branch information...
pldubouilh committed Feb 23, 2018
1 parent fd2fa14 commit f49b641d98cf267601407295e2c43c10426d2df0
Showing with 88 additions and 2 deletions.
  1. +11 −0 .travis.yml
  2. +27 −0 client/fake-video.html
  3. +7 −2 package.json
  4. +43 −0 tests/test.js
View
@@ -0,0 +1,11 @@
language: node_js
node_js:
- "8.1.3"
cache:
directories:
- node_modules
install:
- npm install
script:
- npm run lint
- npm run test
View
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>live-torrent demo</title>
</head>
<body> <h1>Tests</h1> </body>
<script src="./build.js"></script>
<script>
const chunksDone = {}
const dlManifest = async () => {
const m = await fetch('manifest.m3u8')
const t = await m.text()
const last = t.split('\n').filter(l => l.includes('http://'))[2]
if (chunksDone[last]) return
chunksDone[last] = true
fetch(last)
}
dlManifest()
setInterval(dlManifest, 2000)
</script>
</html>
View
@@ -4,7 +4,9 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "browserify client/loader.js -o client/build.js && node cli.js -u http://wms.shared.streamshow.it/carinatv/carinatv/ -p playlist.m3u8"
"start": "browserify client/loader.js -o client/build.js && node cli.js -u http://wms.shared.streamshow.it/carinatv/carinatv/ -p playlist.m3u8",
"lint": "standard .",
"test": "concurrently -s first --kill-others \"npm run start &>/dev/null\" \"sleep 5 && node tests/test.js\""
},
"keywords": [
"webtorrent",
@@ -44,6 +46,9 @@
"yargs": "^11.0.0"
},
"devDependencies": {
"standard": "^11.0.0"
"concurrently": "^3.5.1",
"puppeteer": "^1.1.0",
"standard": "^11.0.0",
"tape": "^4.9.0"
}
}
View
@@ -0,0 +1,43 @@
const puppeteer = require('puppeteer')
const test = require('tape')
const url = 'http://127.0.0.1:8008/fake-video.html'
const sleep = t => new Promise(resolve => setTimeout(resolve, t))
async function testp2p (t) {
t.plan(1)
// Spawn first chrome
const browser1 = await puppeteer.launch({ headless: true, args: ['--no-sandbox'] })
const page1 = await browser1.newPage()
await page1.goto(url)
await sleep(6000)
// Spawn second chrome
const browser2 = await puppeteer.launch({ headless: true, args: ['--no-sandbox'] })
const page2 = await browser2.newPage()
let p2p = false
page2.on('console', msg => {
console.log(msg.text())
p2p = msg.text().includes('P2P Download') || msg.text().includes('P2P Upload') ? true : p2p
})
await page2.goto(url)
await sleep(30000)
// Cleanup
await browser1.close()
await browser2.close()
console.log(' ')
t.true(p2p, 'browsers exchanged content between each-others 👏')
t.end()
}
const doTest = async () => {
test('Test p2p between 2 browsers\n', testp2p)
}
doTest()

0 comments on commit f49b641

Please sign in to comment.