diff --git a/src/components/action-trigger-volume.js b/src/components/action-trigger-volume.js index 04ba1e7d85..39002d6378 100644 --- a/src/components/action-trigger-volume.js +++ b/src/components/action-trigger-volume.js @@ -34,25 +34,31 @@ AFRAME.registerComponent("action-trigger-volume", { const collidingLastFrame = this.collidingLastFrame[object3D.id]; if (isColliding && !collidingLastFrame) { - if(this.data.isAvatarLink) { - if(AVN.isAuthenticated) { - this.el.sceneEl.systems["hubs-systems"].soundEffectsSystem.playSoundOneShot(SOUND_MEDIA_LOADED); - const avatarId = this.data.src || new URL(this.data.src).pathname.split("/").pop(); - console.log("AVN: Setting avatar to ", avatarId); - window.APP.store.update({ profile: { avatarId } }); - this.el.sceneEl.emit("avatar_updated"); - } else { - this.el.sceneEl.systems["hubs-systems"].soundEffectsSystem.playSoundOneShot(SOUND_FREEZE); - console.log(`AVN: Avatar change denied because user is not authenticated`); - } + // Is this a fragment? + if(this.data.src.charAt(0) === "#") { + // Just update the URL and the Waypoint system will process the instruction without changing the history + window.history.replaceState(null, null, window.location.href.split("#")[0] + this.data.src); } else { - if(AVN.allowNavigation) { - console.log("AVN: Navigating to scene link", this.data.src); - this.el.sceneEl.systems["hubs-systems"].soundEffectsSystem.playSoundOneShot(SOUND_HOVER_OR_GRAB); - changeHubAvn(this.data.src); + if(this.data.isAvatarLink) { + if(AVN.isAuthenticated) { + this.el.sceneEl.systems["hubs-systems"].soundEffectsSystem.playSoundOneShot(SOUND_MEDIA_LOADED); + const avatarId = this.data.src || new URL(this.data.src).pathname.split("/").pop(); + console.log("AVN: Setting avatar to ", avatarId); + window.APP.store.update({ profile: { avatarId } }); + this.el.sceneEl.emit("avatar_updated"); + } else { + this.el.sceneEl.systems["hubs-systems"].soundEffectsSystem.playSoundOneShot(SOUND_FREEZE); + console.log(`AVN: Avatar change denied because user is not authenticated`); + } } else { - this.el.sceneEl.systems["hubs-systems"].soundEffectsSystem.playSoundOneShot(SOUND_FREEZE); - console.log(`AVN: Navigation denied because room is not explorable`); + if(AVN.allowNavigation) { + console.log("AVN: Navigating to scene link", this.data.src); + this.el.sceneEl.systems["hubs-systems"].soundEffectsSystem.playSoundOneShot(SOUND_HOVER_OR_GRAB); + changeHubAvn(this.data.src); + } else { + this.el.sceneEl.systems["hubs-systems"].soundEffectsSystem.playSoundOneShot(SOUND_FREEZE); + console.log(`AVN: Navigation denied because room is not explorable`); + } } } } else if (!isColliding && collidingLastFrame) { diff --git a/src/components/media-loader.js b/src/components/media-loader.js index 99485d3c7d..24a9bcf900 100644 --- a/src/components/media-loader.js +++ b/src/components/media-loader.js @@ -361,8 +361,9 @@ AFRAME.registerComponent("media-loader", { this.el.removeAttribute("media-image"); } try { + const isFragment = src.charAt(0) === "#" // Short circuit for external web links (don't bother with fetching content types and thumbnails) - if(this.data.contentType === "text/html" && !AVN.isAvnUrl(src)) { + if(this.data.contentType === "text/html" && !isFragment && !AVN.isAvnUrl(src)) { console.log(`Showing simple link for URL '${src}'`) // Change image to be a 1x1 transparent PNG (image mesh provides the hover target) this.el.setAttribute("media-image", { @@ -383,37 +384,39 @@ AFRAME.registerComponent("media-loader", { } //check if url is an anchor hash e.g. #Spawn_Point_1 - if (src.charAt(0) === "#") { - src = this.data.src = `${window.location.origin}${window.location.pathname}${window.location.search}${src}`; + if (isFragment) { + //src = this.data.src = `${window.location.origin}${window.location.pathname}${window.location.search}${src}`; } let canonicalAudioUrl = null; // set non-null only if audio track is separated from video track (eg. 360 video) let contentType = this.data.contentType; + let isAvatar = false; // AVN: Link elements should remain as is for proper inflation const isLinkElement = contentType === "text/html" - const parsedUrl = new URL(src); - let isAvatar = false; - if(ConnectClient.AvnfsUtils.isValidUrl(parsedUrl)) { - const { mediaType } = ConnectClient.AvnfsUtils.decodeUrl(parsedUrl) - if(!isLinkElement) { - contentType = mediaType; - } - //TODO: BETTER TEST FOR AVATARS - isAvatar = mediaType.includes("avatar"); - } else { - if(parsedUrl.hostname == "scene.link") { - // Indirect media resolution - const result = await global.AVNGlobal.fetchMediaData(src); - src = result.origin; + const parsedUrl = isFragment ? undefined : new URL(src); + if(parsedUrl) { + if(ConnectClient.AvnfsUtils.isValidUrl(parsedUrl)) { + const { mediaType } = ConnectClient.AvnfsUtils.decodeUrl(parsedUrl) if(!isLinkElement) { - contentType = (result.meta && result.meta.expected_content_type) || contentType; + contentType = mediaType; } - const tags = result.meta && result.meta.tags; - isAvatar = tags && tags.includes(AvnTags.Avatar); + //TODO: BETTER TEST FOR AVATARS + isAvatar = mediaType.includes("avatar"); } else { - console.warn(`Unexpected URL to resolve '${src}'`) - } - } + if(parsedUrl.hostname == "scene.link") { + // Indirect media resolution + const result = await global.AVNGlobal.fetchMediaData(src); + src = result.origin; + if(!isLinkElement) { + contentType = (result.meta && result.meta.expected_content_type) || contentType; + } + const tags = result.meta && result.meta.tags; + isAvatar = tags && tags.includes(AvnTags.Avatar); + } else { + console.warn(`Unexpected URL to resolve '${src}'`) + } + } + } // if the component creator didn't know the content type, we didn't get it from reticulum, and // we don't think we can infer it from the extension, we need to make a HEAD request to find it out diff --git a/src/systems/waypoint-system.js b/src/systems/waypoint-system.js index 63ac6e1a0b..70c87afd26 100644 --- a/src/systems/waypoint-system.js +++ b/src/systems/waypoint-system.js @@ -332,8 +332,7 @@ export class WaypointSystem { const waypoint = this.ready.find(c => c.el.object3D.name === waypointName); if (waypoint) { this.moveToWaypoint(waypoint, this.previousWaypointHash === null); - // AVN: Reload behaviour is more consistent if you don't remove the waypoint hash - //window.history.replaceState(null, null, window.location.href.split("#")[0]); // Reset so you can re-activate the same waypoint + window.history.replaceState(null, null, window.location.href.split("#")[0]); // Reset so you can re-activate the same waypoint } this.previousWaypointHash = window.location.hash; }