@libp2p/webrtc 5.2.3 → 5.2.4-4939ef7ae
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/README.md +1 -1
- package/dist/index.min.js +7 -7
- package/dist/src/constants.d.ts +56 -2
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +75 -2
- package/dist/src/constants.js.map +1 -1
- package/dist/src/index.d.ts +9 -7
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/maconn.d.ts +1 -1
- package/dist/src/maconn.js +1 -1
- package/dist/src/muxer.d.ts.map +1 -1
- package/dist/src/muxer.js +4 -4
- package/dist/src/muxer.js.map +1 -1
- package/dist/src/private-to-private/initiate-connection.d.ts.map +1 -1
- package/dist/src/private-to-private/initiate-connection.js +3 -2
- package/dist/src/private-to-private/initiate-connection.js.map +1 -1
- package/dist/src/private-to-private/listener.d.ts +4 -1
- package/dist/src/private-to-private/listener.d.ts.map +1 -1
- package/dist/src/private-to-private/listener.js +14 -2
- package/dist/src/private-to-private/listener.js.map +1 -1
- package/dist/src/private-to-private/transport.d.ts +13 -4
- package/dist/src/private-to-private/transport.d.ts.map +1 -1
- package/dist/src/private-to-private/transport.js +19 -13
- package/dist/src/private-to-private/transport.js.map +1 -1
- package/dist/src/private-to-public/listener.d.ts +2 -0
- package/dist/src/private-to-public/listener.d.ts.map +1 -1
- package/dist/src/private-to-public/listener.js +20 -9
- package/dist/src/private-to-public/listener.js.map +1 -1
- package/dist/src/private-to-public/transport.d.ts +2 -1
- package/dist/src/private-to-public/transport.d.ts.map +1 -1
- package/dist/src/private-to-public/transport.js +3 -3
- package/dist/src/private-to-public/transport.js.map +1 -1
- package/dist/src/private-to-public/utils/generate-noise-prologue.js +1 -1
- package/dist/src/private-to-public/utils/generate-noise-prologue.js.map +1 -1
- package/dist/src/private-to-public/utils/get-rtcpeerconnection.d.ts.map +1 -1
- package/dist/src/private-to-public/utils/get-rtcpeerconnection.js +1 -2
- package/dist/src/private-to-public/utils/get-rtcpeerconnection.js.map +1 -1
- package/dist/src/private-to-public/utils/sdp.d.ts +1 -1
- package/dist/src/private-to-public/utils/sdp.d.ts.map +1 -1
- package/dist/src/private-to-public/utils/sdp.js +9 -10
- package/dist/src/private-to-public/utils/sdp.js.map +1 -1
- package/dist/src/stream.d.ts +0 -33
- package/dist/src/stream.d.ts.map +1 -1
- package/dist/src/stream.js +6 -56
- package/dist/src/stream.js.map +1 -1
- package/dist/src/util.d.ts +0 -1
- package/dist/src/util.d.ts.map +1 -1
- package/dist/src/util.js +1 -2
- package/dist/src/util.js.map +1 -1
- package/package.json +9 -9
- package/src/constants.ts +89 -2
- package/src/index.ts +10 -7
- package/src/maconn.ts +1 -1
- package/src/muxer.ts +4 -5
- package/src/private-to-private/initiate-connection.ts +3 -2
- package/src/private-to-private/listener.ts +20 -3
- package/src/private-to-private/transport.ts +33 -16
- package/src/private-to-public/listener.ts +25 -10
- package/src/private-to-public/transport.ts +6 -4
- package/src/private-to-public/utils/generate-noise-prologue.ts +1 -1
- package/src/private-to-public/utils/get-rtcpeerconnection.ts +1 -2
- package/src/private-to-public/utils/sdp.ts +9 -10
- package/src/stream.ts +6 -65
- package/src/util.ts +1 -3
- package/dist/typedoc-urls.json +0 -14
@@ -6,7 +6,7 @@ import { IP4, WebRTCDirect } from '@multiformats/multiaddr-matcher'
|
|
6
6
|
import { Crypto } from '@peculiar/webcrypto'
|
7
7
|
import getPort from 'get-port'
|
8
8
|
import pWaitFor from 'p-wait-for'
|
9
|
-
import { CODEC_CERTHASH, CODEC_WEBRTC_DIRECT
|
9
|
+
import { CODEC_CERTHASH, CODEC_WEBRTC_DIRECT } from '../constants.js'
|
10
10
|
import { connect } from './utils/connect.js'
|
11
11
|
import { generateTransportCertificate } from './utils/generate-certificates.js'
|
12
12
|
import { createDialerRTCPeerConnection } from './utils/get-rtcpeerconnection.js'
|
@@ -23,6 +23,7 @@ export interface WebRTCDirectListenerComponents {
|
|
23
23
|
peerId: PeerId
|
24
24
|
privateKey: PrivateKey
|
25
25
|
logger: ComponentLogger
|
26
|
+
upgrader: Upgrader
|
26
27
|
metrics?: Metrics
|
27
28
|
}
|
28
29
|
|
@@ -62,6 +63,7 @@ export class WebRTCDirectListener extends TypedEventEmitter<ListenerEvents> impl
|
|
62
63
|
private readonly init: WebRTCDirectListenerInit
|
63
64
|
private readonly components: WebRTCDirectListenerComponents
|
64
65
|
private readonly metrics?: WebRTCListenerMetrics
|
66
|
+
private readonly shutdownController: AbortController
|
65
67
|
|
66
68
|
constructor (components: WebRTCDirectListenerComponents, init: WebRTCDirectListenerInit) {
|
67
69
|
super()
|
@@ -72,6 +74,7 @@ export class WebRTCDirectListener extends TypedEventEmitter<ListenerEvents> impl
|
|
72
74
|
this.connections = new Map()
|
73
75
|
this.log = components.logger.forComponent('libp2p:webrtc-direct:listener')
|
74
76
|
this.certificate = init.certificates?.[0]
|
77
|
+
this.shutdownController = new AbortController()
|
75
78
|
|
76
79
|
if (components.metrics != null) {
|
77
80
|
this.metrics = {
|
@@ -93,14 +96,14 @@ export class WebRTCDirectListener extends TypedEventEmitter<ListenerEvents> impl
|
|
93
96
|
.pop()?.[1]
|
94
97
|
|
95
98
|
if (host == null) {
|
96
|
-
throw new Error('IP4/6 host must be specified in webrtc-direct
|
99
|
+
throw new Error('IP4/6 host must be specified in webrtc-direct multiaddr')
|
97
100
|
}
|
98
101
|
const port = parseInt(parts
|
99
102
|
.filter(([code, value]) => code === UDP_PROTOCOL.code)
|
100
103
|
.pop()?.[1] ?? '')
|
101
104
|
|
102
105
|
if (isNaN(port)) {
|
103
|
-
throw new Error('UDP port must be specified in webrtc-direct
|
106
|
+
throw new Error('UDP port must be specified in webrtc-direct multiaddr')
|
104
107
|
}
|
105
108
|
|
106
109
|
// have to do this before any async work happens so starting two listeners
|
@@ -178,16 +181,21 @@ export class WebRTCDirectListener extends TypedEventEmitter<ListenerEvents> impl
|
|
178
181
|
}
|
179
182
|
|
180
183
|
return stunListener(host, port, this.log, (ufrag, remoteHost, remotePort) => {
|
181
|
-
this.
|
184
|
+
const signal = this.components.upgrader.createInboundAbortSignal(this.shutdownController.signal)
|
185
|
+
|
186
|
+
this.incomingConnection(ufrag, remoteHost, remotePort, signal)
|
182
187
|
.catch(err => {
|
183
188
|
this.log.error('error processing incoming STUN request', err)
|
184
189
|
})
|
190
|
+
.finally(() => {
|
191
|
+
signal.clear()
|
192
|
+
})
|
185
193
|
})
|
186
194
|
})
|
187
195
|
}
|
188
196
|
}
|
189
197
|
|
190
|
-
private async incomingConnection (ufrag: string, remoteHost: string, remotePort: number): Promise<void> {
|
198
|
+
private async incomingConnection (ufrag: string, remoteHost: string, remotePort: number, signal: AbortSignal): Promise<void> {
|
191
199
|
const key = `${remoteHost}:${remotePort}:${ufrag}`
|
192
200
|
let peerConnection = this.connections.get(key)
|
193
201
|
|
@@ -198,6 +206,9 @@ export class WebRTCDirectListener extends TypedEventEmitter<ListenerEvents> impl
|
|
198
206
|
|
199
207
|
this.log('create peer connection for %s', key)
|
200
208
|
|
209
|
+
// do not create RTCPeerConnection objects if the signal has aborted already
|
210
|
+
signal.throwIfAborted()
|
211
|
+
|
201
212
|
// https://github.com/libp2p/specs/blob/master/webrtc/webrtc-direct.md#browser-to-public-server
|
202
213
|
peerConnection = await createDialerRTCPeerConnection('server', ufrag, this.init.rtcConfiguration, this.certificate)
|
203
214
|
|
@@ -222,7 +233,7 @@ export class WebRTCDirectListener extends TypedEventEmitter<ListenerEvents> impl
|
|
222
233
|
logger: this.components.logger,
|
223
234
|
metrics: this.components.metrics,
|
224
235
|
events: this.metrics?.listenerEvents,
|
225
|
-
signal
|
236
|
+
signal,
|
226
237
|
remoteAddr: multiaddr(`/ip${isIPv4(remoteHost) ? 4 : 6}/${remoteHost}/udp/${remotePort}`),
|
227
238
|
dataChannel: this.init.dataChannel,
|
228
239
|
upgrader: this.init.upgrader,
|
@@ -268,10 +279,6 @@ export class WebRTCDirectListener extends TypedEventEmitter<ListenerEvents> impl
|
|
268
279
|
}
|
269
280
|
|
270
281
|
async close (): Promise<void> {
|
271
|
-
for (const connection of this.connections.values()) {
|
272
|
-
connection.close()
|
273
|
-
}
|
274
|
-
|
275
282
|
// stop our UDP mux listeners
|
276
283
|
await Promise.all(
|
277
284
|
UDP_MUX_LISTENERS
|
@@ -285,6 +292,14 @@ export class WebRTCDirectListener extends TypedEventEmitter<ListenerEvents> impl
|
|
285
292
|
// remove our stopped UDP mux listeners
|
286
293
|
UDP_MUX_LISTENERS = UDP_MUX_LISTENERS.filter(listener => listener.owner !== this)
|
287
294
|
|
295
|
+
// close existing connections
|
296
|
+
for (const connection of this.connections.values()) {
|
297
|
+
connection.close()
|
298
|
+
}
|
299
|
+
|
300
|
+
// stop any in-progress incoming dials
|
301
|
+
this.shutdownController.abort()
|
302
|
+
|
288
303
|
// RTCPeerConnections will be removed from the connections map when their
|
289
304
|
// connection state changes to 'closed'/'disconnected'/'failed
|
290
305
|
await pWaitFor(() => {
|
@@ -2,14 +2,13 @@ import { serviceCapabilities, transportSymbol } from '@libp2p/interface'
|
|
2
2
|
import { peerIdFromString } from '@libp2p/peer-id'
|
3
3
|
import { WebRTCDirect } from '@multiformats/multiaddr-matcher'
|
4
4
|
import { raceSignal } from 'race-signal'
|
5
|
-
import { HANDSHAKE_TIMEOUT_MS } from '../constants.js'
|
6
5
|
import { genUfrag } from '../util.js'
|
7
6
|
import { WebRTCDirectListener } from './listener.js'
|
8
7
|
import { connect } from './utils/connect.js'
|
9
8
|
import { createDialerRTCPeerConnection } from './utils/get-rtcpeerconnection.js'
|
10
9
|
import type { DataChannelOptions, TransportCertificate } from '../index.js'
|
11
10
|
import type { WebRTCDialEvents } from '../private-to-private/transport.js'
|
12
|
-
import type { CreateListenerOptions, Transport, Listener, ComponentLogger, Logger, Connection, CounterGroup, Metrics, PeerId, DialTransportOptions, PrivateKey } from '@libp2p/interface'
|
11
|
+
import type { CreateListenerOptions, Transport, Listener, ComponentLogger, Logger, Connection, CounterGroup, Metrics, PeerId, DialTransportOptions, PrivateKey, Upgrader } from '@libp2p/interface'
|
13
12
|
import type { TransportManager } from '@libp2p/interface-internal'
|
14
13
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
15
14
|
|
@@ -22,6 +21,7 @@ export interface WebRTCDirectTransportComponents {
|
|
22
21
|
metrics?: Metrics
|
23
22
|
logger: ComponentLogger
|
24
23
|
transportManager: TransportManager
|
24
|
+
upgrader: Upgrader
|
25
25
|
}
|
26
26
|
|
27
27
|
export interface WebRTCMetrics {
|
@@ -72,7 +72,6 @@ export class WebRTCDirectTransport implements Transport {
|
|
72
72
|
* Dial a given multiaddr
|
73
73
|
*/
|
74
74
|
async dial (ma: Multiaddr, options: DialTransportOptions<WebRTCDialEvents>): Promise<Connection> {
|
75
|
-
options?.signal?.throwIfAborted()
|
76
75
|
const rawConn = await this._connect(ma, options)
|
77
76
|
this.log('dialing address: %a', ma)
|
78
77
|
return rawConn
|
@@ -106,6 +105,9 @@ export class WebRTCDirectTransport implements Transport {
|
|
106
105
|
* Connect to a peer using a multiaddr
|
107
106
|
*/
|
108
107
|
async _connect (ma: Multiaddr, options: DialTransportOptions<WebRTCDialEvents>): Promise<Connection> {
|
108
|
+
// do not create RTCPeerConnection if the signal has already been aborted
|
109
|
+
options.signal.throwIfAborted()
|
110
|
+
|
109
111
|
let theirPeerId: PeerId | undefined
|
110
112
|
const remotePeerString = ma.getPeerId()
|
111
113
|
if (remotePeerString != null) {
|
@@ -124,7 +126,7 @@ export class WebRTCDirectTransport implements Transport {
|
|
124
126
|
logger: this.components.logger,
|
125
127
|
metrics: this.components.metrics,
|
126
128
|
events: this.metrics?.dialerEvents,
|
127
|
-
signal: options.signal
|
129
|
+
signal: options.signal,
|
128
130
|
remoteAddr: ma,
|
129
131
|
dataChannel: this.init.dataChannel,
|
130
132
|
upgrader: options.upgrader,
|
@@ -15,7 +15,7 @@ export function generateNoisePrologue (localFingerprint: string, remoteAddr: Mul
|
|
15
15
|
const localFpString = localFingerprint.trim().toLowerCase().replaceAll(':', '')
|
16
16
|
const localFpArray = uint8arrayFromString(localFpString, 'hex')
|
17
17
|
const local = Digest.create(sha256.code, localFpArray)
|
18
|
-
const remote: Uint8Array = sdp.
|
18
|
+
const remote: Uint8Array = sdp.multibaseDecoder.decode(sdp.certhash(remoteAddr))
|
19
19
|
const byteLength = PREFIX.byteLength + local.bytes.byteLength + remote.byteLength
|
20
20
|
|
21
21
|
if (role === 'server') {
|
@@ -1,8 +1,7 @@
|
|
1
1
|
import { PeerConnection } from '@ipshipyard/node-datachannel'
|
2
2
|
import { RTCPeerConnection } from '@ipshipyard/node-datachannel/polyfill'
|
3
3
|
import { Crypto } from '@peculiar/webcrypto'
|
4
|
-
import { DEFAULT_ICE_SERVERS } from '../../constants.js'
|
5
|
-
import { MAX_MESSAGE_SIZE } from '../../stream.js'
|
4
|
+
import { DEFAULT_ICE_SERVERS, MAX_MESSAGE_SIZE } from '../../constants.js'
|
6
5
|
import { generateTransportCertificate } from './generate-certificates.js'
|
7
6
|
import type { TransportCertificate } from '../../index.js'
|
8
7
|
import type { CertificateFingerprint } from '@ipshipyard/node-datachannel'
|
@@ -4,9 +4,8 @@ import { base64url } from 'multiformats/bases/base64'
|
|
4
4
|
import { bases, digest } from 'multiformats/basics'
|
5
5
|
import * as Digest from 'multiformats/hashes/digest'
|
6
6
|
import { sha256 } from 'multiformats/hashes/sha2'
|
7
|
-
import { CODEC_CERTHASH } from '../../constants.js'
|
7
|
+
import { CODEC_CERTHASH, MAX_MESSAGE_SIZE } from '../../constants.js'
|
8
8
|
import { InvalidFingerprintError, UnsupportedHashAlgorithmError } from '../../error.js'
|
9
|
-
import { MAX_MESSAGE_SIZE } from '../../stream.js'
|
10
9
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
11
10
|
import type { MultihashDigest } from 'multiformats/hashes/interface'
|
12
11
|
|
@@ -14,7 +13,7 @@ import type { MultihashDigest } from 'multiformats/hashes/interface'
|
|
14
13
|
* Get base2 | identity decoders
|
15
14
|
*/
|
16
15
|
// @ts-expect-error - Not easy to combine these types.
|
17
|
-
export const
|
16
|
+
export const multibaseDecoder: any = Object.values(bases).map(b => b.decoder).reduce((d, b) => d.or(b))
|
18
17
|
|
19
18
|
const fingerprintRegex = /^a=fingerprint:(?:\w+-[0-9]+)\s(?<fingerprint>(:?[0-9a-fA-F]{2})+)$/m
|
20
19
|
export function getFingerprintFromSdp (sdp: string | undefined): string | undefined {
|
@@ -42,16 +41,16 @@ export function certhash (ma: Multiaddr): string {
|
|
42
41
|
* Convert a certhash into a multihash
|
43
42
|
*/
|
44
43
|
export function decodeCerthash (certhash: string): MultihashDigest {
|
45
|
-
return digest.decode(
|
44
|
+
return digest.decode(multibaseDecoder.decode(certhash))
|
46
45
|
}
|
47
46
|
|
48
47
|
export function certhashToFingerprint (certhash: string): string {
|
49
|
-
const
|
48
|
+
const multibaseDecoded = decodeCerthash(certhash)
|
50
49
|
|
51
|
-
return new Array(
|
50
|
+
return new Array(multibaseDecoded.bytes.length)
|
52
51
|
.fill(0)
|
53
52
|
.map((val, index) => {
|
54
|
-
return
|
53
|
+
return multibaseDecoded.digest[index].toString(16).padStart(2, '0').toUpperCase()
|
55
54
|
})
|
56
55
|
.join(':')
|
57
56
|
}
|
@@ -60,9 +59,9 @@ export function certhashToFingerprint (certhash: string): string {
|
|
60
59
|
* Extract the fingerprint from a multiaddr
|
61
60
|
*/
|
62
61
|
export function ma2Fingerprint (ma: Multiaddr): string {
|
63
|
-
const
|
64
|
-
const prefix = toSupportedHashFunction(
|
65
|
-
const fingerprint =
|
62
|
+
const multihashDecoded = decodeCerthash(certhash(ma))
|
63
|
+
const prefix = toSupportedHashFunction(multihashDecoded.code)
|
64
|
+
const fingerprint = multihashDecoded.digest.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '')
|
66
65
|
const sdp = fingerprint.match(/.{1,2}/g)
|
67
66
|
|
68
67
|
if (sdp == null) {
|
package/src/stream.ts
CHANGED
@@ -7,8 +7,8 @@ import pDefer from 'p-defer'
|
|
7
7
|
import pTimeout from 'p-timeout'
|
8
8
|
import { raceEvent } from 'race-event'
|
9
9
|
import { raceSignal } from 'race-signal'
|
10
|
-
import { encodingLength } from 'uint8-varint'
|
11
10
|
import { Uint8ArrayList } from 'uint8arraylist'
|
11
|
+
import { BUFFERED_AMOUNT_LOW_TIMEOUT, FIN_ACK_TIMEOUT, MAX_BUFFERED_AMOUNT, MAX_MESSAGE_SIZE, OPEN_TIMEOUT, PROTOBUF_OVERHEAD } from './constants.js'
|
12
12
|
import { Message } from './private-to-public/pb/message.js'
|
13
13
|
import type { DataChannelOptions } from './index.js'
|
14
14
|
import type { RTCDataChannel } from './webrtc/index.js'
|
@@ -27,65 +27,6 @@ export interface WebRTCStreamInit extends AbstractStreamInit, DataChannelOptions
|
|
27
27
|
logger: ComponentLogger
|
28
28
|
}
|
29
29
|
|
30
|
-
/**
|
31
|
-
* How much can be buffered to the DataChannel at once
|
32
|
-
*/
|
33
|
-
export const MAX_BUFFERED_AMOUNT = 2 * 1024 * 1024
|
34
|
-
|
35
|
-
/**
|
36
|
-
* How long time we wait for the 'bufferedamountlow' event to be emitted
|
37
|
-
*/
|
38
|
-
export const BUFFERED_AMOUNT_LOW_TIMEOUT = 30 * 1000
|
39
|
-
|
40
|
-
/**
|
41
|
-
* Max message size that can be sent to the DataChannel. In browsers this is
|
42
|
-
* 256KiB but go-libp2p and rust-libp2p only support 16KiB at the time of
|
43
|
-
* writing.
|
44
|
-
*
|
45
|
-
* @see https://blog.mozilla.org/webrtc/large-data-channel-messages/
|
46
|
-
* @see https://issues.webrtc.org/issues/40644524
|
47
|
-
*/
|
48
|
-
export const MAX_MESSAGE_SIZE = 16 * 1024
|
49
|
-
|
50
|
-
/**
|
51
|
-
* max protobuf overhead:
|
52
|
-
*
|
53
|
-
* ```
|
54
|
-
* [message-length][flag-field-id+type][flag-field-length][flag-field][message-field-id+type][message-field-length][message-field]
|
55
|
-
* ```
|
56
|
-
*/
|
57
|
-
function calculateProtobufOverhead (maxMessageSize = MAX_MESSAGE_SIZE): number {
|
58
|
-
// these have a fixed size
|
59
|
-
const messageLength = encodingLength(maxMessageSize - encodingLength(maxMessageSize))
|
60
|
-
const flagField = 1 + encodingLength(Object.keys(Message.Flag).length - 1) // id+type/value
|
61
|
-
const messageFieldIdType = 1 // id+type
|
62
|
-
const available = maxMessageSize - messageLength - flagField - messageFieldIdType
|
63
|
-
|
64
|
-
// let message-length/message-data fill the rest of the message
|
65
|
-
const messageFieldLengthLength = encodingLength(available)
|
66
|
-
|
67
|
-
return messageLength + flagField + messageFieldIdType + messageFieldLengthLength
|
68
|
-
}
|
69
|
-
|
70
|
-
/**
|
71
|
-
* The protobuf message overhead includes the maximum amount of all bytes in the
|
72
|
-
* protobuf that aren't message field bytes
|
73
|
-
*/
|
74
|
-
export const PROTOBUF_OVERHEAD = calculateProtobufOverhead()
|
75
|
-
|
76
|
-
/**
|
77
|
-
* When closing streams we send a FIN then wait for the remote to
|
78
|
-
* reply with a FIN_ACK. If that does not happen within this timeout
|
79
|
-
* we close the stream anyway.
|
80
|
-
*/
|
81
|
-
export const FIN_ACK_TIMEOUT = 5000
|
82
|
-
|
83
|
-
/**
|
84
|
-
* When sending data messages, if the channel is not in the "open" state, wait
|
85
|
-
* this long for the "open" event to fire.
|
86
|
-
*/
|
87
|
-
export const OPEN_TIMEOUT = 5000
|
88
|
-
|
89
30
|
export class WebRTCStream extends AbstractStream {
|
90
31
|
/**
|
91
32
|
* The data channel used to send and receive data
|
@@ -305,10 +246,10 @@ export class WebRTCStream extends AbstractStream {
|
|
305
246
|
while (data.byteLength > 0) {
|
306
247
|
const toSend = Math.min(data.byteLength, this.maxMessageSize)
|
307
248
|
const buf = data.subarray(0, toSend)
|
308
|
-
const
|
309
|
-
const
|
249
|
+
const messageBuf = Message.encode({ message: buf })
|
250
|
+
const sendBuf = lengthPrefixed.encode.single(messageBuf)
|
310
251
|
this.log.trace('-> sending message %s', this.channel.readyState)
|
311
|
-
await this._sendMessage(
|
252
|
+
await this._sendMessage(sendBuf)
|
312
253
|
this.log.trace('-> sent message %s', this.channel.readyState)
|
313
254
|
|
314
255
|
data.consume(toSend)
|
@@ -411,8 +352,8 @@ export class WebRTCStream extends AbstractStream {
|
|
411
352
|
}
|
412
353
|
|
413
354
|
this.log.trace('sending flag %s', flag.toString())
|
414
|
-
const
|
415
|
-
const prefixedBuf = lengthPrefixed.encode.single(
|
355
|
+
const messageBuf = Message.encode({ flag })
|
356
|
+
const prefixedBuf = lengthPrefixed.encode.single(messageBuf)
|
416
357
|
|
417
358
|
try {
|
418
359
|
await this._sendMessage(prefixedBuf, false)
|
package/src/util.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { detect } from 'detect-browser'
|
2
2
|
import pDefer from 'p-defer'
|
3
3
|
import pTimeout from 'p-timeout'
|
4
|
-
import { DEFAULT_ICE_SERVERS, UFRAG_ALPHABET, UFRAG_PREFIX } from './constants.js'
|
4
|
+
import { DATA_CHANNEL_DRAIN_TIMEOUT, DEFAULT_ICE_SERVERS, UFRAG_ALPHABET, UFRAG_PREFIX } from './constants.js'
|
5
5
|
import type { RTCDataChannel } from './webrtc/index.js'
|
6
6
|
import type { PeerConnection } from '@ipshipyard/node-datachannel'
|
7
7
|
import type { LoggerOptions } from '@libp2p/interface'
|
@@ -13,8 +13,6 @@ export const nopSource = async function * nop (): AsyncGenerator<Uint8Array, any
|
|
13
13
|
|
14
14
|
export const nopSink = async (_: any): Promise<void> => {}
|
15
15
|
|
16
|
-
export const DATA_CHANNEL_DRAIN_TIMEOUT = 30 * 1000
|
17
|
-
|
18
16
|
export function drainAndClose (channel: RTCDataChannel, direction: string, drainTimeout: number = DATA_CHANNEL_DRAIN_TIMEOUT, options: LoggerOptions): void {
|
19
17
|
if (channel.readyState !== 'open') {
|
20
18
|
return
|
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
|
-
}
|