Promote BIM share on Launcher login event
This commit is contained in:
parent
168b535953
commit
ce34ecdd4d
|
|
@ -188,7 +188,8 @@ const SHARE_AUTH_GUEST_PARAM = "ndc_bim_guest";
|
||||||
const SHARE_PROMOTION_TIMEOUT_MS = 4500;
|
const SHARE_PROMOTION_TIMEOUT_MS = 4500;
|
||||||
const SHARE_PROMOTION_RETRY_MS = 15000;
|
const SHARE_PROMOTION_RETRY_MS = 15000;
|
||||||
const SESSION_STATUS_WATCH_INTERVAL_MS = 2500;
|
const SESSION_STATUS_WATCH_INTERVAL_MS = 2500;
|
||||||
const NODEDC_SESSION_EVENT_TYPE = "nodedc:session:logout";
|
const NODEDC_SESSION_LOGOUT_EVENT_TYPE = "nodedc:session:logout";
|
||||||
|
const NODEDC_SESSION_LOGIN_EVENT_TYPE = "nodedc:session:login";
|
||||||
|
|
||||||
const acceptByType = {
|
const acceptByType = {
|
||||||
xkt: ".xkt",
|
xkt: ".xkt",
|
||||||
|
|
@ -632,6 +633,13 @@ const getShareTopLevelPromotionUrl = () => {
|
||||||
return typeof promoteUrl === "string" && promoteUrl.trim() ? promoteUrl : "";
|
return typeof promoteUrl === "string" && promoteUrl.trim() ? promoteUrl : "";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const buildLauncherOptionalServiceUrl = (nextPath = getCurrentReturnPath(), fallbackPath = nextPath) => {
|
||||||
|
const launchUrl = new URL("/api/services/bim-viewer/optional-launch", getLauncherUrl());
|
||||||
|
launchUrl.searchParams.set("returnTo", nextPath);
|
||||||
|
launchUrl.searchParams.set("fallbackTo", fallbackPath);
|
||||||
|
return launchUrl.toString();
|
||||||
|
};
|
||||||
|
|
||||||
const hasShareGuestAuthMarker = () => {
|
const hasShareGuestAuthMarker = () => {
|
||||||
try {
|
try {
|
||||||
return new URLSearchParams(window.location.search || "").get(SHARE_AUTH_GUEST_PARAM) === "1";
|
return new URLSearchParams(window.location.search || "").get(SHARE_AUTH_GUEST_PARAM) === "1";
|
||||||
|
|
@ -660,12 +668,20 @@ const clearShareStartupPending = () => {
|
||||||
const isNodeDCSessionLogoutEvent = (value) => (
|
const isNodeDCSessionLogoutEvent = (value) => (
|
||||||
value &&
|
value &&
|
||||||
typeof value === "object" &&
|
typeof value === "object" &&
|
||||||
value.type === NODEDC_SESSION_EVENT_TYPE &&
|
value.type === NODEDC_SESSION_LOGOUT_EVENT_TYPE &&
|
||||||
|
typeof value.id === "string"
|
||||||
|
);
|
||||||
|
|
||||||
|
const isNodeDCSessionLoginEvent = (value) => (
|
||||||
|
value &&
|
||||||
|
typeof value === "object" &&
|
||||||
|
value.type === NODEDC_SESSION_LOGIN_EVENT_TYPE &&
|
||||||
typeof value.id === "string"
|
typeof value.id === "string"
|
||||||
);
|
);
|
||||||
|
|
||||||
let nodeDCSessionSyncCleanup = null;
|
let nodeDCSessionSyncCleanup = null;
|
||||||
let nodeDCLogoutHandling = false;
|
let nodeDCLogoutHandling = false;
|
||||||
|
let nodeDCLoginHandling = false;
|
||||||
let nodeDCSessionWatchTimer = null;
|
let nodeDCSessionWatchTimer = null;
|
||||||
let nodeDCSessionWatchInFlight = false;
|
let nodeDCSessionWatchInFlight = false;
|
||||||
|
|
||||||
|
|
@ -717,6 +733,24 @@ const handleNodeDCSessionLogout = async () => {
|
||||||
window.location.replace(loginUrl.toString());
|
window.location.replace(loginUrl.toString());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleNodeDCSessionLogin = () => {
|
||||||
|
if (nodeDCLoginHandling || runtimeSessionInfo.authenticated === true) return;
|
||||||
|
nodeDCLoginHandling = true;
|
||||||
|
|
||||||
|
const shareToken = getShareTokenFromPath();
|
||||||
|
if (shareToken) {
|
||||||
|
const promotionUrl = getShareTopLevelPromotionUrl() ||
|
||||||
|
buildLauncherOptionalServiceUrl(
|
||||||
|
`/share/${encodeURIComponent(shareToken)}`,
|
||||||
|
`/share/${encodeURIComponent(shareToken)}?${SHARE_AUTH_GUEST_PARAM}=1`
|
||||||
|
);
|
||||||
|
window.location.assign(promotionUrl);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.location.assign(buildLauncherOptionalServiceUrl());
|
||||||
|
};
|
||||||
|
|
||||||
const setupNodeDCSessionSync = () => {
|
const setupNodeDCSessionSync = () => {
|
||||||
if (nodeDCSessionSyncCleanup || typeof document === "undefined") return;
|
if (nodeDCSessionSyncCleanup || typeof document === "undefined") return;
|
||||||
|
|
||||||
|
|
@ -736,8 +770,14 @@ const setupNodeDCSessionSync = () => {
|
||||||
document.body.appendChild(iframe);
|
document.body.appendChild(iframe);
|
||||||
|
|
||||||
const handleMessage = (event) => {
|
const handleMessage = (event) => {
|
||||||
if (event.origin !== launcherOrigin || !isNodeDCSessionLogoutEvent(event.data)) return;
|
if (event.origin !== launcherOrigin) return;
|
||||||
|
if (isNodeDCSessionLogoutEvent(event.data)) {
|
||||||
void handleNodeDCSessionLogout();
|
void handleNodeDCSessionLogout();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isNodeDCSessionLoginEvent(event.data)) {
|
||||||
|
handleNodeDCSessionLogin();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener("message", handleMessage);
|
window.addEventListener("message", handleMessage);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue