LocalPage.html 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <!--
  2. This is a custom local page hosted by the Atomic Game Engine. Communication with the
  3. host can be done in 3 ways
  4. - notify the host of an event via atomicHostEvent
  5. - request data from the host (synchronously) via atomicHostRequest
  6. - request the host to call back to a function whenever it is ready to (asynchronous)
  7. -->
  8. <html>
  9. <head>
  10. Embedded Web Page in Atomic
  11. </head>
  12. <h1>
  13. Embedded Web Page in Atomic.
  14. </h1>
  15. <p>
  16. Click some links to demonstrate communication between the web view and the running game logic
  17. </p>
  18. <button onclick="sendToHost()">Send Message to Host Process</button>
  19. <button onclick="requestFromHost()">Request From Host</button>
  20. <button onclick="notifyCallbackFunction()">Host calls callback function</button>
  21. <script src="./atomicQuery.js"></script>
  22. <script>
  23. let clicks = 0;
  24. // Send a notification to the host
  25. function sendToHost() {
  26. clicks++;
  27. atomicHostEvent("CUSTOM_NOTIFICATION", {
  28. clickCount: clicks
  29. });
  30. }
  31. // request some information from the host
  32. function requestFromHost() {
  33. atomicHostRequest("GET_FROM_HOST", {
  34. prefix: "fus"
  35. }).then(function (response) {
  36. alert("Host Said: " + response.displayMessage);
  37. });
  38. }
  39. // Ask the host to call a function at some point in the future
  40. function notifyCallbackFunction() {
  41. atomicHostEvent("CALLBACK_FUNCTION", {
  42. callbackFunction: "HOST_callme"
  43. });
  44. }
  45. // The function the host should call
  46. function HOST_callme(message) {
  47. alert("Host called me with: " + message);
  48. }
  49. </script>
  50. </html>