One other thing to be careful about is to pass a list or row, even if empty, each time so that Node.js will have an object to work on!īWait is used to determine if you wish to suspend code execution until the Node.js method completes, therefore if you set it to wait by sending kTrue, a completion callback will occur before $callmethod returns true or false for its completion. This means that you should be careful to map the data correctly to JSON and avoid trying to pass that to $callmethod in vListOrRow. The vListOrRow parameter will be converted to JSON and then passed to the JavaScript method as its parameter. The cModule and cMethod parameters identify a module and a method within the specified module which will be called. Optionally, we can also wait for the method to complete. $callmethod(cModule, cMethod, vListOrRow ) This method will call the method passed as a parameter and it can also pass a parameter to the JS method in the JavaScript object representation of vListOrRow. When called, any in-progress method calls may not complete. $cancel() This method can be used to terminate the node.js process. You can make multiple method calls to the same process, so there is no need to call the $start method that frequently results in minimal overhead of starting the node.js process. Upon calling this method, the background thread will start a node.js process which will go through the JavaScript method calls. $start() This method will run the JS worker in the background thread, return true if the worker was successfully started. You must call the $init method before any other methods. $init() This method can be used to initialise the object so it is ready to execute JS method calls, it will return true if successful. The JavaScript Worker has a bunch of useful methods that we can call: Or alternatively, we can subclass the external object with an Omnis object class: The first step to use the JavaScript worker is to create it using an object variable with the sub-type of OW3 Worker Objects\JAVASCRIPTWorker: While the third example is for those who have some coding experience (not necessarily years) and feel confident to dive straight into the action and install an npm module, write some JavaScript to connect Omnis to the npm module and call the module from within Omnis and return some data back. The second example will show you how to install an npm module and make a request to that module from within Studio (some files are already pre-written in the installation in order to facilitate this). We will have three examples in this TechNote, the first example is going to get you familiar with what we are working with and will give you insight into what happens in the background. You can call a Node.js module and its method from within Omnis, you can also pass parameters to it and return results back to Omnis. It has methods and functions which will run in the Node.js environment. Now the real question comes: what is a node.js module? You can think of a Node.js module as an Omnis object class. What it allows us to do is install modules for Node.js very easily with a simple command in our terminal: npm install *name of package*. Many people that have used Linux before can compare it to the usual 'apt-get' command, or for the macOS user, it is similar to Homebrew's 'brew' command. Node.js makes use of 'npm' which stands for node package manager. What this means is that you can run JavaScript code in this environment that is running in the background alongside your Omnis application (yes you can turn it off if you wish to) and take full advantage of all the packages created for Node.js (there are many, and they are very useful!). Node.js is an open-source server environment based on Google Chrome's V8 JavaScript engine which is also cross-platform, allowing you to run it virtually anywhere, similar to your Omnis application. With this new worker, you can run node.js "modules" very easily and it enables you, the developer, to extend your Omnis Studio application to a point that was not easily reachable before! What is Node.js? In order to take full advantage of node.js' capabilities, we have created a new OW3 Worker Object: the JavaScript worker. With version 10 of Omnis Studio, we now have introduced node.js in the backend to support our remote debugger. In this Tech Note we will be exploring the JavaScript Worker introduced in Omnis Studio 10. Omnis Technical Note TNEX0006 Updated July 2023 Using the JavaScript Worker Object and Node.JS
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |