Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| blocks:app-note:interacting-from-a-custom-web-page [2020-04-02 09:11] – [Installation] mattias | blocks:app-note:interacting-from-a-custom-web-page [2023-08-01 21:07] (current) – [Installation] admin | ||
|---|---|---|---|
| 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 ===== | ||
| - | You need a computer with a running blocks server and a web browser to use this application note. | + | You need a computer with a running blocks server and a web browser to run this application note. Here' |
| - | + | ||
| - | We have prepared a PIXILAB-blocks-root folder containing everything you need to run the examples. | + | |
| - | {{ : | + | |
| - | If you don't know how to do this, read the instructions in the [[https:// | + | |
| - | + | ||
| - | If you have done the general setup, copied the files and pointed to this application notes root block, follow | + | |
| - Start Blocks. | - Start Blocks. | ||
| - | - Open the editor using the Admin button. | + | - Open the Blocks |
| - | - Log in using the name admin and the password pixi. | + | - Log in using the proper credentials (default user name is //admin// and the password |
| - 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 92: | 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 118: | 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 126: | 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 135: | 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 221: | Line 237: | ||
| 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' | ||
| - | [[blocks: | ||