Skip to content

Commit

Permalink
fix(webrtc-core): added onSuccess suffix to new events
Browse files Browse the repository at this point in the history
  • Loading branch information
fnowakow committed Feb 13, 2024
1 parent f799f88 commit dad425e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
"WCME",
"webex",
"webrtc",
"createoffer",
"setlocaldescription",
"setremotedescription"
"createofferonsuccess",
"setlocaldescriptiononsuccess",
"setremotedescriptiononsuccess"
],
"flagWords": [],
"ignorePaths": [
Expand Down
6 changes: 3 additions & 3 deletions src/peer-connection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ describe('PeerConnection', () => {
mockCreateRTCPeerConnection.mockReturnValueOnce(mockPc as unknown as RTCPeerConnection);
pc = new PeerConnection();
createOfferSpy = jest.spyOn(pc, 'createOffer');
pc.on(PeerConnection.Events.CreateOffer, callback);
pc.on(PeerConnection.Events.CreateOfferOnSuccess, callback);
});

it('should emit event when createOffer called', async () => {
Expand Down Expand Up @@ -317,7 +317,7 @@ describe('PeerConnection', () => {
});
setLocalDescriptionSpy = jest.spyOn(mockPc, 'setLocalDescription');
pc = new PeerConnection();
pc.on(PeerConnection.Events.SetLocalDescription, callback);
pc.on(PeerConnection.Events.SetLocalDescriptionOnSuccess, callback);
});

it('sets the local description with an SDP offer', async () => {
Expand Down Expand Up @@ -382,7 +382,7 @@ describe('PeerConnection', () => {
mockCreateRTCPeerConnection.mockReturnValueOnce(mockPc as unknown as RTCPeerConnection);
pc = new PeerConnection();
setRemoteDescriptionSpy = jest.spyOn(pc, 'setRemoteDescription');
pc.on(PeerConnection.Events.SetRemoteDescription, callback);
pc.on(PeerConnection.Events.SetRemoteDescriptionOnSuccess, callback);
});

it('should emit event when setRemoteDescription called', async () => {
Expand Down
18 changes: 9 additions & 9 deletions src/peer-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ type IceGatheringStateChangeEvent = {
enum PeerConnectionEvents {
IceGatheringStateChange = 'icegatheringstatechange',
ConnectionStateChange = 'connectionstatechange',
CreateOffer = 'createoffer',
SetLocalDescription = 'setlocaldescription',
SetRemoteDescription = 'setremotedescription',
CreateOfferOnSuccess = 'createofferonsuccess',
SetLocalDescriptionOnSuccess = 'setlocaldescriptiononsuccess',
SetRemoteDescriptionOnSuccess = 'setremotedescriptiononsuccess',
}

interface PeerConnectionEventHandlers extends EventMap {
[PeerConnectionEvents.IceGatheringStateChange]: (ev: IceGatheringStateChangeEvent) => void;
[PeerConnectionEvents.ConnectionStateChange]: (state: ConnectionState) => void;
[PeerConnectionEvents.CreateOffer]: (offer: RTCSessionDescriptionInit) => void;
[PeerConnectionEvents.SetLocalDescription]: (
[PeerConnectionEvents.CreateOfferOnSuccess]: (offer: RTCSessionDescriptionInit) => void;
[PeerConnectionEvents.SetLocalDescriptionOnSuccess]: (
description: RTCSessionDescription | RTCSessionDescriptionInit
) => void;
[PeerConnectionEvents.SetRemoteDescription]: (
[PeerConnectionEvents.SetRemoteDescriptionOnSuccess]: (
description: RTCSessionDescription | RTCSessionDescriptionInit
) => void;
}
Expand Down Expand Up @@ -198,7 +198,7 @@ class PeerConnection extends EventEmitter<PeerConnectionEventHandlers> {
*/
async createOffer(options?: RTCOfferOptions): Promise<RTCSessionDescriptionInit> {
return this.pc.createOffer(options).then((offer) => {
this.emit(PeerConnection.Events.CreateOffer, offer);
this.emit(PeerConnection.Events.CreateOfferOnSuccess, offer);
return offer;
});
}
Expand Down Expand Up @@ -231,7 +231,7 @@ class PeerConnection extends EventEmitter<PeerConnectionEventHandlers> {

return this.pc.setLocalDescription(description).then(() => {
if (description) {
this.emit(PeerConnection.Events.SetLocalDescription, description);
this.emit(PeerConnection.Events.SetLocalDescriptionOnSuccess, description);
}
});
}
Expand All @@ -249,7 +249,7 @@ class PeerConnection extends EventEmitter<PeerConnectionEventHandlers> {
description: RTCSessionDescription | RTCSessionDescriptionInit
): Promise<void> {
return this.pc.setRemoteDescription(description).then(() => {
this.emit(PeerConnection.Events.SetRemoteDescription, description);
this.emit(PeerConnection.Events.SetRemoteDescriptionOnSuccess, description);
});
}

Expand Down

0 comments on commit dad425e

Please sign in to comment.