New scripting engine in Switch 2020

Post Reply
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

New scripting engine in Switch 2020

Post 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
Scheer
Newbie
Posts: 5
Joined: Tue Mar 15, 2016 3:12 pm

Re: New scripting engine in Switch 2020

Post 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.
cstevens
Member
Posts: 103
Joined: Tue Feb 12, 2013 8:42 pm

Re: New scripting engine in Switch 2020

Post 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.
aoswood
Member
Posts: 20
Joined: Wed Sep 14, 2011 6:16 pm

Re: New scripting engine in Switch 2020

Post 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?
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Re: New scripting engine in Switch 2020

Post by dkelly »

Can you post your Javascript code?
bkromer
Member
Posts: 99
Joined: Thu Jul 11, 2019 10:41 am

Re: New scripting engine in Switch 2020

Post 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?
Benjamin
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: New scripting engine in Switch 2020

Post 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 :)
ThomasDeschamps
Member
Posts: 21
Joined: Wed Jul 20, 2016 12:03 pm

Re: New scripting engine in Switch 2020

Post 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)
KaesDS
Newbie
Posts: 12
Joined: Thu Sep 22, 2016 10:33 am

Re: New scripting engine in Switch 2020

Post 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/
w3gmbh
Newbie
Posts: 12
Joined: Mon Dec 16, 2013 4:14 pm

Re: New scripting engine in Switch 2020

Post 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.
apietrocini
Member
Posts: 32
Joined: Fri Mar 24, 2017 7:06 pm
Location: Cleveland, OH

Re: New scripting engine in Switch 2020

Post 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
Post Reply