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

Commit 4962501

Browse files
michaelfakhridaviddias
authored andcommitted
Added signaling error handling to webrtc-star transport (#39)
* Added a failing test that shows expected behaviour but is failing due to lack of error handling code. * Added error handling to js-libp2p-webrtc-star so that unavailable peers do not cause error states.
1 parent 3d7232d commit 4962501

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/webrtc-star/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ function WebRTCStar () {
7575
})
7676

7777
sioClient.on('ws-handshake', (offer) => {
78+
if (offer.intentId === intentId && offer.err) {
79+
return callback(new Error(offer.err))
80+
}
81+
7882
if (offer.intentId !== intentId || !offer.answer) {
7983
return
8084
}
@@ -135,7 +139,7 @@ function WebRTCStar () {
135139
})
136140

137141
function incommingDial (offer) {
138-
if (offer.answer) {
142+
if (offer.answer || offer.err) {
139143
return
140144
}
141145

test/webrtc-star/test-dial.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ describe('dial', () => {
5959
)
6060
})
6161
})
62+
it('dial offline / non-existent node on IPv4, check callback', (done) => {
63+
let maOffline = multiaddr('/libp2p-webrtc-star/ip4/127.0.0.1/tcp/15555/ws/ipfs/ABCD')
64+
ws1.dial(maOffline, (err, conn) => {
65+
expect(err).to.exist
66+
done()
67+
})
68+
})
6269

6370
it.skip('dial on IPv6', (done) => {
6471
// TODO IPv6 not supported yet

0 commit comments

Comments
 (0)