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

Is there a function to manually run snapshot function #74

Closed
johnyang90 opened this issue Jan 7, 2021 · 5 comments
Closed

Is there a function to manually run snapshot function #74

johnyang90 opened this issue Jan 7, 2021 · 5 comments

Comments

@johnyang90
Copy link

I am using the default snapshot function to create snapshot, I understand that the snapshot is to capture whatever on the screen. However, we added some custom buttons on the page level, so is there any way we can hide all the custom buttons before capture the snapshot?

@awe-media
Copy link
Owner

Hi @johnyang90, the snapshot action calls the application.snapshot.take() function.

You can override this with your own code so when it's called you do whatever you need first, then call the original function. You can do that like this.

var ast = application.snapshot.take; // create a reference to the original function
application.snapshot.take = function() { // override the original function with your own function
  // put your own code here to hide any HTML or in-scene objects you want e.g.
  // if (application.current_view.name == MY_FIRST_VIEW) { // make your hide code only apply to a specific scene if you want
  //   awe.projections.view(MY_FIRST_VIEW_PROJECTION_ID).update({ visible:false });
  // } else {
  // ...
  // }
  return ast(); // call the original function
};

If you want this to apply to all scenes then you can add it to the /settings/custom_code section.

If you want it to just apply to one specific scene then you can wrap it inside an view_loaded listener. And you should clean up after the view is unloaded too. Here's a more detailed example.

var ast = application.snapshot.take; // create a reference to the original function
function setup_custom_snapshot() {
  if (application.current_view.name == MY_FIRST_VIEW) { // limit the setup to just one specific scene
    application.snapshot.take = function() { // override the original function with your own function
      // put your own code here to hide any HTML or in-scene objects you want e.g.
      // awe.projections.view(MY_PROJECTION_ID).update({ visible:false });
      return ast(); // call the original function
    };
  }
}
function teardown_custom_snapshot() {
  application.snapshot.take = ast; // restore the original function
}

window.addEventListener('view_loaded', setup_custom_snapshot);
window.addEventListener('view_unloaded', teardown_custom_snapshot);

Note that only in-scene objects will be included in the snapshot image, so no HTML elements will be visible in the image.

@johnyang90
Copy link
Author

johnyang90 commented Jan 11, 2021

I tried to set some of the projections' visibility to false on snapshot button click, it doesn't hidden until i click second time, is there any function to run snapshot function once all the projections visible are updated successfully?

and what is the custom function to close snapshot preview, because I will need to show back the hidden buttons when snapshot preview is closed?

@awe-media
Copy link
Owner

Hi @johnyang90, there's no option to await the projection updates at the moment. So you are best to add a small delay using setTimeout() e.g.

var ast = application.snapshot.take; // create a reference to the original function
application.snapshot.take = function() { // override the original function with your own function
  ...
  setTimeout(() => {
    ast(); // call the original function
  }, 500); // add half a second delay to allow for scene update
};

We'd recommend testing this on a slow/low powered device so you can get the timing right to allow for them.

The function to close the snapshot preview is application.snapshot.hide_preview(true). You can use the same type of overriding approach with that.

@johnyang90
Copy link
Author

hi @awe-media , thanks for the suggestion, it is working now.
However, i tried to run custom javascript for the snapshot close button, it seems like doesn't work.

Screenshot 2021-01-11 at 2 40 23 PM

I checked the frontend coding, the onclick function is placed inlined with the button, hence i think the custom function is not running.

Screenshot 2021-01-11 at 2 41 33 PM

@johnyang90
Copy link
Author

sorry my bad, i made some mistake on the projection id, now it is working.
Thanks a lot yar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants