blackberry / WebWorks-Community-APIs

Community owned repository containing JavaScript Extensions for BlackBerry WebWorks
Apache License 2.0
141 stars 205 forks source link

Migrate and upstream BarcodeScanner #386

Open timwindsor opened 9 years ago

timwindsor commented 9 years ago

With version 2.0 of the BarcodeScanner, we can now better integrate with the PhoneGap plugin.

Destination repo is here: https://github.com/blackberry/BarcodeScanner

Source is here: https://github.com/blackberry/WebWorks-Community-APIs/tree/master/BB10-Cordova/BarcodeScanner

Planned upstream location is now: https://github.com/hypery2k/cordova-barcodescanner-plugin

timwindsor commented 9 years ago

Upstream is here: https://github.com/phonegap/phonegap-plugin-barcodescanner/pull/32

scheideman commented 9 years ago

Since the ZXing c++ port does not have the encoding methods implemented I looked at some JavaScript libraries as Tim suggested. Here are two that I found which look like they might work: https://github.com/davidshimjs/qrcodejs https://github.com/metafloor/bwip-js

The first one is more popular, much smaller and easier to integrate; however it only for making QRcodes.

timwindsor commented 9 years ago

From what I can tell, it appears that iOS does QRCode only, but Android can take extra parameters to do any supported pattern. We're probably fine just doing the QRCode only then.

scheideman commented 9 years ago

Okay so I am using https://github.com/davidshimjs/qrcodejs. But I am having a issue. The steps I took are:

  1. I include the src file with a <source-file src="src/qrcode.js" /> tag in plugin.xml
  2. I used module.exports in qrcode.js to export the functions I need
  3. Get access to the module in index.js using: qr =require('plugin/com.blackberry.community.barcodescanner/qrcode.js');
  4. then call var qrcode = qr.<function name>(); to call the function from qrcode.js
  5. I call result.ok(data, false) to return the encoded barcode img,

However when I run the app and result.ok() is called I get a undefined warning in frameworkModules.js at

define('lib/plugins/default.js', function (require, exports, module){

          ...

           try {
                requestObj.getExtension().getMethod().exec();
            } catch (e) {
                console.warn(e.msg);
                <undefined warning>
                 fail(-1, e.msg, e.code);
            }
};

And the data is not returned to client.js. Any suggestions?

timwindsor commented 9 years ago

If you open frameworkModules.js while this is added, do you see the qrcode module there? What is it called in the define("...") line?

Also, I expect I didn't mention this before, but you want to apply your work to the plugin in this repo: https://github.com/blackberry/phonegap-plugin-barcodescanner, not here, which is older code before we migrated it into the phonegap cross platform one.

scheideman commented 9 years ago

Yes here is the define line:

define('plugin/com.blackberry.community.barcodescanner/qrcode.js', function (require, exports, module)

Oh okay, I will start working off that repo.

scheideman commented 9 years ago

Also what folder should the qrcode.js file go in? I have been placing it in the src folder with index.js.

timwindsor commented 9 years ago

I think it should go in src with index.js - but I wonder what the right require() call is. It might actually be just:

require('qrcode');

You might have to mess around with it, or even trace the require call to find out.

scheideman commented 9 years ago

I got it working. I have it set up so the encode method returns a 64 bit encoded png image. I just have to do some testing now.

scheideman commented 8 years ago

The only thing I am not sure about is if there is any extra processing I need to do for the different data types (eg. TEXT_TYPE, EMAIL_TYPE, SMS_TYPE,PHONE_TYPE).

timwindsor commented 8 years ago

My thought is that those values are used by the Android ZXing encoder to tweak things. Maybe ignore it for now, unless you have time to test it on and Android device or simulator.