Search code examples
autodesk-forge

Is disconnected workflows available with viewer V7 api


I try to use the workflows from " https://aps.autodesk.com/blog/disconnected-workflows " . I use the .net core and sucess with viewer V6 , but when I try to use the V7 that console comes out of the error message " GET https://cdn.derivative.autodesk.com/derivativeservice/v2/manifest/dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6dGVzdF8wMTA2L3JhY2Jhc2ljc2FtcGxlcHJvamVjdC5ydnQ?domain=http%3A%2F%2Flocalhost%3A3060 net::ERR_INTERNET_DISCONNECTED "

This message occurred when I try to use service-worker offline the website and load the model I have cashed. How can I fix it or other way to get the same result? I am not sure that the problem is in the part I try to load the document or not.

I use this code

export function loadModel_cache(urn) {
  let viewerError = document.getElementById("viewer-error");
  if (viewerError) {
    viewerError.parentNode.removeChild(viewerError);
  }

  function onDocumentLoadFailure() {
    viewerError = document.createElement("div");
    viewerError.id = "viewer-error";
    viewerError.innerHTML =
      "<span>Could not load document. Are you offline?</span>";
    document.getElementById("preview").appendChild(viewerError);
    updateOverlay();
    console.error("Could not load document " + urn);
  }
  function onItemLoadSuccess(viewer) {}
  function onItemLoadFailure() {
    updateOverlay();
    console.error("Could not load model from document " + urn);
  }
  currentUrn = null;
  const status = document.querySelector(
    `#overlay > ul > li[data-urn="${urn}"] > .model-status`
  );
  status.style.setProperty("display", "inline");
  status.innerHTML = "(loading...)";
  Autodesk.Viewing.Document.load(
    "urn:" + urn,
    (doc) => {
      const viewables = doc.getRoot().search({ type: "geometry" });
      console.log(viewables);
      console.log(doc);
      currentApp.loadDocumentNode(doc, viewables[0]).then(() => {
        onItemLoadSuccess();
        currentUrn = urn;
        updateOverlay();
      }); // Assuming there's always at least one viewable
    },

    onDocumentLoadFailure
  );

replace this one that use in the source code

function loadModel(urn) {
  let viewerError = document.getElementById("viewer-error");
  if (viewerError) {
    viewerError.parentNode.removeChild(viewerError);
  }

  function onDocumentLoadSuccess() {
    const viewables = currentApp.bubble.search({ type: "geometry" });
    console.log(viewables);
    currentApp.selectItem(
      viewables[0].data,
      onItemLoadSuccess,
      onItemLoadFailure
    ); // Assuming there's always at least one viewable
  }
  function onDocumentLoadFailure() {
    viewerError = document.createElement("div");
    viewerError.id = "viewer-error";
    viewerError.innerHTML =
      "<span>Could not load document. Are you offline?</span>";
    document.getElementById("viewer").appendChild(viewerError);
    updateOverlay();
    console.error("Could not load document " + urn);
  }
  function onItemLoadSuccess(viewer) {
    viewer.addEventListener(
      Autodesk.Viewing.GEOMETRY_LOADED_EVENT,
      function () {
        currentUrn = urn;
        updateOverlay();
      }
    );
  }
  function onItemLoadFailure() {
    updateOverlay();
    console.error("Could not load model from document " + urn);
  }
  currentUrn = null;
  const status = document.querySelector(
    `#overlay > ul > li[data-urn="${urn}"] > .model-status`
  );
  status.style.setProperty("display", "inline");
  status.innerHTML = "(loading...)";
  console.log(currentApp); //---------------------------------
  currentApp.loadDocument(
    "urn:" + urn,
    onDocumentLoadSuccess,
    onDocumentLoadFailure
  );
}

Solution

  • Newer versions of the viewer may be talking to different backend services so if you wanted to enable the "disconnected workflows" there, it should be possible, you would just need to update the types of URLs the service workers should cache.

    Currently the service worker code here assumes that all the derivatives are coming from https://developer.api.autodesk.com/derivativeservice/v2, and as you found out already, newer versions of the viewer are actually pulling the data from https://cdn.derivative.autodesk.com/derivativeservice/v2.

    Also, be careful about the SVF vs SVF2 format difference. You will only be able to cache SVF data, not SVF2.