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>2016-05-08 20:37:51 +0300
committerFeross Aboukhadijeh <feross@feross.org>2016-05-08 20:37:51 +0300
commitc6f4018384580ce55533240c74ab1c9b52cc08a1 (patch)
treec0c0b6c228ed0826d0630eca6b115ed36f6c46b2 /index.js
parentad16358d0417f71a122444b4bce2e85daef55f3f (diff)
style: set default peerId and nodeId in clearer way
Diffstat (limited to 'index.js')
-rw-r--r--index.js20
1 files changed, 14 insertions, 6 deletions
diff --git a/index.js b/index.js
index 2b8f188..f8194da 100644
--- a/index.js
+++ b/index.js
@@ -54,14 +54,22 @@ function WebTorrent (opts) {
if (!opts) opts = {}
- self.peerId = typeof opts.peerId === 'string'
- ? opts.peerId
- : (opts.peerId || new Buffer(VERSION_PREFIX + hat(48))).toString('hex')
+ if (typeof opts.peerId === 'string') {
+ self.peerId = opts.peerId
+ } else if (Buffer.isBuffer(opts.peerId)) {
+ self.peerId = opts.peerId.toString('hex')
+ } else {
+ self.peerId = new Buffer(VERSION_PREFIX + hat(48))
+ }
self.peerIdBuffer = new Buffer(self.peerId, 'hex')
- self.nodeId = typeof opts.nodeId === 'string'
- ? opts.nodeId
- : (opts.nodeId && opts.nodeId.toString('hex')) || hat(160)
+ if (typeof opts.nodeId === 'string') {
+ self.nodeId = opts.nodeId
+ } else if (Buffer.isBuffer(opts.nodeId)) {
+ self.nodeId = opts.nodeId.toString('hex')
+ } else {
+ self.nodeId = hat(160)
+ }
self.nodeIdBuffer = new Buffer(self.nodeId, 'hex')
self.destroyed = false