From 5771fbd2e9d44505441da8b9142eb323d48b7735 Mon Sep 17 00:00:00 2001 From: naveenkirugulige Date: Wed, 4 Mar 2026 16:22:50 +0530 Subject: [PATCH] api: throw error in addIceCandidate when peer connection is closed Browsers (Chrome, Firefox, Safari) throw an InvalidStateError when addIceCandidate is called on a closed RTCPeerConnection, as per the W3C WebRTC spec. This change aligns react-native-webrtc with that behavior by throwing an error instead of silently proceeding. This is consistent with how addTrack and removeTrack already handle the closed state in this codebase. Fixes: #1795 --- src/RTCPeerConnection.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/RTCPeerConnection.ts b/src/RTCPeerConnection.ts index 9cfe1a540..4315e2f3f 100644 --- a/src/RTCPeerConnection.ts +++ b/src/RTCPeerConnection.ts @@ -326,6 +326,10 @@ export default class RTCPeerConnection extends EventTarget { + if (this.connectionState === 'closed') { + throw new Error('Peer Connection is closed'); + } + log.debug(`${this._pcId} addIceCandidate`); if (!candidate || !candidate.candidate) {