From de94b2d6e5c806d770576636c67877959190cd5b Mon Sep 17 00:00:00 2001 From: kwasniow Date: Fri, 24 Apr 2026 10:47:39 +0200 Subject: [PATCH] feat: peer connection support setConfiguration api --- src/mocks/rtc-peer-connection-stub.ts | 1 + src/peer-connection.spec.ts | 21 +++++++++++++++++++++ src/peer-connection.ts | 9 +++++++++ 3 files changed, 31 insertions(+) diff --git a/src/mocks/rtc-peer-connection-stub.ts b/src/mocks/rtc-peer-connection-stub.ts index bbc14b6..dba9b19 100644 --- a/src/mocks/rtc-peer-connection-stub.ts +++ b/src/mocks/rtc-peer-connection-stub.ts @@ -27,6 +27,7 @@ class RTCPeerConnectionStub { ): Promise { return new Promise(() => {}); } + setConfiguration(configuration?: RTCConfiguration): void {} onconnectionstatechange: () => void = () => {}; oniceconnectionstatechange: () => void = () => {}; onicecandidate: (event: RTCPeerConnectionIceEvent) => void = () => {}; diff --git a/src/peer-connection.spec.ts b/src/peer-connection.spec.ts index b2ea7e4..fb4ab4b 100644 --- a/src/peer-connection.spec.ts +++ b/src/peer-connection.spec.ts @@ -478,6 +478,27 @@ describe('PeerConnection', () => { }); }); + describe('setConfiguration', () => { + let mockPc: MockedObjectDeep; + let pc: PeerConnection; + + beforeEach(() => { + jest.clearAllMocks(); + mockPc = mocked(new RTCPeerConnectionStub(), true); + mockCreateRTCPeerConnection.mockReturnValueOnce(mockPc as unknown as RTCPeerConnection); + pc = new PeerConnection(); + }); + + it('should call setConfiguration on the underlying peer connection', () => { + expect.hasAssertions(); + const configuration: RTCConfiguration = { + iceServers: [{ urls: 'stun:stun.example.com' }], + }; + pc.setConfiguration(configuration); + expect(mockPc.setConfiguration).toHaveBeenCalledWith(configuration); + }); + }); + describe('setRemoteDescription', () => { let mockPc: MockedObjectDeep; let setRemoteDescriptionSpy: jest.SpyInstance; diff --git a/src/peer-connection.ts b/src/peer-connection.ts index 1d15ec4..4f97986 100644 --- a/src/peer-connection.ts +++ b/src/peer-connection.ts @@ -172,6 +172,15 @@ class PeerConnection extends EventEmitter { return this.iceCandidates; } + /** + * Sets the current configuration of the underlying RTCPeerConnection. + * + * @param configuration - An RTCConfiguration object which provides the options to be set. + */ + setConfiguration(configuration: RTCConfiguration): void { + this.pc.setConfiguration(configuration); + } + /** * Adds a new media track to the set of tracks which will be transmitted to the other peer. *