diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2014-12-17 06:55:41 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2014-12-17 07:03:19 +0300 |
commit | 147311347388e02fcc93cdadc17dc7cc2ec99397 (patch) | |
tree | f58c03f7ca0a24909710572138cef4a641f7f891 | |
parent | b8cfe8ea3cde0f0e18d9facc1c3924e783d7f2d0 (diff) |
Generate client version string from package.json version
Depends on this PR: https://github.com/webpro/versionify/pull/2
-rw-r--r-- | index.js | 11 | ||||
-rw-r--r-- | package.json | 21 |
2 files changed, 24 insertions, 8 deletions
@@ -17,6 +17,7 @@ var parallel = require('run-parallel') var parseTorrent = require('parse-torrent') var speedometer = require('speedometer') var stream = require('stream') +var zeroFill = require('zero-fill') var FSStorage = require('./lib/fs-storage') // browser exclude var Storage = require('./lib/storage') @@ -25,6 +26,14 @@ var Torrent = require('./lib/torrent') inherits(WebTorrent, EventEmitter) /** + * BitTorrent client version string (used in peer ID). + * Generated from package.json major and minor version. For example: + * '0.16.1' -> '0016' + * '1.2.5' -> '0102' + */ +var VERSION = '__VERSION__'.match(/([0-9]+)/g).slice(0, 2).map(zeroFill(2)).join('') + +/** * WebTorrent Client * @param {Object} opts */ @@ -49,7 +58,7 @@ function WebTorrent (opts) { : Storage self.peerId = opts.peerId === undefined - ? new Buffer('-WW0001-' + hat(48), 'utf8') + ? new Buffer('-WW' + VERSION + '-' + hat(48), 'utf8') : typeof opts.peerId === 'string' ? new Buffer(opts.peerId, 'utf8') : opts.peerId diff --git a/package.json b/package.json index 5444d89..85b0609 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,11 @@ "load-ip-set": false, "ut_pex": false }, + "browserify": { + "transform": [ + "browserify-versionify" + ] + }, "bugs": { "url": "https://github.com/feross/webtorrent/issues" }, @@ -64,12 +69,14 @@ "ut_metadata": "^2.1.0", "ut_pex": "^1.0.1", "webtorrent-swarm": "^0.3.0", - "windows-no-runnable": "~0.0.6" + "windows-no-runnable": "~0.0.6", + "zero-fill": "^2.1.0" }, "devDependencies": { "bittorrent-tracker": "^2.5.0", "brfs": "^1.2.0", - "browserify": "^6.1.0", + "browserify": "^7.0.0", + "browserify-versionify": "^1.0.2", "portfinder": "^0.2.1", "run-auto": "^1.0.0", "tape": "^3.0.3", @@ -77,11 +84,6 @@ "zelda": "^2.0.0", "zuul": "^1.11.1" }, - "optionalDependencies": { - "airplay-js": "^0.2.3", - "chromecast-js": "^0.1.4", - "nodebmc": "0.0.5" - }, "homepage": "http://webtorrent.io", "keywords": [ "torrent", @@ -96,6 +98,11 @@ ], "license": "MIT", "main": "index.js", + "optionalDependencies": { + "airplay-js": "^0.2.3", + "chromecast-js": "^0.1.4", + "nodebmc": "0.0.5" + }, "repository": { "type": "git", "url": "git://github.com/feross/webtorrent.git" |