hybridgroup / cylon-example-chrome

Cylon.JS example, running in a Chrome app.
http://cylonjs.com
4 stars 1 forks source link

How does Browserify automatically use chrome.serial API #1

Open vivek1729 opened 8 years ago

vivek1729 commented 8 years ago

Absolutely love the work you guys are doing and I firmly believe that javascript is the way to go with everything. I want to make a Chrome App using cylon.js and therefore stumbled upon this repo from this blog post. Looking through the README, it's documented that we have to write our code in the script.js file for instance and bundle it using Browserify like so:

 ./node_modules/.bin/browserify -r cylon-gpio -r cylon-i2c -r cylon-firmata script.js > ./js/robot.js

While this makes sense to me, after going through browser.js file which is inculded by default in index.html, I notice that there are chrome specific serial API's used there supporting the chrome runtime. Does, Browserify accomplish it by default? I doubt.

So, if I want to modify script.js to support different device having different code, how do I bundle it successfully utilizing the Chrome API's or how do I use browser.js to build the bundled js file otherwise?

deadprogram commented 8 years ago

Hi @vivek1729

The Chrome API's are available in a Chrome packaged app, based on the permissions requested by the manifest.json https://github.com/hybridgroup/cylon-example-chrome/blob/master/manifest.json#L15 and then granted by the user during the installation.

Regarding the auto-handling of the serialport, that is actually handled by browser-serialport https://github.com/garrows/browser-serialport when executing within a Chrome app.

So as you already surmised, you modify your script.js, then use browserfy to build your browser.js file, then use that file to build your Chrome app.

Hope that helps!