From d717cd36be8bc539396c4713a2f4b6e4fe9d3b4c Mon Sep 17 00:00:00 2001 From: Vincent Fretin Date: Wed, 24 Apr 2024 16:08:00 +0200 Subject: [PATCH 1/4] Don't subscribe to audio/video if occupantId ends with '-l' meaning they are only listener and doesn't talk --- src/index.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index 3281255..94255bf 100644 --- a/src/index.js +++ b/src/index.js @@ -337,13 +337,17 @@ class JanusAdapter { this.leftOccupants.delete(occupantId); - var subscriber = await this.createSubscriber(occupantId); + if (occupantId.endsWith("-l")) { + this.occupants[occupantId] = {}; + } else { + var subscriber = await this.createSubscriber(occupantId); - if (!subscriber) return; + if (!subscriber) return; - this.occupants[occupantId] = subscriber; + this.occupants[occupantId] = subscriber; - this.setMediaStream(occupantId, subscriber.mediaStream); + this.setMediaStream(occupantId, subscriber.mediaStream); + } // Call the Networked AFrame callbacks for the new occupant. this.onOccupantConnected(occupantId); @@ -363,7 +367,7 @@ class JanusAdapter { if (this.occupants[occupantId]) { // Close the subscriber peer connection. Which also detaches the plugin handle. - this.occupants[occupantId].conn.close(); + this.occupants[occupantId].conn?.close(); delete this.occupants[occupantId]; } @@ -445,7 +449,7 @@ class JanusAdapter { var conn = new RTCPeerConnection(this.peerConnectionConfig || DEFAULT_PEER_CONNECTION_CONFIG); debug("pub waiting for sfu"); - await handle.attach("janus.plugin.sfu", this.loops && this.clientId ? parseInt(this.clientId) % this.loops : undefined); + await handle.attach("janus.plugin.sfu", this.loops && this.clientId ? parseInt(this.clientId.replace("-l", "")) % this.loops : undefined); this.associate(conn, handle); @@ -585,7 +589,7 @@ class JanusAdapter { var conn = new RTCPeerConnection(this.peerConnectionConfig || DEFAULT_PEER_CONNECTION_CONFIG); debug(occupantId + ": sub waiting for sfu"); - await handle.attach("janus.plugin.sfu", this.loops ? parseInt(occupantId) % this.loops : undefined); + await handle.attach("janus.plugin.sfu", this.loops ? parseInt(occupantId.replace("-l", "")) % this.loops : undefined); this.associate(conn, handle); From 595fd860870f95939b683081cd832226f1ede51f Mon Sep 17 00:00:00 2001 From: Vincent Fretin Date: Wed, 24 Apr 2024 17:02:02 +0200 Subject: [PATCH 2/4] removing -l suffix not needed here, we don't subscribe to listener --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 94255bf..ea294af 100644 --- a/src/index.js +++ b/src/index.js @@ -589,7 +589,7 @@ class JanusAdapter { var conn = new RTCPeerConnection(this.peerConnectionConfig || DEFAULT_PEER_CONNECTION_CONFIG); debug(occupantId + ": sub waiting for sfu"); - await handle.attach("janus.plugin.sfu", this.loops ? parseInt(occupantId.replace("-l", "")) % this.loops : undefined); + await handle.attach("janus.plugin.sfu", this.loops ? parseInt(occupantId) % this.loops : undefined); this.associate(conn, handle); From cdae1d75e43d9d77ec3e51311e646b7940a24784 Mon Sep 17 00:00:00 2001 From: Vincent Fretin Date: Wed, 24 Apr 2024 17:21:09 +0200 Subject: [PATCH 3/4] properly define subscriber variable that is returned --- src/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index ea294af..412b261 100644 --- a/src/index.js +++ b/src/index.js @@ -337,10 +337,12 @@ class JanusAdapter { this.leftOccupants.delete(occupantId); + var subscriber; if (occupantId.endsWith("-l")) { - this.occupants[occupantId] = {}; + subscriber = {}; + this.occupants[occupantId] = subscriber; } else { - var subscriber = await this.createSubscriber(occupantId); + subscriber = await this.createSubscriber(occupantId); if (!subscriber) return; From 5829c5a5cf4d9ab966ad2c9567560bc2a27f2a95 Mon Sep 17 00:00:00 2001 From: Vincent Fretin Date: Tue, 30 Apr 2024 18:11:14 +0200 Subject: [PATCH 4/4] parseInt already removes non number characters --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 412b261..629a3ce 100644 --- a/src/index.js +++ b/src/index.js @@ -451,7 +451,7 @@ class JanusAdapter { var conn = new RTCPeerConnection(this.peerConnectionConfig || DEFAULT_PEER_CONNECTION_CONFIG); debug("pub waiting for sfu"); - await handle.attach("janus.plugin.sfu", this.loops && this.clientId ? parseInt(this.clientId.replace("-l", "")) % this.loops : undefined); + await handle.attach("janus.plugin.sfu", this.loops && this.clientId ? parseInt(this.clientId) % this.loops : undefined); this.associate(conn, handle);