From 972a6d9773dcd5d3599a90904031d3c6d709f3b9 Mon Sep 17 00:00:00 2001 From: Thummanoon Kunanuntakij Date: Sat, 13 Oct 2018 02:09:34 +0700 Subject: [PATCH] convert variable declaration to es6 style --- examples/node-download.js | 20 ++++++++++---------- examples/node-seed.js | 8 +++----- lib/global.js | 26 +++++++++++--------------- package.json | 2 +- 4 files changed, 25 insertions(+), 31 deletions(-) diff --git a/examples/node-download.js b/examples/node-download.js index 65a3e6b..8739dd7 100644 --- a/examples/node-download.js +++ b/examples/node-download.js @@ -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) }) }) diff --git a/examples/node-seed.js b/examples/node-seed.js index a10cd3f..7848792 100644 --- a/examples/node-seed.js +++ b/examples/node-seed.js @@ -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) diff --git a/lib/global.js b/lib/global.js index 80cb30f..2ee535f 100644 --- a/lib/global.js +++ b/lib/global.js @@ -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) @@ -21,11 +23,5 @@ global.WRTC = () => { } }) - function ensureCloseElectron () { - process.removeListener('SIGINT', ensureCloseElectron) - process.removeListener('SIGTERM', ensureCloseElectron) - wrtc.close() - } - return wrtc } diff --git a/package.json b/package.json index 74b403c..3ce1741 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "standard": "*" }, "engines": { - "node": ">=4" + "node": ">=6" }, "homepage": "http://webtorrent.io", "keywords": [