Skip to content

Commit 2bf43a2

Browse files
committed
feat: close only after ICE restart
this prevents possible spurious ICE restarts on disconnect
1 parent b569cee commit 2bf43a2

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

demo-react/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ function ChatDialog(props: ChatDialogProps) {
328328
const date = new Date(Number.parseInt(ts));
329329

330330
return (
331-
<nav>
331+
<nav key={key}>
332332
<button className="circle capitalize">
333333
{peerId.substring(0, 1)}
334334
</button>

peer/src/session.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,19 @@ export class Session {
7575
/**
7676
* See {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/ondatachannel}
7777
*/
78-
public ondatachannel: RTCPeerConnection["ondatachannel"] = () => {};
78+
public ondatachannel: RTCPeerConnection["ondatachannel"] = () => { };
7979

8080
/**
8181
* See {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/onconnectionstatechange}
8282
*/
8383
public onconnectionstatechange: RTCPeerConnection["onconnectionstatechange"] =
84-
() => {};
84+
() => { };
8585

8686
/**
8787
* Callback invoked when a new media track is added to the connection.
8888
* See {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/ontrack}
8989
*/
90-
public ontrack: RTCPeerConnection["ontrack"] = () => {};
90+
public ontrack: RTCPeerConnection["ontrack"] = () => { };
9191

9292
/**
9393
* Adds a media track to the connection.
@@ -183,6 +183,7 @@ export class Session {
183183

184184
this.logger.debug("session closed", {
185185
connectionState: this.connectionState,
186+
reason,
186187
});
187188
}
188189

@@ -274,10 +275,9 @@ export class Session {
274275
break;
275276
}
276277
case "disconnected":
277-
this.triggerIceRestart();
278278
break;
279279
case "failed":
280-
this.close("connection failed");
280+
this.triggerIceRestart();
281281
break;
282282
case "closed":
283283
break;
@@ -423,9 +423,9 @@ export class Session {
423423
}
424424

425425
private triggerIceRestart = () => {
426-
// the impolite offer will trigger the polite peer's to also restart Ice
427-
if (!this.impolite) return;
428-
426+
// // the impolite offer will trigger the polite peer's to also restart Ice
427+
// if (!this.impolite) return;
428+
//
429429
const elapsed = performance.now() - this.lastIceRestart;
430430
if (elapsed < ICE_RESTART_DEBOUNCE_DELAY_MS) {
431431
// schedule ice restart after some delay;

peer/src/store.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,10 @@ export class PeerStore {
140140
if (sess.connectionState === "closed") {
141141
const current = this.$_remotePeers.get();
142142
delete current[id];
143-
this.$_remotePeers.set({ ...current });
144-
return;
145-
}
146-
147-
if (sess.connectionState === "failed") {
148143
delete this.sendChannels[id];
149144
console.log(`connection failed, removed ${id}`);
145+
this.$_remotePeers.set({ ...current });
146+
return;
150147
}
151148

152149
const remotePeer = this.$_remotePeers.get()[id];

0 commit comments

Comments
 (0)