@libp2p/webrtc 5.2.10 → 5.2.11-afa5c9f59
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 +13 -13
- package/dist/src/private-to-public/listener.d.ts.map +1 -1
- package/dist/src/private-to-public/listener.js +1 -0
- package/dist/src/private-to-public/listener.js.map +1 -1
- package/dist/src/private-to-public/transport.d.ts +1 -5
- package/dist/src/private-to-public/transport.d.ts.map +1 -1
- package/dist/src/private-to-public/transport.js +29 -37
- package/dist/src/private-to-public/transport.js.map +1 -1
- package/dist/src/private-to-public/utils/connect.js +124 -124
- package/dist/src/private-to-public/utils/connect.js.map +1 -1
- package/dist/src/stream.d.ts +5 -0
- package/dist/src/stream.d.ts.map +1 -1
- package/dist/src/stream.js +15 -10
- package/dist/src/stream.js.map +1 -1
- package/package.json +9 -9
- package/src/private-to-public/listener.ts +1 -0
- package/src/private-to-public/transport.ts +33 -42
- package/src/private-to-public/utils/connect.ts +136 -135
- package/src/stream.ts +21 -12
- package/dist/typedoc-urls.json +0 -14
package/src/stream.ts
CHANGED
@@ -60,7 +60,7 @@ export class WebRTCStream extends AbstractStream {
|
|
60
60
|
// override onEnd to send/receive FIN_ACK before closing the stream
|
61
61
|
const originalOnEnd = init.onEnd
|
62
62
|
init.onEnd = (err?: Error): void => {
|
63
|
-
this.log.trace('readable and writeable ends closed', this.status)
|
63
|
+
this.log.trace('readable and writeable ends closed with status "%s"', this.status)
|
64
64
|
|
65
65
|
void Promise.resolve(async () => {
|
66
66
|
if (this.timeline.abort != null || this.timeline.reset !== null) {
|
@@ -77,9 +77,8 @@ export class WebRTCStream extends AbstractStream {
|
|
77
77
|
}
|
78
78
|
})
|
79
79
|
.then(() => {
|
80
|
-
|
80
|
+
// stop processing incoming messages
|
81
81
|
this.incomingData.end()
|
82
|
-
this.channel.close()
|
83
82
|
|
84
83
|
// final cleanup
|
85
84
|
originalOnEnd?.(err)
|
@@ -87,6 +86,9 @@ export class WebRTCStream extends AbstractStream {
|
|
87
86
|
.catch(err => {
|
88
87
|
this.log.error('error ending stream', err)
|
89
88
|
})
|
89
|
+
.finally(() => {
|
90
|
+
this.channel.close()
|
91
|
+
})
|
90
92
|
}
|
91
93
|
|
92
94
|
super(init)
|
@@ -229,6 +231,7 @@ export class WebRTCStream extends AbstractStream {
|
|
229
231
|
}
|
230
232
|
|
231
233
|
try {
|
234
|
+
this.log.trace('sending message, channel state "%s"', this.channel.readyState)
|
232
235
|
// send message without copying data
|
233
236
|
this.channel.send(data.subarray())
|
234
237
|
} catch (err: any) {
|
@@ -237,8 +240,7 @@ export class WebRTCStream extends AbstractStream {
|
|
237
240
|
}
|
238
241
|
|
239
242
|
async sendData (data: Uint8ArrayList): Promise<void> {
|
240
|
-
|
241
|
-
|
243
|
+
const bytesTotal = data.byteLength
|
242
244
|
// sending messages is an async operation so use a copy of the list as it
|
243
245
|
// may be changed beneath us
|
244
246
|
data = data.sublist()
|
@@ -248,14 +250,13 @@ export class WebRTCStream extends AbstractStream {
|
|
248
250
|
const buf = data.subarray(0, toSend)
|
249
251
|
const messageBuf = Message.encode({ message: buf })
|
250
252
|
const sendBuf = lengthPrefixed.encode.single(messageBuf)
|
251
|
-
this.log.trace('
|
253
|
+
this.log.trace('sending %d/%d bytes on channel', buf.byteLength, bytesTotal)
|
252
254
|
await this._sendMessage(sendBuf)
|
253
|
-
this.log.trace('-> sent message %s', this.channel.readyState)
|
254
255
|
|
255
256
|
data.consume(toSend)
|
256
257
|
}
|
257
258
|
|
258
|
-
this.log.trace('
|
259
|
+
this.log.trace('finished sending data, channel state "%s"', this.channel.readyState)
|
259
260
|
}
|
260
261
|
|
261
262
|
async sendReset (): Promise<void> {
|
@@ -263,6 +264,8 @@ export class WebRTCStream extends AbstractStream {
|
|
263
264
|
await this._sendFlag(Message.Flag.RESET)
|
264
265
|
} catch (err) {
|
265
266
|
this.log.error('failed to send reset - %e', err)
|
267
|
+
} finally {
|
268
|
+
this.channel.close()
|
266
269
|
}
|
267
270
|
}
|
268
271
|
|
@@ -347,7 +350,7 @@ export class WebRTCStream extends AbstractStream {
|
|
347
350
|
// flags can be sent while we or the remote are closing the datachannel so
|
348
351
|
// if the channel isn't open, don't try to send it but return false to let
|
349
352
|
// the caller know and act if they need to
|
350
|
-
this.log.trace('not sending flag %s because channel is "%s" and not "open"', this.channel.readyState
|
353
|
+
this.log.trace('not sending flag %s because channel is "%s" and not "open"', flag.toString(), this.channel.readyState)
|
351
354
|
return false
|
352
355
|
}
|
353
356
|
|
@@ -387,14 +390,20 @@ export interface WebRTCStreamOptions extends DataChannelOptions {
|
|
387
390
|
onEnd?(err?: Error | undefined): void
|
388
391
|
|
389
392
|
logger: ComponentLogger
|
393
|
+
|
394
|
+
/**
|
395
|
+
* If true the underlying datachannel is being used to perform the noise
|
396
|
+
* handshake during connection establishment
|
397
|
+
*/
|
398
|
+
handshake?: boolean
|
390
399
|
}
|
391
400
|
|
392
401
|
export function createStream (options: WebRTCStreamOptions): WebRTCStream {
|
393
|
-
const { channel, direction } = options
|
402
|
+
const { channel, direction, handshake } = options
|
394
403
|
|
395
404
|
return new WebRTCStream({
|
396
|
-
id:
|
397
|
-
log: options.logger.forComponent(`libp2p:webrtc:stream:${direction}:${channel.id}`),
|
405
|
+
id: `${channel.id}`,
|
406
|
+
log: options.logger.forComponent(`libp2p:webrtc:stream:${handshake === true ? 'handshake' : direction}:${channel.id}`),
|
398
407
|
...options
|
399
408
|
})
|
400
409
|
}
|
package/dist/typedoc-urls.json
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"DataChannelOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webrtc.DataChannelOptions.html",
|
3
|
-
".:DataChannelOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webrtc.DataChannelOptions.html",
|
4
|
-
"TransportCertificate": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webrtc.TransportCertificate.html",
|
5
|
-
".:TransportCertificate": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webrtc.TransportCertificate.html",
|
6
|
-
"WebRTCDirectTransportComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webrtc.WebRTCDirectTransportComponents.html",
|
7
|
-
"WebRTCTransportComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webrtc.WebRTCTransportComponents.html",
|
8
|
-
"WebRTCTransportDirectInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webrtc.WebRTCTransportDirectInit.html",
|
9
|
-
"WebRTCTransportInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webrtc.WebRTCTransportInit.html",
|
10
|
-
"webRTC": "https://libp2p.github.io/js-libp2p/functions/_libp2p_webrtc.webRTC.html",
|
11
|
-
".:webRTC": "https://libp2p.github.io/js-libp2p/functions/_libp2p_webrtc.webRTC.html",
|
12
|
-
"webRTCDirect": "https://libp2p.github.io/js-libp2p/functions/_libp2p_webrtc.webRTCDirect.html",
|
13
|
-
".:webRTCDirect": "https://libp2p.github.io/js-libp2p/functions/_libp2p_webrtc.webRTCDirect.html"
|
14
|
-
}
|