-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: delay notification of early WebRTC stream creation (#2206)
The datachannel muxer is created during set up of the `Connection` object. If we notify of early stream creation before the `Connection` object is properly configured, the early streams will be lost. This can happen when the remote opens a data channel before the local node has finished setting up it's end of the connection. The fix is to notify asynchronously which gives the upgrader enough time to finish setting up the `Connection`.
- Loading branch information
1 parent
dfbe0cc
commit d25d951
Showing
3 changed files
with
72 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-expressions */ | ||
|
||
import { expect } from 'aegir/chai' | ||
import pRetry from 'p-retry' | ||
import { stubInterface } from 'sinon-ts' | ||
import { DataChannelMuxerFactory } from '../src/muxer.js' | ||
|
||
describe('muxer', () => { | ||
it('should delay notification of early streams', async () => { | ||
let onIncomingStreamInvoked = false | ||
|
||
// @ts-expect-error incomplete implementation | ||
const peerConnection: RTCPeerConnection = {} | ||
|
||
const muxerFactory = new DataChannelMuxerFactory({ | ||
peerConnection | ||
}) | ||
|
||
// simulate early connection | ||
// @ts-expect-error incomplete implementation | ||
const event: RTCDataChannelEvent = { | ||
channel: stubInterface<RTCDataChannel>({ | ||
readyState: 'connecting' | ||
}) | ||
} | ||
peerConnection.ondatachannel?.(event) | ||
|
||
muxerFactory.createStreamMuxer({ | ||
onIncomingStream: () => { | ||
onIncomingStreamInvoked = true | ||
} | ||
}) | ||
|
||
expect(onIncomingStreamInvoked).to.be.false() | ||
|
||
await pRetry(() => { | ||
if (!onIncomingStreamInvoked) { | ||
throw new Error('onIncomingStreamInvoked was still false') | ||
} | ||
}) | ||
|
||
expect(onIncomingStreamInvoked).to.be.true() | ||
}) | ||
}) |