From b121802132b4ad50ef67965d95a9c2fa201aa7a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Cervi=C3=B1o?= Date: Mon, 24 Feb 2020 10:05:12 +0100 Subject: [PATCH] Improve the way we look for Erizo Client Connections internally (#1544) --- .../erizoClient/src/ErizoConnectionManager.js | 12 +++++++++++ erizo_controller/erizoClient/src/Room.js | 21 ++++--------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/erizo_controller/erizoClient/src/ErizoConnectionManager.js b/erizo_controller/erizoClient/src/ErizoConnectionManager.js index 72e90c8ba9..cb2c3bee8b 100644 --- a/erizo_controller/erizoClient/src/ErizoConnectionManager.js +++ b/erizo_controller/erizoClient/src/ErizoConnectionManager.js @@ -168,6 +168,18 @@ class ErizoConnectionManager { this.ErizoConnectionsMap = new Map(); // key: erizoId, value: {connectionId: connection} } + getErizoConnection(erizoConnectionId) { + let connection; + this.ErizoConnectionsMap.forEach((entry) => { + Object.keys(entry).forEach((entryKey) => { + if (entry[entryKey].connectionId === erizoConnectionId) { + connection = entry[entryKey]; + } + }); + }); + return connection; + } + getOrBuildErizoConnection(specInput, erizoId = undefined, singlePC = false) { Logger.debug(`message: getOrBuildErizoConnection, erizoId: ${erizoId}`); let connection = {}; diff --git a/erizo_controller/erizoClient/src/Room.js b/erizo_controller/erizoClient/src/Room.js index 7a3a6f0dfc..67fe73c483 100644 --- a/erizo_controller/erizoClient/src/Room.js +++ b/erizo_controller/erizoClient/src/Room.js @@ -386,27 +386,14 @@ const Room = (altIo, altConnectionHelpers, altConnectionManager, specInput) => { }; const socketOnConnectionMessageFromErizo = (arg) => { - let done = false; if (arg.evt.type === 'quality_level') { socketOnConnectionQualityLevel(arg); return; } - localStreams.forEach((stream) => { - if (!done && !stream.failed && stream.pc && stream.pc.connectionId === arg.connectionId) { - stream.pc.processSignalingMessage(arg.evt); - done = true; - } - }); - if (done) { - return; - } - remoteStreams.forEach((stream) => { - if (!done && !stream.failed && stream.pc && stream.pc.connectionId === arg.connectionId) { - stream.pc.processSignalingMessage(arg.evt); - done = true; - } - }); - if (!done) { + const connection = that.erizoConnectionManager.getErizoConnection(arg.connectionId); + if (connection) { + connection.processSignalingMessage(arg.evt); + } else { Logger.warning('Received signaling message to unknown connectionId', arg.connectionId); } };