Skip to content
This repository was archived by the owner on Apr 24, 2023. It is now read-only.

Commit 2a5832c

Browse files
committed
fix: return error if dialing ma without id
1 parent 4238cb8 commit 2a5832c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/index.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,13 @@ class WebRTCStar {
4545

4646
callback = callback ? once(callback) : noop
4747

48-
let b58 = ma.split('ipfs/').pop()
48+
let peerId = ma.getPeerId()
4949

50-
log('dialing %s (id=%s)', ma, b58)
50+
log('dialing %s (id=%s)', ma, peerId)
51+
52+
if (!peerId) {
53+
return callback(new Error('Cannot dial peer: No Id provided!'))
54+
}
5155

5256
const spOptions = { initiator: true, trickle: false }
5357

@@ -61,7 +65,7 @@ class WebRTCStar {
6165

6266
channel.on('signal', (signal) => {
6367
log('dial#%s got signal', ma)
64-
this.exchange.request(Id.createFromB58String(b58), 'webrtc', Buffer.from(JSON.stringify({signal})), (err, result) => {
68+
this.exchange.request(Id.createFromB58String(peerId), 'webrtc', Buffer.from(JSON.stringify({signal})), (err, result) => {
6569
if (err) {
6670
log('dial#%s exchange failed %s', ma, err)
6771
return callback(err)

0 commit comments

Comments
 (0)