From a748d251096780b93ebb364ab81adc129a5e2b64 Mon Sep 17 00:00:00 2001 From: Francesco Durighetto Date: Wed, 30 May 2018 22:11:01 +0200 Subject: [PATCH] Fix the way ICE propagates connection state events (#1232) --- .../erizoClient/src/ErizoConnectionManager.js | 3 ++- erizo_controller/erizoClient/src/Room.js | 12 ++++++++---- erizo_controller/erizoClient/src/Stream.js | 4 ++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/erizo_controller/erizoClient/src/ErizoConnectionManager.js b/erizo_controller/erizoClient/src/ErizoConnectionManager.js index d6d0b1f373..ae0a68face 100644 --- a/erizo_controller/erizoClient/src/ErizoConnectionManager.js +++ b/erizo_controller/erizoClient/src/ErizoConnectionManager.js @@ -65,7 +65,8 @@ class ErizoConnection extends EventEmitterConst { this.emit(ConnectionEvent({ type: 'remove-stream', stream: evt.stream })); }; - this.stack.peerConnection.oniceconnectionstatechange = (state) => { + this.stack.peerConnection.oniceconnectionstatechange = () => { + const state = this.stack.peerConnection.iceConnectionState; this.emit(ConnectionEvent({ type: 'ice-state-change', state })); }; } diff --git a/erizo_controller/erizoClient/src/Room.js b/erizo_controller/erizoClient/src/Room.js index 7fb227fa13..b2953a7418 100644 --- a/erizo_controller/erizoClient/src/Room.js +++ b/erizo_controller/erizoClient/src/Room.js @@ -125,7 +125,8 @@ const Room = (altIo, altConnectionHelpers, altConnectionManager, specInput) => { getP2PConnectionOptions(stream, peerSocket))); stream.on('added', dispatchStreamSubscribed.bind(null, stream)); stream.on('icestatechanged', (evt) => { - if (evt.state === 'failed') { + Logger.info(`${stream.getID()} - iceConnectionState: ${evt.msg.state}`); + if (evt.msg.state === 'failed') { onStreamFailed(stream); } }); @@ -139,7 +140,8 @@ const Room = (altIo, altConnectionHelpers, altConnectionManager, specInput) => { stream.addPC(connection, peerSocket); stream.on('icestatechanged', (evt) => { - if (evt.state === 'failed') { + Logger.info(`${stream.getID()} - iceConnectionState: ${evt.msg.state}`); + if (evt.msg.state === 'failed') { stream.pc.get(peerSocket).close(); stream.pc.remove(peerSocket); } @@ -193,7 +195,8 @@ const Room = (altIo, altConnectionHelpers, altConnectionManager, specInput) => { getErizoConnectionOptions(stream, options, true), erizoId, spec.singlePC)); stream.on('added', dispatchStreamSubscribed.bind(null, stream)); stream.on('icestatechanged', (evt) => { - if (evt.state === 'failed') { + Logger.info(`${stream.getID()} - iceConnectionState: ${evt.msg.state}`); + if (evt.msg.state === 'failed') { onStreamFailed(stream); } }); @@ -206,7 +209,8 @@ const Room = (altIo, altConnectionHelpers, altConnectionManager, specInput) => { getErizoConnectionOptions(stream, options), erizoId, spec.singlePC)); stream.on('icestatechanged', (evt) => { - if (evt.state === 'failed') { + Logger.info(`${stream.getID()} - iceConnectionState: ${evt.msg.state}`); + if (evt.msg.state === 'failed') { onStreamFailed(stream); } }); diff --git a/erizo_controller/erizoClient/src/Stream.js b/erizo_controller/erizoClient/src/Stream.js index 08def71d9d..2e524e11ba 100644 --- a/erizo_controller/erizoClient/src/Stream.js +++ b/erizo_controller/erizoClient/src/Stream.js @@ -45,8 +45,8 @@ const Stream = (altConnectionHelpers, specInput) => { } }; - const onICEConnectionStateChange = (state) => { - that.emit(StreamEvent({ type: 'icestatechanged', msg: state })); + const onICEConnectionStateChange = (msg) => { + that.emit(StreamEvent({ type: 'icestatechanged', msg })); }; if (that.videoSize !== undefined &&