Skip to content

Commit

Permalink
feat: expose on ice candidate event callback (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
k-wasniowski authored Apr 17, 2024
1 parent d204dba commit c246686
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/peer-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type IceGatheringStateChangeEvent = {

enum PeerConnectionEvents {
IceGatheringStateChange = 'icegatheringstatechange',
IceCandidate = 'icecandidate',
ConnectionStateChange = 'connectionstatechange',
CreateOfferOnSuccess = 'createofferonsuccess',
CreateAnswerOnSuccess = 'createansweronsuccess',
Expand All @@ -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;
Expand Down Expand Up @@ -96,6 +98,10 @@ class PeerConnection extends EventEmitter<PeerConnectionEventHandlers> {
this.pc.onicegatheringstatechange = (ev: Event) => {
this.emit(PeerConnection.Events.IceGatheringStateChange, ev);
};

this.pc.onicecandidate = (ev: RTCPeerConnectionIceEvent) => {
this.emit(PeerConnection.Events.IceCandidate, ev);
};
}

/**
Expand Down Expand Up @@ -369,4 +375,4 @@ class PeerConnection extends EventEmitter<PeerConnectionEventHandlers> {
}

export { ConnectionState } from './connection-state-handler';
export { MediaStreamTrackKind, RTCDataChannelOptions, PeerConnection };
export { MediaStreamTrackKind, PeerConnection, RTCDataChannelOptions };

0 comments on commit c246686

Please sign in to comment.