On Peer Connection Created
Web only
This event is only available in the JavaScript/TypeScript SDK.
Fired when the SDK instantiates a new RTCPeerConnection for a call, before ICE gathering begins. Subscribe to this event to observe low-level WebRTC lifecycle events such as connection state, ICE connection state, and ICE gathering state changes.
Event Registration
client.on("peerConnectionCreated", (callId: string | null, pc: RTCPeerConnection) => {
// Handle peer connection created event
});
Usage Example
client.on('peerConnectionCreated', (callId, pc) => {
console.log(`Peer connection created for call ${callId}`);
pc.addEventListener('connectionstatechange', () => {
console.log(`[PC ${callId}] connectionState: ${pc.connectionState}`);
});
pc.addEventListener('iceconnectionstatechange', () => {
console.log(
`[PC ${callId}] iceConnectionState: ${pc.iceConnectionState}`
);
});
pc.addEventListener('icegatheringstatechange', () => {
console.log(`[PC ${callId}] iceGatheringState: ${pc.iceGatheringState}`);
});
});Event Data
| Parameter | Type | Description |
|---|---|---|
callId | string | null | The call identifier. null for outbound calls — the server has not yet assigned an ID at the point the peer connection is created |
pc | RTCPeerConnection | The underlying WebRTC peer connection instance |
Notes
- This event fires before ICE gathering begins, giving you the earliest opportunity to attach WebRTC event listeners
- Use
pc.addEventListener(...)to subscribe to WebRTC events on the peer connection - This event is
@experimentaland may change in future releases
Related Actions
getPeerConnection- Retrieve the peer connection for an active call by ID after it has been established