From d85513dc650fb3d3121fb64ff248be715f55f309 Mon Sep 17 00:00:00 2001 From: Christopher Van Wiemeersch Date: Thu, 17 May 2018 16:37:57 -0500 Subject: [PATCH 1/7] fix `TypeError: Cannot read property enableMicrophone of undefined` error in `src/components/mute-mic.js` (fixes #394) --- src/components/mute-mic.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/components/mute-mic.js b/src/components/mute-mic.js index 00729ba190..adc3191274 100644 --- a/src/components/mute-mic.js +++ b/src/components/mute-mic.js @@ -46,24 +46,32 @@ AFRAME.registerComponent("mute-mic", { onToggle: function() { if (this.el.is("muted")) { - NAF.connection.adapter.enableMicrophone(true); + if (NAF.connection.adapter) { + NAF.connection.adapter.enableMicrophone(true); + } this.el.removeState("muted"); } else { - NAF.connection.adapter.enableMicrophone(false); + if (NAF.connection.adapter) { + NAF.connection.adapter.enableMicrophone(false); + } this.el.addState("muted"); } }, onMute: function() { if (!this.el.is("muted")) { - NAF.connection.adapter.enableMicrophone(false); + if (NAF.connection.adapter) { + NAF.connection.adapter.enableMicrophone(false); + } this.el.addState("muted"); } }, onUnmute: function() { if (this.el.is("muted")) { - NAF.connection.adapter.enableMicrophone(true); + if (NAF.connection.adapter) { + NAF.connection.adapter.enableMicrophone(true); + } this.el.removeState("muted"); } } From 509a2b745b5067112807aef55cf41ddded0b11e2 Mon Sep 17 00:00:00 2001 From: Christopher Van Wiemeersch Date: Mon, 21 May 2018 17:14:44 -0500 Subject: [PATCH 2/7] handle `toggleFreeze` error, etc. --- src/components/block-button.js | 14 +++++++-- src/components/freeze-controller.js | 12 ++++---- src/components/networked-video-player.js | 4 +++ src/hub.js | 36 ++++++++++++++++-------- 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/src/components/block-button.js b/src/components/block-button.js index 9dc23988c3..3a8decfe3c 100644 --- a/src/components/block-button.js +++ b/src/components/block-button.js @@ -17,12 +17,20 @@ AFRAME.registerComponent("block-button", { }, block(clientId) { - NAF.connection.adapter.block(clientId); + if (NAF.connection && NAF.connection.adapter) { + NAF.connection.adapter.block(clientId); + } }, // Currently unused unblock(clientId) { - NAF.connection.adapter.unblock(clientId); - NAF.connection.entities.completeSync(clientId); + if (NAF.connection) { + if (NAF.connection.adapter) { + NAF.connection.adapter.unblock(clientId); + } + if (NAF.connection.entities) { + NAF.connection.entities.completeSync(clientId); + } + } } }); diff --git a/src/components/freeze-controller.js b/src/components/freeze-controller.js index 3cb64d76d9..58b5dcdeb0 100644 --- a/src/components/freeze-controller.js +++ b/src/components/freeze-controller.js @@ -17,11 +17,13 @@ AFRAME.registerComponent("freeze-controller", { onToggle: function() { window.APP.store.update({ activity: { hasFoundFreeze: true } }); - NAF.connection.adapter.toggleFreeze(); - if (NAF.connection.adapter.frozen) { - this.el.addState("frozen"); - } else { - this.el.removeState("frozen"); + if (NAF.connection && NAF.connection.adapter) { + NAF.connection.adapter.toggleFreeze(); + if (NAF.connection.adapter.frozen) { + this.el.addState("frozen"); + } else { + this.el.removeState("frozen"); + } } } }); diff --git a/src/components/networked-video-player.js b/src/components/networked-video-player.js index 189a43e393..aa6b08e0f5 100644 --- a/src/components/networked-video-player.js +++ b/src/components/networked-video-player.js @@ -37,6 +37,10 @@ AFRAME.registerComponent("networked-video-player", { document.body.appendChild(container); } + if (!NAF.connection.adapter || !NAF.connection.adapter.getMediaStream) { + return; + } + const stream = await NAF.connection.adapter.getMediaStream(ownerId, "video"); if (!stream) { return; diff --git a/src/hub.js b/src/hub.js index 8bd8e2a29f..f80fd12079 100644 --- a/src/hub.js +++ b/src/hub.js @@ -273,16 +273,22 @@ const onReady = async () => { mediaStream.removeTrack(track); } } - NAF.connection.adapter.setLocalMediaStream(mediaStream); + if (NAF.connection.adapter && NAF.connection.adapter.setLocalMediaStream) { + NAF.connection.adapter.setLocalMediaStream(mediaStream); + } screenEntity.setAttribute("visible", sharingScreen); }); document.body.addEventListener("blocked", ev => { - NAF.connection.entities.removeEntitiesOfClient(ev.detail.clientId); + if (NAF.connection.entities) { + NAF.connection.entities.removeEntitiesOfClient(ev.detail.clientId); + } }); document.body.addEventListener("unblocked", ev => { - NAF.connection.entities.completeSync(ev.detail.clientId); + if (NAF.connection.entities) { + NAF.connection.entities.completeSync(ev.detail.clientId); + } }); if (!qsTruthy("offline")) { @@ -292,19 +298,25 @@ const onReady = async () => { store.update({ activity: { lastEnteredAt: moment().toJSON() } }); }); } - remountUI({ occupantCount: NAF.connection.adapter.publisher.initialOccupants.length + 1 }); + if (NAF.connection.adapter) { + remountUI({ occupantCount: NAF.connection.adapter.publisher.initialOccupants.length + 1 }); + } }); document.body.addEventListener("clientConnected", () => { - remountUI({ - occupantCount: Object.keys(NAF.connection.adapter.occupants).length + 1 - }); + if (NAF.connection.adapter) { + remountUI({ + occupantCount: Object.keys(NAF.connection.adapter.occupants).length + 1 + }); + } }); document.body.addEventListener("clientDisconnected", () => { - remountUI({ - occupantCount: Object.keys(NAF.connection.adapter.occupants).length + 1 - }); + if (NAF.connection.adapter) { + remountUI({ + occupantCount: Object.keys(NAF.connection.adapter.occupants).length + 1 + }); + } }); scene.components["networked-scene"].connect().catch(connectError => { @@ -332,7 +344,9 @@ const onReady = async () => { } if (mediaStream) { - NAF.connection.adapter.setLocalMediaStream(mediaStream); + if (NAF.connection.adapter && NAF.connection.adapter.setLocalMediaStream) { + NAF.connection.adapter.setLocalMediaStream(mediaStream); + } if (screenEntity) { screenEntity.setAttribute("visible", sharingScreen); From 5abf8b747a7ad847b2ca441cf4327cead86e6ab4 Mon Sep 17 00:00:00 2001 From: Christopher Van Wiemeersch Date: Mon, 21 May 2018 17:24:03 -0500 Subject: [PATCH 3/7] remove unneeded checks for `NAF.connection` --- src/components/block-button.js | 14 ++++++-------- src/components/freeze-controller.js | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/components/block-button.js b/src/components/block-button.js index 3a8decfe3c..714a7b765c 100644 --- a/src/components/block-button.js +++ b/src/components/block-button.js @@ -17,20 +17,18 @@ AFRAME.registerComponent("block-button", { }, block(clientId) { - if (NAF.connection && NAF.connection.adapter) { + if (NAF.connection.adapter) { NAF.connection.adapter.block(clientId); } }, // Currently unused unblock(clientId) { - if (NAF.connection) { - if (NAF.connection.adapter) { - NAF.connection.adapter.unblock(clientId); - } - if (NAF.connection.entities) { - NAF.connection.entities.completeSync(clientId); - } + if (NAF.connection.adapter) { + NAF.connection.adapter.unblock(clientId); + } + if (NAF.connection.entities) { + NAF.connection.entities.completeSync(clientId); } } }); diff --git a/src/components/freeze-controller.js b/src/components/freeze-controller.js index 58b5dcdeb0..7633fb1a5e 100644 --- a/src/components/freeze-controller.js +++ b/src/components/freeze-controller.js @@ -17,7 +17,7 @@ AFRAME.registerComponent("freeze-controller", { onToggle: function() { window.APP.store.update({ activity: { hasFoundFreeze: true } }); - if (NAF.connection && NAF.connection.adapter) { + if (NAF.connection.adapter) { NAF.connection.adapter.toggleFreeze(); if (NAF.connection.adapter.frozen) { this.el.addState("frozen"); From ce61f26c8dafbaac968da6af30c678a9efabf1a5 Mon Sep 17 00:00:00 2001 From: Christopher Van Wiemeersch Date: Mon, 21 May 2018 17:25:05 -0500 Subject: [PATCH 4/7] remove `NAF.connection.*` checks in `block-button` component --- src/components/block-button.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/components/block-button.js b/src/components/block-button.js index 714a7b765c..9dc23988c3 100644 --- a/src/components/block-button.js +++ b/src/components/block-button.js @@ -17,18 +17,12 @@ AFRAME.registerComponent("block-button", { }, block(clientId) { - if (NAF.connection.adapter) { - NAF.connection.adapter.block(clientId); - } + NAF.connection.adapter.block(clientId); }, // Currently unused unblock(clientId) { - if (NAF.connection.adapter) { - NAF.connection.adapter.unblock(clientId); - } - if (NAF.connection.entities) { - NAF.connection.entities.completeSync(clientId); - } + NAF.connection.adapter.unblock(clientId); + NAF.connection.entities.completeSync(clientId); } }); From 0eb4be4b62226ff1f0711d33370de59b0c652fad Mon Sep 17 00:00:00 2001 From: Christopher Van Wiemeersch Date: Mon, 21 May 2018 17:44:15 -0500 Subject: [PATCH 5/7] address review feedback (thanks, @brianpeiris!) --- src/components/networked-video-player.js | 4 ---- src/hub.js | 8 ++------ 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/components/networked-video-player.js b/src/components/networked-video-player.js index aa6b08e0f5..189a43e393 100644 --- a/src/components/networked-video-player.js +++ b/src/components/networked-video-player.js @@ -37,10 +37,6 @@ AFRAME.registerComponent("networked-video-player", { document.body.appendChild(container); } - if (!NAF.connection.adapter || !NAF.connection.adapter.getMediaStream) { - return; - } - const stream = await NAF.connection.adapter.getMediaStream(ownerId, "video"); if (!stream) { return; diff --git a/src/hub.js b/src/hub.js index f80fd12079..ccad290cb6 100644 --- a/src/hub.js +++ b/src/hub.js @@ -280,15 +280,11 @@ const onReady = async () => { }); document.body.addEventListener("blocked", ev => { - if (NAF.connection.entities) { - NAF.connection.entities.removeEntitiesOfClient(ev.detail.clientId); - } + NAF.connection.entities.removeEntitiesOfClient(ev.detail.clientId); }); document.body.addEventListener("unblocked", ev => { - if (NAF.connection.entities) { - NAF.connection.entities.completeSync(ev.detail.clientId); - } + NAF.connection.entities.completeSync(ev.detail.clientId); }); if (!qsTruthy("offline")) { From 7f155e9887cfb4e8374931947e5aa60360216f26 Mon Sep 17 00:00:00 2001 From: Brian Peiris Date: Thu, 27 Dec 2018 15:05:49 -0800 Subject: [PATCH 6/7] Simplify adapter check. Don't indicate success if muting fails --- src/components/freeze-controller.js | 17 ++++++++--------- src/components/mute-mic.js | 18 ++++++------------ 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/components/freeze-controller.js b/src/components/freeze-controller.js index fecb4da11e..769bbf2289 100644 --- a/src/components/freeze-controller.js +++ b/src/components/freeze-controller.js @@ -36,15 +36,14 @@ AFRAME.registerComponent("freeze-controller", { onToggle: function() { window.APP.store.update({ activity: { hasFoundFreeze: true } }); - if (NAF.connection.adapter) { - NAF.connection.adapter.toggleFreeze(); - if (NAF.connection.adapter.frozen) { - this.el.emit("play_freeze_sound"); - this.el.addState("frozen"); - } else { - this.el.emit("play_thaw_sound"); - this.el.removeState("frozen"); - } + if (!NAF.connection.adapter) return; + NAF.connection.adapter.toggleFreeze(); + if (NAF.connection.adapter.frozen) { + this.el.emit("play_freeze_sound"); + this.el.addState("frozen"); + } else { + this.el.emit("play_thaw_sound"); + this.el.removeState("frozen"); } } }); diff --git a/src/components/mute-mic.js b/src/components/mute-mic.js index 0136e73e3e..e6ab16830f 100644 --- a/src/components/mute-mic.js +++ b/src/components/mute-mic.js @@ -50,33 +50,27 @@ AFRAME.registerComponent("mute-mic", { }, onToggle: function() { + if (!NAF.connection.adapter) return; if (this.el.is("muted")) { - if (NAF.connection.adapter) { - NAF.connection.adapter.enableMicrophone(true); - } + NAF.connection.adapter.enableMicrophone(true); this.el.removeState("muted"); } else { - if (NAF.connection.adapter) { - NAF.connection.adapter.enableMicrophone(false); - } + NAF.connection.adapter.enableMicrophone(false); this.el.addState("muted"); } }, onMute: function() { + if (!NAF.connection.adapter) return; if (!this.el.is("muted")) { - if (NAF.connection.adapter) { - NAF.connection.adapter.enableMicrophone(false); - } + NAF.connection.adapter.enableMicrophone(false); this.el.addState("muted"); } }, onUnmute: function() { if (this.el.is("muted")) { - if (NAF.connection.adapter) { - NAF.connection.adapter.enableMicrophone(true); - } + NAF.connection.adapter.enableMicrophone(true); this.el.removeState("muted"); } } From edfd08074370756125ec2e7dfd146929751da806 Mon Sep 17 00:00:00 2001 From: Brian Peiris Date: Thu, 27 Dec 2018 15:06:07 -0800 Subject: [PATCH 7/7] Fix fileId error on ducks --- src/scene-entry-manager.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/scene-entry-manager.js b/src/scene-entry-manager.js index 5153dda53e..d5462ee0ac 100644 --- a/src/scene-entry-manager.js +++ b/src/scene-entry-manager.js @@ -257,7 +257,8 @@ export default class SceneEntryManager { const networkId = components.networked.data.networkId; el.setAttribute("networked", { persistent: false }); - const { fileId } = el.components["media-loader"].data; + const mediaLoader = components["media-loader"]; + const fileId = mediaLoader.data && mediaLoader.data.fileId; this.hubChannel.unpin(networkId, fileId); });