Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
blocks:app-note:interacting-from-a-custom-web-page [2019-12-03 10:28] max [Running the Example] |
blocks:app-note:interacting-from-a-custom-web-page [2023-08-01 21:07] (current) admin [Installation] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
- | This application note shows how your custom web page can talk to a Blocks server in various ways, including: | + | The application note titled " |
- | * Making | + | * Making HTTP requests |
* Setting any property in your Blocks system from the web page. | * Setting any property in your Blocks system from the web page. | ||
* Subscribing to property changes to keep your web page in the loop, regardless of how the property was changed. | * Subscribing to property changes to keep your web page in the loop, regardless of how the property was changed. | ||
Line 13: | Line 13: | ||
===== Installation ===== | ===== Installation ===== | ||
- | Follow these steps to install | + | You need a computer with a running blocks server and a web browser |
- | - Install the enclosed {{: | ||
- Start Blocks. | - Start Blocks. | ||
- | - Open the editor using the Admin button. | + | - Open the Blocks |
+ | - Log in using the proper credentials (default user name is //admin// and the password is //pixi//). | ||
- Open a second browser window to the same address as the editor window, but replace /edit/xxx with /spot. This opens a test spot display. | - Open a second browser window to the same address as the editor window, but replace /edit/xxx with /spot. This opens a test spot display. | ||
- Double-click TheSpot in the editor and reassign it to the ID shown in your separate spot window. This will be your test spot, controlled from the custom app. | - Double-click TheSpot in the editor and reassign it to the ID shown in your separate spot window. This will be your test spot, controlled from the custom app. | ||
Line 86: | Line 86: | ||
</ | </ | ||
- | This call returns a pubSubPeer that manages the websocket connection to the server. The constructor call takes an optional callback function, in the example above called // | + | This call returns a pubSubPeer that manages the websocket connection to the server. |
+ | |||
+ | The example shown above assumes that the custom web page is served by the Blocks server. If it is served from some other server, you must add a //second// parameter that is the URL for accessing the websocket endpoint on your Blocks server, like this; | ||
+ | |||
+ | < | ||
+ | const pubSubPeer = new PIXILAB_BLOCKS.PubSubPeer( | ||
+ | onServerConnectionChange, | ||
+ | " | ||
+ | ); | ||
+ | </ | ||
+ | |||
+ | Replace < | ||
+ | |||
+ | < | ||
+ | const pubSubPeer = new PIXILAB_BLOCKS.PubSubPeer( | ||
+ | onServerConnectionChange, | ||
+ | " | ||
+ | ); | ||
+ | </ | ||
+ | |||
+ | The first parameter of the PubSubPeer | ||
< | < | ||
Line 112: | Line 132: | ||
=== pubSubPeer.add === | === pubSubPeer.add === | ||
- | This is similar to the //set// function, and takes the same two parameters. | + | This is similar to the //set// function, and takes the same two parameters. |
+ | |||
+ | The //add// methid | ||
Line 120: | Line 142: | ||
- The full path to the property to subscribe to (see above). | - The full path to the property to subscribe to (see above). | ||
- | - A callback | + | - An object containing a single |
- | The // | + | The // |
:!: You should pay attention to any initial value returned by the // | :!: You should pay attention to any initial value returned by the // | ||
Line 129: | Line 151: | ||
=== pubSubPeer.unsubscribe === | === pubSubPeer.unsubscribe === | ||
- | This function allows you to terminate any value subscription initiated by the // | + | This function allows you to terminate any value subscription initiated by the // |
- The full path to the property to subscribe to (see above). | - The full path to the property to subscribe to (see above). | ||
- | - The same callback function | + | - The very same object |
- | The main.js example | + | The main.js example |
Line 214: | Line 236: | ||
Once these three steps are done, the promise is resolved with the name of the generated image file, now available under /public on the Blocks server. If any error occurs, the promise is instead rejected, passing an error code back as the HTTP POST request' | Once these three steps are done, the promise is resolved with the name of the generated image file, now available under /public on the Blocks server. If any error occurs, the promise is instead rejected, passing an error code back as the HTTP POST request' | ||
+ |