@libp2p/webrtc 4.0.34-863b3de03 → 4.0.34-8e4fdcde9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +10 -10
- package/dist/src/private-to-private/initiate-connection.d.ts +9 -4
- package/dist/src/private-to-private/initiate-connection.d.ts.map +1 -1
- package/dist/src/private-to-private/initiate-connection.js +17 -6
- package/dist/src/private-to-private/initiate-connection.js.map +1 -1
- package/dist/src/private-to-private/transport.d.ts +5 -2
- package/dist/src/private-to-private/transport.d.ts.map +1 -1
- package/dist/src/private-to-private/transport.js +23 -17
- package/dist/src/private-to-private/transport.js.map +1 -1
- package/dist/src/private-to-private/util.d.ts.map +1 -1
- package/dist/src/private-to-private/util.js +4 -2
- package/dist/src/private-to-private/util.js.map +1 -1
- package/dist/src/private-to-public/transport.d.ts +5 -9
- package/dist/src/private-to-public/transport.d.ts.map +1 -1
- package/dist/src/private-to-public/transport.js +6 -9
- package/dist/src/private-to-public/transport.js.map +1 -1
- package/package.json +12 -11
- package/src/private-to-private/initiate-connection.ts +22 -8
- package/src/private-to-private/transport.ts +29 -21
- package/src/private-to-private/util.ts +5 -2
- package/src/private-to-public/transport.ts +10 -11
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CodeError, setMaxListeners } from '@libp2p/interface'
|
|
1
|
+
import { CodeError, serviceCapabilities, serviceDependencies, setMaxListeners } from '@libp2p/interface'
|
|
2
2
|
import { type CreateListenerOptions, type DialOptions, transportSymbol, type Transport, type Listener, type Upgrader, type ComponentLogger, type Logger, type Connection, type PeerId, type CounterGroup, type Metrics, type Startable } from '@libp2p/interface'
|
|
3
3
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
4
4
|
import { multiaddr, type Multiaddr } from '@multiformats/multiaddr'
|
|
@@ -72,6 +72,19 @@ export class WebRTCTransport implements Transport, Startable {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
readonly [transportSymbol] = true
|
|
76
|
+
|
|
77
|
+
readonly [Symbol.toStringTag] = '@libp2p/webrtc'
|
|
78
|
+
|
|
79
|
+
readonly [serviceCapabilities]: string[] = [
|
|
80
|
+
'@libp2p/transport'
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
readonly [serviceDependencies]: string[] = [
|
|
84
|
+
'@libp2p/identify',
|
|
85
|
+
'@libp2p/circuit-relay-v2-transport'
|
|
86
|
+
]
|
|
87
|
+
|
|
75
88
|
isStarted (): boolean {
|
|
76
89
|
return this._started
|
|
77
90
|
}
|
|
@@ -96,10 +109,6 @@ export class WebRTCTransport implements Transport, Startable {
|
|
|
96
109
|
})
|
|
97
110
|
}
|
|
98
111
|
|
|
99
|
-
readonly [Symbol.toStringTag] = '@libp2p/webrtc'
|
|
100
|
-
|
|
101
|
-
readonly [transportSymbol] = true
|
|
102
|
-
|
|
103
112
|
/**
|
|
104
113
|
* Filter check for all Multiaddrs that this transport can listen on
|
|
105
114
|
*/
|
|
@@ -124,20 +133,16 @@ export class WebRTCTransport implements Transport, Startable {
|
|
|
124
133
|
async dial (ma: Multiaddr, options: DialOptions): Promise<Connection> {
|
|
125
134
|
this.log.trace('dialing address: %a', ma)
|
|
126
135
|
|
|
127
|
-
const peerConnection =
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
dataChannelOptions: this.init.dataChannel
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
const { remoteAddress } = await initiateConnection({
|
|
134
|
-
peerConnection,
|
|
136
|
+
const { remoteAddress, peerConnection, muxerFactory } = await initiateConnection({
|
|
137
|
+
rtcConfiguration: this.init.rtcConfiguration,
|
|
138
|
+
dataChannel: this.init.dataChannel,
|
|
135
139
|
multiaddr: ma,
|
|
136
140
|
dataChannelOptions: this.init.dataChannel,
|
|
137
141
|
signal: options.signal,
|
|
138
142
|
connectionManager: this.components.connectionManager,
|
|
139
143
|
transportManager: this.components.transportManager,
|
|
140
|
-
log: this.log
|
|
144
|
+
log: this.log,
|
|
145
|
+
logger: this.components.logger
|
|
141
146
|
})
|
|
142
147
|
|
|
143
148
|
const webRTCConn = new WebRTCMultiaddrConnection(this.components, {
|
|
@@ -176,6 +181,11 @@ export class WebRTCTransport implements Transport, Startable {
|
|
|
176
181
|
log: this.log
|
|
177
182
|
})
|
|
178
183
|
|
|
184
|
+
// close the stream if SDP messages have been exchanged successfully
|
|
185
|
+
await stream.close({
|
|
186
|
+
signal
|
|
187
|
+
})
|
|
188
|
+
|
|
179
189
|
const webRTCConn = new WebRTCMultiaddrConnection(this.components, {
|
|
180
190
|
peerConnection,
|
|
181
191
|
timeline: { open: (new Date()).getTime() },
|
|
@@ -183,20 +193,18 @@ export class WebRTCTransport implements Transport, Startable {
|
|
|
183
193
|
metrics: this.metrics?.listenerEvents
|
|
184
194
|
})
|
|
185
195
|
|
|
186
|
-
// close the connection on shut down
|
|
187
|
-
this._closeOnShutdown(peerConnection, webRTCConn)
|
|
188
|
-
|
|
189
196
|
await this.components.upgrader.upgradeInbound(webRTCConn, {
|
|
190
197
|
skipEncryption: true,
|
|
191
198
|
skipProtection: true,
|
|
192
199
|
muxerFactory
|
|
193
200
|
})
|
|
194
201
|
|
|
195
|
-
// close the
|
|
196
|
-
|
|
197
|
-
signal
|
|
198
|
-
})
|
|
202
|
+
// close the connection on shut down
|
|
203
|
+
this._closeOnShutdown(peerConnection, webRTCConn)
|
|
199
204
|
} catch (err: any) {
|
|
205
|
+
this.log.error('incoming signalling error', err)
|
|
206
|
+
|
|
207
|
+
peerConnection.close()
|
|
200
208
|
stream.abort(err)
|
|
201
209
|
throw err
|
|
202
210
|
}
|
|
@@ -23,11 +23,14 @@ export const readCandidatesUntilConnected = async (pc: RTCPeerConnection, stream
|
|
|
23
23
|
connectedPromise.promise,
|
|
24
24
|
stream.read({
|
|
25
25
|
signal: options.signal
|
|
26
|
-
})
|
|
26
|
+
}).catch(() => {})
|
|
27
27
|
])
|
|
28
28
|
|
|
29
29
|
// stream ended or we became connected
|
|
30
30
|
if (message == null) {
|
|
31
|
+
// throw if we timed out
|
|
32
|
+
options.signal?.throwIfAborted()
|
|
33
|
+
|
|
31
34
|
break
|
|
32
35
|
}
|
|
33
36
|
|
|
@@ -48,7 +51,7 @@ export const readCandidatesUntilConnected = async (pc: RTCPeerConnection, stream
|
|
|
48
51
|
|
|
49
52
|
const candidate = new RTCIceCandidate(candidateInit)
|
|
50
53
|
|
|
51
|
-
options.log.trace('%s received new ICE candidate', options.direction,
|
|
54
|
+
options.log.trace('%s received new ICE candidate %o', options.direction, candidateInit)
|
|
52
55
|
|
|
53
56
|
try {
|
|
54
57
|
await pc.addIceCandidate(candidate)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { noise } from '@chainsafe/libp2p-noise'
|
|
2
|
-
import {
|
|
2
|
+
import { transportSymbol, serviceCapabilities } from '@libp2p/interface'
|
|
3
3
|
import * as p from '@libp2p/peer-id'
|
|
4
4
|
import { protocols } from '@multiformats/multiaddr'
|
|
5
5
|
import { WebRTCDirect } from '@multiformats/multiaddr-matcher'
|
|
@@ -16,6 +16,7 @@ import * as sdp from './sdp.js'
|
|
|
16
16
|
import { genUfrag } from './util.js'
|
|
17
17
|
import type { WebRTCDialOptions } from './options.js'
|
|
18
18
|
import type { DataChannelOptions } from '../index.js'
|
|
19
|
+
import type { CreateListenerOptions, Transport, Listener, ComponentLogger, Logger, Connection, CounterGroup, Metrics, PeerId } from '@libp2p/interface'
|
|
19
20
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
20
21
|
|
|
21
22
|
/**
|
|
@@ -73,6 +74,14 @@ export class WebRTCDirectTransport implements Transport {
|
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
|
|
77
|
+
readonly [transportSymbol] = true
|
|
78
|
+
|
|
79
|
+
readonly [Symbol.toStringTag] = '@libp2p/webrtc-direct'
|
|
80
|
+
|
|
81
|
+
readonly [serviceCapabilities]: string[] = [
|
|
82
|
+
'@libp2p/transport'
|
|
83
|
+
]
|
|
84
|
+
|
|
76
85
|
/**
|
|
77
86
|
* Dial a given multiaddr
|
|
78
87
|
*/
|
|
@@ -103,16 +112,6 @@ export class WebRTCDirectTransport implements Transport {
|
|
|
103
112
|
return this.listenFilter(multiaddrs)
|
|
104
113
|
}
|
|
105
114
|
|
|
106
|
-
/**
|
|
107
|
-
* Implement toString() for WebRTCTransport
|
|
108
|
-
*/
|
|
109
|
-
readonly [Symbol.toStringTag] = '@libp2p/webrtc-direct'
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Symbol.for('@libp2p/transport')
|
|
113
|
-
*/
|
|
114
|
-
readonly [transportSymbol] = true
|
|
115
|
-
|
|
116
115
|
/**
|
|
117
116
|
* Connect to a peer using a multiaddr
|
|
118
117
|
*/
|