New scripting engine in Switch 2020

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

New scripting engine in Switch 2020

Post by dkelly » Mon Jun 08, 2020 5:18 pm

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

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: 99
Joined: Tue Feb 12, 2013 8:42 pm

Re: New scripting engine in Switch 2020

Post by cstevens » Wed Jun 10, 2020 10:23 pm

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
Newbie
Posts: 19
Joined: Wed Sep 14, 2011 6:16 pm

Re: New scripting engine in Switch 2020

Post by aoswood » Thu Jun 11, 2020 9:36 pm

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: 655
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Re: New scripting engine in Switch 2020

Post by dkelly » Wed Jun 17, 2020 4:44 pm

Can you post your Javascript code?

User avatar
bkromer
Member
Posts: 34
Joined: Thu Jul 11, 2019 10:41 am
Location: Germany

Re: New scripting engine in Switch 2020

Post by bkromer » Sun Jun 28, 2020 2:57 pm

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 Kromer

freddyp
Advanced member
Posts: 495
Joined: Thu Feb 09, 2012 3:53 pm

Re: New scripting engine in Switch 2020

Post by freddyp » Tue Jul 07, 2020 2:09 pm

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
Newbie
Posts: 15
Joined: Wed Jul 20, 2016 12:03 pm

Re: New scripting engine in Switch 2020

Post by ThomasDeschamps » Thu Jul 09, 2020 10:03 am

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)

Post Reply