Skip to content

Commit 7cea7b9

Browse files
tabcatclaude
andauthored
chore(transport-webrtc): remove firefox detection and workarounds (#3467)
* chore(transport-webrtc): remove firefox out-of-order send workaround Firefox no longer delivers small messages out of order, so the `_sendMessage` branch that concatenated buffers on Firefox is no longer needed. Verified by running the `should handle many small writes` transport compliance test (2000 x 1024-byte echoes) over real Firefox WebRTC. * chore(transport-webrtc): drop firefox detection and fallbacks Firefox 113+ supports `connectionstatechange`, so the `iceconnectionstatechange` fallback in `connect.ts` is no longer needed. This was missed when #3279 migrated the rest of the codebase off `detect-browser`. With the stream send workaround also gone, there are no remaining firefox-specific code paths, so drop `isFirefox`, the `detect-browser` dependency, and the `isFirefox` branch in the peer.spec `should connect` test. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 8ddbb9e commit 7cea7b9

6 files changed

Lines changed: 4 additions & 43 deletions

File tree

packages/transport-webrtc/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
"@multiformats/multiaddr-matcher": "^3.0.1",
5858
"@peculiar/webcrypto": "^1.5.0",
5959
"@peculiar/x509": "^2.0.0",
60-
"detect-browser": "^5.3.0",
6160
"get-port": "^7.1.0",
6261
"interface-datastore": "^9.0.1",
6362
"it-length-prefixed": "^10.0.1",

packages/transport-webrtc/src/private-to-public/utils/connect.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { WebRTCTransportError } from '../../error.js'
44
import { DataChannelMuxerFactory } from '../../muxer.js'
55
import { toMultiaddrConnection } from '../../rtcpeerconnection-to-conn.ts'
66
import { createStream } from '../../stream.js'
7-
import { isFirefox } from '../../util.js'
87
import { generateNoisePrologue } from './generate-noise-prologue.ts'
98
import * as sdp from './sdp.ts'
109
import type { DirectRTCPeerConnection } from './get-rtcpeerconnection.ts'
@@ -34,8 +33,6 @@ export interface ServerOptions extends ConnectOptions {
3433
role: 'server'
3534
}
3635

37-
const CONNECTION_STATE_CHANGE_EVENT = isFirefox ? 'iceconnectionstatechange' : 'connectionstatechange'
38-
3936
function isServer (options: ClientOptions | ServerOptions, peerConnection: any): peerConnection is DirectRTCPeerConnection {
4037
return options.role === 'server'
4138
}
@@ -135,7 +132,7 @@ export async function connect (peerConnection: RTCPeerConnection | DirectRTCPeer
135132
log: options.logger.forComponent('libp2p:webrtc-direct:connection')
136133
})
137134

