From c246686c4c3c3294db45ee5ac0887677b72defc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Wa=C5=9Bniowski?= Date: Wed, 17 Apr 2024 17:54:52 +0200 Subject: [PATCH] feat: expose on ice candidate event callback (#74) --- src/peer-connection.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/peer-connection.ts b/src/peer-connection.ts index d05ab3b..7018b49 100644 --- a/src/peer-connection.ts +++ b/src/peer-connection.ts @@ -27,6 +27,7 @@ type IceGatheringStateChangeEvent = { enum PeerConnectionEvents { IceGatheringStateChange = 'icegatheringstatechange', + IceCandidate = 'icecandidate', ConnectionStateChange = 'connectionstatechange', CreateOfferOnSuccess = 'createofferonsuccess', CreateAnswerOnSuccess = 'createansweronsuccess', @@ -36,6 +37,7 @@ enum PeerConnectionEvents { interface PeerConnectionEventHandlers extends EventMap { [PeerConnectionEvents.IceGatheringStateChange]: (ev: IceGatheringStateChangeEvent) => void; + [PeerConnectionEvents.IceCandidate]: (ev: RTCPeerConnectionIceEvent) => void; [PeerConnectionEvents.ConnectionStateChange]: (state: ConnectionState) => void; [PeerConnectionEvents.CreateOfferOnSuccess]: (offer: RTCSessionDescriptionInit) => void; [PeerConnectionEvents.CreateAnswerOnSuccess]: (answer: RTCSessionDescriptionInit) => void; @@ -96,6 +98,10 @@ class PeerConnection extends EventEmitter { this.pc.onicegatheringstatechange = (ev: Event) => { this.emit(PeerConnection.Events.IceGatheringStateChange, ev); }; + + this.pc.onicecandidate = (ev: RTCPeerConnectionIceEvent) => { + this.emit(PeerConnection.Events.IceCandidate, ev); + }; } /** @@ -369,4 +375,4 @@ class PeerConnection extends EventEmitter { } export { ConnectionState } from './connection-state-handler'; -export { MediaStreamTrackKind, RTCDataChannelOptions, PeerConnection }; +export { MediaStreamTrackKind, PeerConnection, RTCDataChannelOptions };