Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#3149 fix waypoint link reloads room #4272

Merged
merged 2 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/components/open-media-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ AFRAME.registerComponent("open-media-button", {
if (visible) {
let label = "open link";
if (!this.data.onlyOpenLink) {
let hubId;
if (await isLocalHubsAvatarUrl(src)) {
label = "use avatar";
} else if ((await isLocalHubsSceneUrl(src)) && mayChangeScene) {
label = "use scene";
} else if (await isHubsRoomUrl(src)) {
const url = new URL(this.src);
if (url.hash && window.location.pathname === url.pathname) {
} else if ((hubId = await isHubsRoomUrl(src))) {
const url = new URL(src);
if (url.hash && APP.hub.hub_id === hubId) {
label = "go to";
} else {
label = "visit room";
Expand All @@ -43,6 +44,7 @@ AFRAME.registerComponent("open-media-button", {

const exitImmersive = async () => await handleExitTo2DInterstitial(false, () => {}, true);

let hubId;
if (this.data.onlyOpenLink) {
await exitImmersive();
window.open(this.src);
Expand All @@ -52,9 +54,15 @@ AFRAME.registerComponent("open-media-button", {
this.el.sceneEl.emit("avatar_updated");
} else if ((await isLocalHubsSceneUrl(this.src)) && mayChangeScene) {
this.el.sceneEl.emit("scene_media_selected", this.src);
} else if (await isHubsRoomUrl(this.src)) {
await exitImmersive();
location.href = this.src;
} else if ((hubId = await isHubsRoomUrl(this.src))) {
const url = new URL(this.src);
if (url.hash && APP.hub.hub_id === hubId) {
// move to waypoint w/o writing to history
window.history.replaceState(null, null, window.location.href.split("#")[0] + url.hash);
} else {
await exitImmersive();
location.href = this.src;
}
} else {
await exitImmersive();
window.open(this.src);
Expand Down
2 changes: 1 addition & 1 deletion src/systems/waypoint-system.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export class WaypointSystem {
const waypoint = this.ready.find(c => c.el.object3D.name === waypointName);
if (waypoint) {
this.moveToWaypoint(waypoint, this.previousWaypointHash === null);
window.location.hash = ""; // 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;
}
Expand Down
11 changes: 7 additions & 4 deletions src/utils/media-url-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ async function isHubsServer(url) {
return isHubsServer;
}

const hubsSceneRegex = /https?:\/\/[^/]+\/scenes\/(\w+)\/?\S*/;
const hubsAvatarRegex = /https?:\/\/[^/]+\/avatars\/(?<id>\w+)\/?\S*/;
const hubsRoomRegex = /(https?:\/\/)?[^/]+\/([a-zA-Z0-9]{7})\/?\S*/;
const hubsSceneRegex = /https?:\/\/[^/]+\/scenes\/[a-zA-Z0-9]{7}(?:\/|$)/;
const hubsAvatarRegex = /https?:\/\/[^/]+\/avatars\/(?<id>[a-zA-Z0-9]{7})(?:\/|$)/;
const hubsRoomRegex = /(https?:\/\/)?[^/]+\/(?<id>[a-zA-Z0-9]{7})(?:\/|$)/;

export const isLocalHubsUrl = async url =>
(await isHubsServer(url)) && new URL(url).origin === document.location.origin;
Expand All @@ -194,7 +194,10 @@ export const isHubsAvatarUrl = async url => (await isHubsServer(url)) && hubsAva
export const isLocalHubsAvatarUrl = async url => (await isHubsAvatarUrl(url)) && (await isLocalHubsUrl(url));

export const isHubsRoomUrl = async url =>
(await isHubsServer(url)) && !(await isHubsAvatarUrl(url)) && !(await isHubsSceneUrl(url)) && hubsRoomRegex.test(url);
(await isHubsServer(url)) &&
!(await isHubsAvatarUrl(url)) &&
!(await isHubsSceneUrl(url)) &&
url.match(hubsRoomRegex)?.groups.id;

export const isHubsDestinationUrl = async url =>
(await isHubsServer(url)) && ((await isHubsSceneUrl(url)) || (await isHubsRoomUrl(url)));
Expand Down