Skip to content

Commit

Permalink
Merge pull request #87 from gentlerainsky/es6
Browse files Browse the repository at this point in the history
convert variable declaration to es6 style
  • Loading branch information
DiegoRBaquero authored Dec 11, 2018
2 parents e44599f + 972a6d9 commit c0e5153
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 31 deletions.
20 changes: 10 additions & 10 deletions examples/node-download.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
// var WebTorrent = require('webtorrent-hybrid')
var WebTorrent = require('../index')
var fs = require('fs')
const WebTorrent = require('../index')
const fs = require('fs')

var client = new WebTorrent()
const client = new WebTorrent()

var torrentId = 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d'
const torrentId = 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d'

console.log('torrentId:\t', torrentId)

client.add(torrentId, torrent => {
var files = torrent.files
var length = files.length
const files = torrent.files
let length = files.length
// Stream each file to the disk
files.forEach(file => {
var source = file.createReadStream()
var destination = fs.createWriteStream(file.name)
const source = file.createReadStream()
const destination = fs.createWriteStream(file.name)
source.on('end', () => {
console.log('file:\t\t', file.name)
// close after all files are saved
if (!--length) process.exit()
length -= 1
if (!length) process.exit()
}).pipe(destination)
})
})
8 changes: 3 additions & 5 deletions examples/node-seed.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// var WebTorrent = require('webtorrent-hybrid')
var WebTorrent = require('../index')
const WebTorrent = require('../index')

var client = new WebTorrent()

var filePath = './node-seed.js'
const client = new WebTorrent()
const filePath = __filename

console.log('filePath:', filePath)

Expand Down
26 changes: 11 additions & 15 deletions lib/global.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
var createTorrent = require('create-torrent')
var ElectronWebRTC = require('electron-webrtc')
const createTorrent = require('create-torrent')
const ElectronWebRTC = require('electron-webrtc')

global.WEBTORRENT_ANNOUNCE = createTorrent.announceList
.map(arr => {
return arr[0]
})
.filter(url => {
return url.indexOf('wss://') === 0 || url.indexOf('ws://') === 0
})
.map(arr => arr[0])
.filter(url => url.indexOf('wss://') === 0 || url.indexOf('ws://') === 0)

global.WRTC = () => {
var wrtc = ElectronWebRTC()
const wrtc = ElectronWebRTC()

const ensureCloseElectron = () => {
process.removeListener('SIGINT', ensureCloseElectron)
process.removeListener('SIGTERM', ensureCloseElectron)
wrtc.close()
}

process.on('SIGINT', ensureCloseElectron)
process.on('SIGTERM', ensureCloseElectron)
Expand All @@ -21,11 +23,5 @@ global.WRTC = () => {
}
})

function ensureCloseElectron () {
process.removeListener('SIGINT', ensureCloseElectron)
process.removeListener('SIGTERM', ensureCloseElectron)
wrtc.close()
}

return wrtc
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"standard": "*"
},
"engines": {
"node": ">=4"
"node": ">=6"
},
"homepage": "http://webtorrent.io",
"keywords": [
Expand Down

0 comments on commit c0e5153

Please sign in to comment.