Page 1 of 1

New scripting engine in Switch 2020

Posted: Mon Jun 08, 2020 5:18 pm
by dkelly
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

Re: New scripting engine in Switch 2020

Posted: Wed Jun 10, 2020 8:39 pm
by Scheer
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

Posted: Wed Jun 10, 2020 10:23 pm
by cstevens
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

Posted: Thu Jun 11, 2020 9:36 pm
by aoswood
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?

Re: New scripting engine in Switch 2020

Posted: Wed Jun 17, 2020 4:44 pm
by dkelly
Can you post your Javascript code?

Re: New scripting engine in Switch 2020

Posted: Sun Jun 28, 2020 2:57 pm
by bkromer
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?

Re: New scripting engine in Switch 2020

Posted: Tue Jul 07, 2020 2:09 pm
by freddyp
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 :)

Re: New scripting engine in Switch 2020

Posted: Thu Jul 09, 2020 10:03 am
by ThomasDeschamps
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)

Re: New scripting engine in Switch 2020

Posted: Thu Jul 16, 2020 8:36 am
by KaesDS
ThomasDeschamps 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...
Sounds like you need to install nodeJS ;)

Try to run

Code: Select all

node -v
in powershell. If there's no output like

Code: Select all

v12.16.0
you need to install node to your machine first :!:

https://nodejs.org/en/

Re: New scripting engine in Switch 2020

Posted: Thu Jul 30, 2020 4:41 pm
by w3gmbh
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.

Re: New scripting engine in Switch 2020

Posted: Fri Sep 04, 2020 7:05 pm
by apietrocini
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