From 944b0214cd2c1870c44689ada70ba010c7934d24 Mon Sep 17 00:00:00 2001 From: Vincent Fretin Date: Sat, 10 Jul 2021 18:45:05 +0200 Subject: [PATCH 1/3] copy index.html to 1.html 2.html 12.html --- examples/1.html | 152 +++++++++++++++++++++++++++++++++++++++++++++++ examples/12.html | 152 +++++++++++++++++++++++++++++++++++++++++++++++ examples/2.html | 152 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 456 insertions(+) create mode 100644 examples/1.html create mode 100644 examples/12.html create mode 100644 examples/2.html diff --git a/examples/1.html b/examples/1.html new file mode 100644 index 0000000..df2a5e4 --- /dev/null +++ b/examples/1.html @@ -0,0 +1,152 @@ + + + + + Audio Example — naf-janus-adapter + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/12.html b/examples/12.html new file mode 100644 index 0000000..df2a5e4 --- /dev/null +++ b/examples/12.html @@ -0,0 +1,152 @@ + + + + + Audio Example — naf-janus-adapter + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/2.html b/examples/2.html new file mode 100644 index 0000000..df2a5e4 --- /dev/null +++ b/examples/2.html @@ -0,0 +1,152 @@ + + + + + Audio Example — naf-janus-adapter + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 08c7a3a38a6927d656dacbe42ba2a0c3aeb0a77d Mon Sep 17 00:00:00 2001 From: Vincent Fretin Date: Sat, 10 Jul 2021 18:46:07 +0200 Subject: [PATCH 2/3] modify room and transport --- examples/1.html | 2 ++ examples/12.html | 4 +++- examples/2.html | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/1.html b/examples/1.html index df2a5e4..cf14ca3 100644 --- a/examples/1.html +++ b/examples/1.html @@ -112,6 +112,8 @@ document.addEventListener('DOMContentLoaded', () => { const scene = document.querySelector('a-scene'); scene.addEventListener('adapter-ready', ({ detail: adapter }) => { + adapter.unreliableTransport = "websocket"; + adapter.reliableTransport = "websocket"; // We don't use the syncOccupants API, set requestedOccupants to be the same array instance as availableOccupants adapter.requestedOccupants = adapter.availableOccupants; const clientId = genClientId(); // generate a random 16 characters string, but you can use a uuid4 for example diff --git a/examples/12.html b/examples/12.html index df2a5e4..3b770e5 100644 --- a/examples/12.html +++ b/examples/12.html @@ -15,7 +15,7 @@ Date: Sat, 10 Jul 2021 18:47:02 +0200 Subject: [PATCH 3/3] subscribe to users of main room, handle join and leave events for other rooms --- src/index.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index c9a0122..0a2bba8 100644 --- a/src/index.js +++ b/src/index.js @@ -531,14 +531,21 @@ class JanusAdapter { // Handle all of the join and leave events. handle.on("event", ev => { var data = ev.plugindata.data; - if (data.event == "join" && data.room_id == this.room) { + if (data.event == "join" && this.room.split('-').indexOf(data.room_id) > -1) { if (this.delayedReconnectTimeout) { // Don't create a new RTCPeerConnection, all RTCPeerConnection will be closed in less than 10s. return; } - this.addAvailableOccupant(data.user_id); - this.syncOccupants(); - } else if (data.event == "leave" && data.room_id == this.room) { + if (data.room_id == this.room.split('-')[0]) { + this.addAvailableOccupant(data.user_id); + this.syncOccupants(); + } else { + // Instead of opening a WebRTC connection and have the dataChannelOpen function called, + // we call completeSync to send the entities to the new user + // but we need to send again to all users (null), sending to data.user_id doesn't work here. + NAF.entities.completeSync(null, true); + } + } else if (data.event == "leave" && this.room.split('-').indexOf(data.room_id) > -1) { this.removeAvailableOccupant(data.user_id); this.removeOccupant(data.user_id); } else if (data.event == "blocked") { @@ -572,7 +579,7 @@ class JanusAdapter { throw err; } - var initialOccupants = message.plugindata.data.response.users[this.room] || []; + var initialOccupants = message.plugindata.data.response.users[this.room.split('-')[0]] || []; if (initialOccupants.includes(this.clientId)) { console.warn("Janus still has previous session for this client. Reconnecting in 10s.");