New scripting engine in Switch 2020
-
- TOP CONTRIBUTOR
- Posts: 658
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
New scripting engine in Switch 2020
I gave a presentation on the new node.js scripting engine that will be released with Switch 2020.
https://www.enfocus.com/en/virtual-safa ... ing-engine
We are looking for a few pilot projects using node.js and Switch. Please contact me if you have an idea or an actual project you'd like to discuss.
Dwight Kelly
dkelly@apago.com
https://www.enfocus.com/en/virtual-safa ... ing-engine
We are looking for a few pilot projects using node.js and Switch. Please contact me if you have an idea or an actual project you'd like to discuss.
Dwight Kelly
dkelly@apago.com
Re: New scripting engine in Switch 2020
I watched the webinar, quite impressive! And the fact that nodejs is now supported gives so much more possibilities for scripting and app development.
Re: New scripting engine in Switch 2020
Great presentation. I'm also looking forward to using this. Your description of the await operator actually cleared up a lot of confusion for me.
Re: New scripting engine in Switch 2020
Dwight or Enfocus support,
I have the Prerelease and am trying to do just a basic log job name, you used as an example in your presentation. I have Node.js installed on the Mac and it also seems to be working.
I am getting a "Unexpected token ',' " error when I try to run a file through.
Are there any setup guides for Node.js with SWITCH?
I have the Prerelease and am trying to do just a basic log job name, you used as an example in your presentation. I have Node.js installed on the Mac and it also seems to be working.
I am getting a "Unexpected token ',' " error when I try to run a file through.
Are there any setup guides for Node.js with SWITCH?
-
- TOP CONTRIBUTOR
- Posts: 658
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Re: New scripting engine in Switch 2020
Can you post your Javascript code?
Re: New scripting engine in Switch 2020
Hey,
I have watched your presentation and downloaded the Spring Update. One thing isn't really clear to me.
When I activate Node.js in Scripter the "Fixture" Panel disappears. I can write and debug code better in VSCode but I can't test the code in scripter I always need a Switch Flow to test the script. Am I right?
I have watched your presentation and downloaded the Spring Update. One thing isn't really clear to me.
When I activate Node.js in Scripter the "Fixture" Panel disappears. I can write and debug code better in VSCode but I can't test the code in scripter I always need a Switch Flow to test the script. Am I right?
Benjamin
Re: New scripting engine in Switch 2020
Correct, you always need to test your Node script via a flow. You can, however, attach the script in the flow with the debugger in VSCode. These are the steps.
In VSCode: Run - Add configuration. This requests to select an environment from a dropdown list. Choose "Node.js". This will create a launch.json file in the .vscode subfolder of your project folder. At the bottom right of the editing pane there is a button "Add configuration" Click on it and you again be presented with a dropdown list from which you choose "Node.js Attach". This adds a part to the JSON where you will see that the value of "request" is "attach" and the value of "port" is 9229. Save the file.
In Switch Designer you set the "Debug" property of the script element to "Yes" and there you will see a value for a port. It is not a coincidence that this has the default value 9229. And you specify the entry point which most of the time will be "jobArrived".
Start the flow and drop a job into the flow. When it hits the folder in front of your Node script, the job will stall because it is waiting for the debugger to come up. That is when you go to VSCode and do Run - Start Debugging.
The debug session will not start right away, because VSCode has 2 configurations to choose from and you obviously tell it to use the "Attach" one. By the way, if this is the only configuration you will ever use for that script, you could also have removed the unwanted configuration from the launch.json file before saving it.
Once the debug session really starts the debugger will jump to some obfuscated wrapper code that is of no interest to you. Hit the play button to jump to the entry point. Add breakpoints as required and knock yourself out debugging your code.
Careful! VSCode will show you a copy of the original script because Switch places your script in its own data root somewhere before running it. Do not start editing and saving that code! Not that it has ever happened to me
In VSCode: Run - Add configuration. This requests to select an environment from a dropdown list. Choose "Node.js". This will create a launch.json file in the .vscode subfolder of your project folder. At the bottom right of the editing pane there is a button "Add configuration" Click on it and you again be presented with a dropdown list from which you choose "Node.js Attach". This adds a part to the JSON where you will see that the value of "request" is "attach" and the value of "port" is 9229. Save the file.
In Switch Designer you set the "Debug" property of the script element to "Yes" and there you will see a value for a port. It is not a coincidence that this has the default value 9229. And you specify the entry point which most of the time will be "jobArrived".
Start the flow and drop a job into the flow. When it hits the folder in front of your Node script, the job will stall because it is waiting for the debugger to come up. That is when you go to VSCode and do Run - Start Debugging.
The debug session will not start right away, because VSCode has 2 configurations to choose from and you obviously tell it to use the "Attach" one. By the way, if this is the only configuration you will ever use for that script, you could also have removed the unwanted configuration from the launch.json file before saving it.
Once the debug session really starts the debugger will jump to some obfuscated wrapper code that is of no interest to you. Hit the play button to jump to the entry point. Add breakpoints as required and knock yourself out debugging your code.
Careful! VSCode will show you a copy of the original script because Switch places your script in its own data root somewhere before running it. Do not start editing and saving that code! Not that it has ever happened to me
-
- Member
- Posts: 21
- Joined: Wed Jul 20, 2016 12:03 pm
Re: New scripting engine in Switch 2020
Hello there,
Maybe a dumb question, but as we say, the only dumb question are those we don't say.
i'm running on windows and never been a true JS developper, i only worked with legacy Switch JS.
I tryed to use npm command in cmd.exe and powershell, but it did'nt work.
i'm sure i'm missing a fool step, but...
Another question how do you choose if you want to use legacy or node.js script directly in switch variable? (rename with a scripted value for exemple, or in outgoing connection folder)
Maybe a dumb question, but as we say, the only dumb question are those we don't say.
i'm running on windows and never been a true JS developper, i only worked with legacy Switch JS.
I tryed to use npm command in cmd.exe and powershell, but it did'nt work.
i'm sure i'm missing a fool step, but...
Another question how do you choose if you want to use legacy or node.js script directly in switch variable? (rename with a scripted value for exemple, or in outgoing connection folder)
Re: New scripting engine in Switch 2020
Sounds like you need to install nodeJSThomasDeschamps wrote: ↑Thu Jul 09, 2020 10:03 am i'm running on windows and never been a true JS developper, i only worked with legacy Switch JS.
I tryed to use npm command in cmd.exe and powershell, but it did'nt work.
i'm sure i'm missing a fool step, but...
Try to run
Code: Select all
node -v
Code: Select all
v12.16.0
https://nodejs.org/en/
Re: New scripting engine in Switch 2020
just tried a bit node.js scripting within Switch. All in all great! Every little thing which has been missing is now available, wow!
But, during debugging, when changing anything within the script(s), Flow has to be deactivated, the Switchscripter has to be loaded again, then saved (changing the path to the main script), Flow activated. And several times when a debugging process hangs (or I'm unpatient), Scripter damages the package, so it has to be rebuilt.
Maybe the building process is disturbed by the anti-malware process in windows, or am I doing something wrong?
regards,
Ralf.
But, during debugging, when changing anything within the script(s), Flow has to be deactivated, the Switchscripter has to be loaded again, then saved (changing the path to the main script), Flow activated. And several times when a debugging process hangs (or I'm unpatient), Scripter damages the package, so it has to be rebuilt.
Maybe the building process is disturbed by the anti-malware process in windows, or am I doing something wrong?
regards,
Ralf.
-
- Member
- Posts: 32
- Joined: Fri Mar 24, 2017 7:06 pm
- Location: Cleveland, OH
Re: New scripting engine in Switch 2020
Thank you Dwight for posting the link and a great explanation of the new features... I tried out your first example and I keep getting an error that says
Error: unable to verify the first certificate... Any clue as to why I'm seeing this...?
Thank you,
Anthony
Error: unable to verify the first certificate... Any clue as to why I'm seeing this...?
Thank you,
Anthony