Skip to content

Commit

Permalink
Simple p2p test
Browse files Browse the repository at this point in the history
  • Loading branch information
pldubouilh committed Feb 23, 2018
1 parent fd2fa14 commit f49b641
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 2 deletions.
11 changes: 11 additions & 0 deletions .travis.yml
@@ -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
27 changes: 27 additions & 0 deletions client/fake-video.html
@@ -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>
9 changes: 7 additions & 2 deletions package.json
Expand Up @@ -4,7 +4,9 @@
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "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": [ "keywords": [
"webtorrent", "webtorrent",
Expand Down Expand Up @@ -44,6 +46,9 @@
"yargs": "^11.0.0" "yargs": "^11.0.0"
}, },
"devDependencies": { "devDependencies": {
"standard": "^11.0.0" "concurrently": "^3.5.1",
"puppeteer": "^1.1.0",
"standard": "^11.0.0",
"tape": "^4.9.0"
} }
} }
43 changes: 43 additions & 0 deletions tests/test.js
@@ -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.