Skip to content

Commit a4d8d22

Browse files
committed
Merge pull request #150 from uProxy/bemasc-pc-close
Make PeerConnection.close() return a Promise.
2 parents 85a5867 + 1c7ff64 commit a4d8d22

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "uproxy-lib",
33
"description": "Shared libraries for uProxy projects.",
4-
"version": "20.1.1",
4+
"version": "21.0.0",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/uProxy/uproxy-lib"

src/webrtc/peerconnection.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export interface PeerConnection<TSignallingMessage> {
8787
// Closing the peer connection will close all associated data channels
8888
// and set |pcState| to |DISCONNECTED| (and hence fulfills
8989
// |onceDisconnected|)
90-
close: () => void;
90+
close: () => Promise<void>;
9191
}
9292

9393
export interface SignallingMessage {
@@ -260,25 +260,20 @@ export class PeerConnectionClass implements PeerConnection<SignallingMessage> {
260260
}
261261

262262
// Close the peer connection. This function is idempotent.
263-
public close = () : void => {
263+
public close = () : Promise<void> => {
264264
log.info(this.peerName_ + ': ' + 'close');
265265

266-
// This may happen because calling close will invoke pc_.close, which
267-
// may call |onSignallingStateChange_| with |this.pc_.signalingState ===
268-
// 'closed'|.
269-
if (this.pcState === State.DISCONNECTED) { return; }
270-
271266
if (this.pcState === State.CONNECTING) {
272267
this.rejectConnected_(new Error('close was called while connecting.'));
273268
}
274269

275270
this.pcState = State.DISCONNECTED;
276271
this.fulfillDisconnected_();
277272

278-
this.pc_.getSignalingState().then((state:string) => {
273+
return this.pc_.getSignalingState().then((state:string) => {
279274
if (state !== 'closed') {
280275
// Note is expected to invoke |onSignallingStateChange_|
281-
this.pc_.close();
276+
return this.pc_.close();
282277
}
283278
});
284279
}

0 commit comments

Comments
 (0)