From 2a5832c93f3d7e4517bbd88568fb66442797aad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kr=C3=BCger?= Date: Fri, 22 Jun 2018 13:00:19 +0200 Subject: [PATCH] fix: return error if dialing ma without id --- src/index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index e611fad9..b2df2c9c 100644 --- a/src/index.js +++ b/src/index.js @@ -45,9 +45,13 @@ class WebRTCStar { callback = callback ? once(callback) : noop - let b58 = ma.split('ipfs/').pop() + let peerId = ma.getPeerId() - log('dialing %s (id=%s)', ma, b58) + log('dialing %s (id=%s)', ma, peerId) + + if (!peerId) { + return callback(new Error('Cannot dial peer: No Id provided!')) + } const spOptions = { initiator: true, trickle: false } @@ -61,7 +65,7 @@ class WebRTCStar { channel.on('signal', (signal) => { log('dial#%s got signal', ma) - this.exchange.request(Id.createFromB58String(b58), 'webrtc', Buffer.from(JSON.stringify({signal})), (err, result) => { + this.exchange.request(Id.createFromB58String(peerId), 'webrtc', Buffer.from(JSON.stringify({signal})), (err, result) => { if (err) { log('dial#%s exchange failed %s', ma, err) return callback(err)