From 25ab56a22b326c43a56738ac3f8cb1cb97e165b1 Mon Sep 17 00:00:00 2001 From: adwpc Date: Fri, 12 Feb 2021 20:30:37 +0800 Subject: [PATCH] feat(restartIce) (#155) --- decs.d.ts | 1 + package.json | 2 +- src/client.ts | 11 ++++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/decs.d.ts b/decs.d.ts index 8c8f84cd..3de73779 100644 --- a/decs.d.ts +++ b/decs.d.ts @@ -328,6 +328,7 @@ interface RTCPeerConnection extends EventTarget { readonly signalingState: RTCSignalingState; readonly connectionState: RTCPeerConnectionState; + restartIce(): void; getConfiguration(): RTCConfiguration; setConfiguration(configuration: RTCConfiguration): void; close(): void; diff --git a/package.json b/package.json index 207bc39a..741d506a 100644 --- a/package.json +++ b/package.json @@ -58,4 +58,4 @@ "ion", "js" ] -} \ No newline at end of file +} diff --git a/src/client.ts b/src/client.ts index cb4f2e6b..f76eca76 100644 --- a/src/client.ts +++ b/src/client.ts @@ -47,7 +47,16 @@ export class Transport { this.signal.trickle({ target: role, candidate }); } }; - } + + this.pc.oniceconnectionstatechange = async (e) => { + if (this.pc.iceConnectionState === "disconnected") { + if (this.pc.restartIce) { + // this will trigger onNegotiationNeeded + this.pc.restartIce(); + } + } + } + }; } export default class Client {