Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2014-12-17 06:55:41 +0300
committerFeross Aboukhadijeh <feross@feross.org>2014-12-17 07:03:19 +0300
commit147311347388e02fcc93cdadc17dc7cc2ec99397 (patch)
treef58c03f7ca0a24909710572138cef4a641f7f891 /index.js
parentb8cfe8ea3cde0f0e18d9facc1c3924e783d7f2d0 (diff)
Generate client version string from package.json version
Depends on this PR: https://github.com/webpro/versionify/pull/2
Diffstat (limited to 'index.js')
-rw-r--r--index.js11
1 files changed, 10 insertions, 1 deletions
diff --git a/index.js b/index.js
index d342455..0a15642 100644
--- a/index.js
+++ b/index.js
@@ -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