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 };