138-
peerConnection.addEventListener(CONNECTION_STATE_CHANGE_EVENT, () => {
135+
peerConnection.addEventListener('connectionstatechange', () => {
139136
switch (peerConnection.connectionState) {
140137
case 'failed':
141138
case 'disconnected':

packages/transport-webrtc/src/stream.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { raceSignal } from 'race-signal'
77
import { Uint8ArrayList } from 'uint8arraylist'
88
import { DEFAULT_FIN_ACK_TIMEOUT, MAX_BUFFERED_AMOUNT, MAX_MESSAGE_SIZE, PROTOBUF_OVERHEAD } from './constants.ts'
99
import { Message } from './private-to-public/pb/message.ts'
10-
import { isFirefox } from './util.ts'
1110
import type { DataChannelOptions } from './index.ts'
1211
import type { AbortOptions, MessageStreamDirection, Logger } from '@libp2p/interface'
1312
import type { AbstractStreamInit, SendResult } from '@libp2p/utils'
@@ -140,14 +139,6 @@ export class WebRTCStream extends AbstractStream {
140139

141140
this.log.trace('sending message, channel state "%s"', this.channel.readyState)
142141

143-
if (isFirefox) {
144-
// TODO: firefox can deliver small messages out of order - remove once a
145-
// browser with https://bugzilla.mozilla.org/show_bug.cgi?id=1983831 is
146-
// available in playwright-test
147-
this.channel.send(data.subarray())
148-
return
149-
}
150-
151142
// send message without copying data
152143
for (const buf of data) {
153144
this.channel.send(buf)

packages/transport-webrtc/src/util.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
import { detect } from 'detect-browser'
21
import pDefer from 'p-defer'
32
import pTimeout from 'p-timeout'
43
import { DATA_CHANNEL_DRAIN_TIMEOUT, DEFAULT_ICE_SERVERS, UFRAG_ALPHABET, UFRAG_PREFIX } from './constants.ts'
54
import type { LoggerOptions } from '@libp2p/interface'
65
import type { Duplex, Source } from 'it-stream-types'
76
import type { PeerConnection } from 'node-datachannel'
87

9-
const browser = detect()
10-
export const isFirefox = ((browser != null) && browser.name === 'firefox')
11-
128
export const nopSource = async function * nop (): AsyncGenerator<Uint8Array, any, unknown> {}
139

1410
export const nopSink = async (_: any): Promise<void> => {}

packages/transport-webrtc/test/peer.spec.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { streamPair, pbStream } from '@libp2p/utils'
55
import { multiaddr } from '@multiformats/multiaddr'
66
import { expect } from 'aegir/chai'
77
import delay from 'delay'
8-
import { detect } from 'detect-browser'
98
import { TypedEventEmitter } from 'main-event'
109
import pRetry from 'p-retry'
1110
import Sinon from 'sinon'
@@ -21,8 +20,6 @@ import type { ConnectionManager, Registrar, TransportManager } from '@libp2p/int
2120
import type { Multiaddr } from '@multiformats/multiaddr'
2221
import type { StubbedInstance } from 'sinon-ts'
2322

24-
const browser = detect()
25-
2623
interface Initiator {
2724
multiaddr: Multiaddr
2825
connectionManager: StubbedInstance<ConnectionManager>
@@ -80,7 +77,6 @@ async function getComponents (): Promise<PrivateToPrivateComponents> {
8077
}
8178

8279
describe('webrtc basic', () => {
83-
const isFirefox = ((browser != null) && browser.name === 'firefox')
8480
let initiator: Initiator
8581
let recipient: Recipient
8682
let initiatorPeerConnection: RTCPeerConnection
@@ -110,11 +106,6 @@ describe('webrtc basic', () => {
110106
).to.eventually.be.fulfilled()
111107

112108
await pRetry(async () => {
113-
if (isFirefox) {
114-
expect(initiatorPeerConnection.iceConnectionState).eq('connected')
115-
expect(recipient.peerConnection.iceConnectionState).eq('connected')
116-
return
117-
}
118109
expect(initiatorPeerConnection.connectionState).eq('connected')
119110
expect(recipient.peerConnection.connectionState).eq('connected')
120111
})

packages/transport-webrtc/test/stream.spec.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { stubInterface } from 'sinon-ts'
88
import { MAX_MESSAGE_SIZE, PROTOBUF_OVERHEAD } from '../src/constants.js'
99
import { Message } from '../src/private-to-public/pb/message.js'
1010
import { createStream } from '../src/stream.js'
11-
import { isFirefox } from '../src/util.ts'
1211
import { RTCPeerConnection } from '../src/webrtc/index.js'
1312
import { receiveFinAck, receiveRemoteCloseWrite } from './util.ts'
1413
import type { WebRTCStream } from '../src/stream.js'
@@ -39,28 +38,16 @@ describe('Max message size', () => {
3938
const sendMore = webrtcStream.send(data)
4039
expect(sendMore).to.be.true()
4140

42-
if (isFirefox) {
43-
// TODO: firefox can deliver small messages out of order - remove once a
44-
// browser with https://bugzilla.mozilla.org/show_bug.cgi?id=1983831 is
45-
// available in playwright-test
46-
expect(channel.send).to.have.property('callCount', 1)
47-
} else {
48-
expect(channel.send).to.have.property('callCount', 2)
49-
}
41+
expect(channel.send).to.have.property('callCount', 2)
5042

5143
const bytes = channel.send.getCalls().reduce((acc, curr) => {
5244
return acc + curr.args[0].byteLength
5345
}, 0)
5446

5547
expect(bytes).to.be.lessThan(MAX_MESSAGE_SIZE)
5648

57-
if (isFirefox) {
58-
// minus 2x bytes because there is no flag field in the protobuf message
59-
expect(channel.send.getCall(0).args[0]).to.have.lengthOf(MAX_MESSAGE_SIZE - 2)
60-
} else {
61-
// minus 2x bytes because there is no flag field in the protobuf message
62-
expect(channel.send.getCall(1).args[0]).to.have.lengthOf(MAX_MESSAGE_SIZE - 4)
63-
}
49+
// minus 2x bytes because there is no flag field in the protobuf message
50+
expect(channel.send.getCall(1).args[0]).to.have.lengthOf(MAX_MESSAGE_SIZE - 4)
6451
})
6552

6653
it(`sends messages greater than ${MAX_MESSAGE_SIZE} bytes in parts`, async () => {

0 commit comments

Comments
 (0)