Hi.
Try this code:
Your main file code: [MyProjectName].js
function OnStart()
{
lay = app.CreateLayout( "Linear", "VCenter,FillXY" )
txt = app.AddText(lay, "This is your main thread", 1)
callNodeJs = app.AddButton(lay, "Generate pdf in nodejs")
callNodeJs.SetOnTouch( CallNodeJS )
app.AddLayout( lay )
node = app.CreateNode();
node.SetOnReady(node_OnReady);
}
function node_OnReady()
{
node.Run("node_script.js")
}
function CallNodeJS()
{
node.Func("GeneratePDF", "Value from main thread")
}
function OnPDFComplete(param1)
{
app.ShowPopup(param1+": PDF completed...")
}
node_script.js file code:
console.log("Hello from nodejs")
// This function will be called from the main ui thread
function GeneratePDF(param1)
{
// generate pdf here
console.log(param1 + ": Generating pdf...")
// call OnPDFComplete() function in the main thread after 4 seconds
setTimeout(() => {
parent.Func("OnPDFComplete", "Value from nodejs")
}, 4000)