Require in Webwiew

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
htuser
Posts: 631
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Require in Webwiew

Post by htuser »

Dear CSPro Developer Team,
Since last october when i tested the 7.7 Alpha version, i feel the greatest freedom sentiment. Now, i've the greatest control on CSPro apps.
Until now,i'm the CSProuser who request the more from you... Right now, i can struggle with JS-CSPro logic API to implement my thinking. And, i feel no
limit with my imaginations. Once again thanks to developer Team.

A question concerning the Webview:
Does can i use JS module using

Code: Select all

const foo = require('foo');
in Webview?
I understand very well JS modules using export/import. However, most existing libs were implemented before support of export/import in browser. Also, for node...
I know there's some workaround such Browserify, Babel and require.js that can be used for using require in browser, but for Webview technologies i'm asking myself if there's no more direct way.
Please let me know.

Best,
G.VOLNY, a CSProuser from Haiti, since 2004
alex_izm
Posts: 19
Joined: December 9th, 2016, 11:31 am

Re: Require in Webwiew

Post by alex_izm »

One way to address this issue is to create a global string variable in your CSPro code with links to all your dependencies and then just embed it in your question CAPI text. For example in your application PROC GLOBAL you can make the following declaration:

Code: Select all

PROC GLOBAL
string links = '<link rel="stylesheet" href="/external/bootstrap/bootstrap.min.css" />'+
    '<link rel="stylesheet" href="/external/bootstrap/bootstrap-icons.css" />'+
    '<link rel="stylesheet" href="/css/reports.css" />'+

    '<script src="/external/jquery/jquery.min.js"></script>'+
    '<script src="/external/bootstrap/bootstrap.bundle.min.js"></script>';
And then in your CAPI HTML you can use the ~~~links~~~ to embed this sting in your HTML:

Code: Select all

~~~links~~~

<button class="btn btn-primary">Bootstrap button</button>
Alex
htuser
Posts: 631
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: Require in Webwiew

Post by htuser »

Thanks Alex for this workaround. While waiting for support of adding external JS libs in Global Proc as it's with external logic file, your latest post will simplify our works.

However, my request was concerning more about using require() function in Webview technologies as it's supported in NodeJS.
An example that i'm thinking about is to connect soil and water sensors to CSEntry Apps via Bluetooth serial. The same way can be using for . The JS libs already exist, but it's almost a nodejs module so, use require , not the import statement. As you know the import statement has been recently implemented in JS (async/await was added in ES8), so, lot of JS modules use require().

Code: Select all

const SerialPort = require('serialport');
const PHMeter= require('phmeter');
Please let's know if there's a way.
Best
G.VOLNY, a CSProuser from Haiti, since 2004
alex_izm
Posts: 19
Joined: December 9th, 2016, 11:31 am

Re: Require in Webwiew

Post by alex_izm »

I am not too familiar with NodeJS, but it, being an actual server, is quite different from the way JS is used in CSPro currently. In our case we are limited by whatever JS can do in a browser client environment. Therefore, things like wrapping a Bluetooth serial connection is not possible since the browser doesn't have access to the OS on such low level.

I guess it might be possible to deploy a NodeJS on your local system and then invoke it from your application JS code. For example https://termux.com/ app allows for deployment of NodeJS on Android devices. I have not tried it so can't vouch for whether it actually works or not.

Alex
htuser
Posts: 631
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: Require in Webwiew

Post by htuser »

Thanks Alex for your support. Hopefully, With goal of PWA (Progressive Web Apps) and Hybrid Apps , Webview will allow more interaction with OS
very soon, so we'll be able to access to low level I/O. In the meantime, i'm reading more on Web Serial and Bluetooth API
https://developer.mozilla.org/en-US/doc ... Serial_API
https://developer.mozilla.org/en-US/doc ... etooth_API
Theses API require the local HTTP server using by CSPro to have HTTPS certificate...

However, theses access would come from CSPro logic because, having a C/C++ engine, it wrap more easily native functions for Windows and Android. But, since i'm asking too much to the developer team :roll: , in can't request this now... :D
Best,
G.VOLNY, a CSProuser from Haiti, since 2004
Post Reply