From 5de36ddb1520619d3b57dfed66026fbd2e1e8b7d Mon Sep 17 00:00:00 2001 From: pabloFuente Date: Mon, 17 May 2021 13:30:08 +0200 Subject: [PATCH] openvidu-browser: extend ExceptionEvent with ICE_CONNECTION_DISCONNECTED --- .../OpenViduInternal/Events/ExceptionEvent.ts | 17 +++++++++++++++-- .../OpenViduInternal/WebRtcPeer/WebRtcPeer.ts | 10 ++++++---- openvidu-browser/src/index.ts | 1 + 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/openvidu-browser/src/OpenViduInternal/Events/ExceptionEvent.ts b/openvidu-browser/src/OpenViduInternal/Events/ExceptionEvent.ts index ac17aeee..8c086fa7 100644 --- a/openvidu-browser/src/OpenViduInternal/Events/ExceptionEvent.ts +++ b/openvidu-browser/src/OpenViduInternal/Events/ExceptionEvent.ts @@ -36,9 +36,22 @@ export enum ExceptionEventName { * The [ICE connection state](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/iceConnectionState) * of an [RTCPeerConnection](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection) reached `failed` status. * + * This is a terminal error that won't have any kind of possible recovery. + * * [[ExceptionEvent]] objects with this [[ExceptionEvent.name]] will have as [[ExceptionEvent.origin]] property a [[Stream]] object. */ - ICE_CONNECTION_FAILED = 'ICE_CONNECTION_FAILED' + ICE_CONNECTION_FAILED = 'ICE_CONNECTION_FAILED', + + /** + * The [ICE connection state](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/iceConnectionState) + * of an [RTCPeerConnection](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection) reached `disconnected` status. + * + * This is not a terminal error, and it is possible for the ICE connection to be reconnected. + * + * [[ExceptionEvent]] objects with this [[ExceptionEvent.name]] will have as [[ExceptionEvent.origin]] property a [[Stream]] object. + */ + ICE_CONNECTION_DISCONNECTED = 'ICE_CONNECTION_DISCONNECTED' + } /** @@ -56,7 +69,7 @@ export class ExceptionEvent extends Event { /** * Object affected by the exception. Depending on the [[ExceptionEvent.name]] property: * - [[Session]]: `ICE_CANDIDATE_ERROR` - * - [[Stream]]: `ICE_CONNECTION_FAILED` + * - [[Stream]]: `ICE_CONNECTION_FAILED`, `ICE_CONNECTION_DISCONNECTED` */ origin: Session | Stream; diff --git a/openvidu-browser/src/OpenViduInternal/WebRtcPeer/WebRtcPeer.ts b/openvidu-browser/src/OpenViduInternal/WebRtcPeer/WebRtcPeer.ts index 34e30246..e39154e4 100644 --- a/openvidu-browser/src/OpenViduInternal/WebRtcPeer/WebRtcPeer.ts +++ b/openvidu-browser/src/OpenViduInternal/WebRtcPeer/WebRtcPeer.ts @@ -324,12 +324,14 @@ export class WebRtcPeer { switch (iceConnectionState) { case 'disconnected': // Possible network disconnection - logger.warn('IceConnectionState of RTCPeerConnection ' + this.id + ' (' + otherId + ') change to "disconnected". Possible network disconnection'); + const msg1 = 'IceConnectionState of RTCPeerConnection ' + this.id + ' (' + otherId + ') change to "disconnected". Possible network disconnection'; + logger.warn(msg1); + this.configuration.onexception(ExceptionEventName.ICE_CONNECTION_DISCONNECTED, msg1); break; case 'failed': - const msg = 'IceConnectionState of RTCPeerConnection ' + this.id + ' (' + otherId + ') to "failed"'; - logger.error(msg); - this.configuration.onexception(ExceptionEventName.ICE_CONNECTION_FAILED, msg); + const msg2 = 'IceConnectionState of RTCPeerConnection ' + this.id + ' (' + otherId + ') to "failed"'; + logger.error(msg2); + this.configuration.onexception(ExceptionEventName.ICE_CONNECTION_FAILED, msg2); break; case 'closed': logger.log('IceConnectionState of RTCPeerConnection ' + this.id + ' (' + otherId + ') change to "closed"'); diff --git a/openvidu-browser/src/index.ts b/openvidu-browser/src/index.ts index 8576b022..31579811 100644 --- a/openvidu-browser/src/index.ts +++ b/openvidu-browser/src/index.ts @@ -25,6 +25,7 @@ export { StreamPropertyChangedEvent } from './OpenViduInternal/Events/StreamProp export { ConnectionPropertyChangedEvent } from './OpenViduInternal/Events/ConnectionPropertyChangedEvent'; export { FilterEvent } from './OpenViduInternal/Events/FilterEvent'; export { NetworkQualityLevelChangedEvent } from './OpenViduInternal/Events/NetworkQualityLevelChangedEvent'; +export { ExceptionEvent } from './OpenViduInternal/Events/ExceptionEvent'; export { Capabilities } from './OpenViduInternal/Interfaces/Public/Capabilities'; export { Device } from './OpenViduInternal/Interfaces/Public/Device';