@sapui5/sap.ndc 1.96.21 → 1.96.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,22 +3,14 @@
3
3
  * (c) Copyright 2009-2022 SAP SE. All rights reserved.
4
4
  */
5
5
 
6
- /*global cordova, EB, ImageCapture, Map */
6
+ /*global cordova, EB, ImageCapture */
7
7
 
8
- // configure shim for zxing library to allow AMD-like import
8
+ // configure shim for zxingcpp library to allow AMD-like import
9
9
  sap.ui.loader.config({
10
10
  shim: {
11
- 'sap/ndc/thirdparty/ZXing': {
12
- amd: true,
13
- exports: 'ZXing'
14
- },
15
11
  'sap/ndc/thirdparty/zxingcpp/zxing_reader': {
16
12
  amd: true,
17
13
  exports: 'ZXing'
18
- },
19
- 'sap/ndc/thirdparty/opencv/opencv_js': {
20
- amd: true,
21
- exports: 'cv'
22
14
  }
23
15
  }
24
16
  });
@@ -89,10 +81,10 @@ sap.ui.define([
89
81
  /* Internal methods and properties */
90
82
  /* =========================================================== */
91
83
  oStream,
92
- oSrc,
93
- oCap,
94
84
  oScanDialog,
95
85
  oBarcodeVideoDOM,
86
+ oBarcodeCanvasDOM,
87
+ oContext,
96
88
  oBarcodeOverlayDOM,
97
89
  oBarcodeHighlightDOM,
98
90
 
@@ -159,18 +151,7 @@ sap.ui.define([
159
151
  description: "WebAssembly build (using Emcripten) of zxing-cpp",
160
152
  status: oScannerAPIStatus.Initial,
161
153
  instance: null, //oZXingCPP
162
- scannerAPI: null, //oZXingCPPScannerAPI
163
- openCV: {
164
- instance: null, //oCV
165
- scannerAPI: null //oCVInstance
166
- }
167
- },
168
- ZXing: {
169
- key: "ZXing",
170
- description: "ZXing",
171
- status: oScannerAPIStatus.Initial,
172
- instance: null, //oZXing
173
- scannerAPI: null //oZXingScannerAPI
154
+ scannerAPI: null //oZXingCPPScannerAPI
174
155
  }
175
156
  },
176
157
  bReady: true // No scanning is in progress
@@ -194,10 +175,6 @@ sap.ui.define([
194
175
  ZXingCPP: {
195
176
  key: "ZXingCPP",
196
177
  status: oScannerAPIStatus.Initial
197
- },
198
- ZXing: {
199
- key: "ZXing",
200
- status: oScannerAPIStatus.Initial
201
178
  }
202
179
  }
203
180
  }).setDefaultBindingMode(BindingMode.OneWay),
@@ -216,16 +193,6 @@ sap.ui.define([
216
193
  return oModel.getProperty("/apis/" + sScannerAPI + "/");
217
194
  }
218
195
 
219
- /**
220
- * Get the scanner API status in data model
221
- * @param {string} sScannerAPI The scanner API
222
- * @returns {string} The status of the scanner API
223
- * @private
224
- */
225
- function getScannerAPIStatus(sScannerAPI) {
226
- return oModel.getProperty("/apis/" + sScannerAPI + "/status");
227
- }
228
-
229
196
  /**
230
197
  * Update the scanner API in data model
231
198
  * @param {string} sScannerAPI The scanner API
@@ -275,17 +242,13 @@ sap.ui.define([
275
242
  function setScannerAPIUnAvailable(sScannerAPI) {
276
243
  oModel.setProperty("/apis/" + sScannerAPI + "/instance", null);
277
244
  oModel.setProperty("/apis/" + sScannerAPI + "/scannerAPI", null);
278
- if (sScannerAPI === 'ZXingCPP') {
279
- oModel.setProperty("/apis/ZXingCPP/openCV/instance", null);
280
- oModel.setProperty("/apis/ZXingCPP/openCV/scannerAPI", null);
281
- }
282
245
  updateScannerAPI(sScannerAPI, oScannerAPIStatus.UnAvailable);
283
246
  }
284
247
 
285
248
  /**
286
249
  * Returns the current scanner API that will be used to scan.
287
250
  * @private
288
- * @returns {string} The Barcode Scanner API info. (e.g. ZebraEnterpriseBrowser, Cordova, ZXingCPP, ZXing or unknown)
251
+ * @returns {string} The Barcode Scanner API info. (e.g. ZebraEnterpriseBrowser, Cordova, ZXingCPP or unknown)
289
252
  */
290
253
  function getCurrentScannerAPI() {
291
254
  return oModel.getProperty("/scannerAPI");
@@ -343,16 +306,15 @@ sap.ui.define([
343
306
  }
344
307
 
345
308
  /**
346
- * Disable the Feature APIs(ZXing, ZXingCPP)
309
+ * Disable the Feature APIs(ZXingCPP)
347
310
  * @private
348
311
  */
349
312
  function disableFeatureAPIs() {
350
313
  // set the feature available to false since the feature flag is false
351
314
  oModel.setProperty("/available", false);
352
315
  oStatusModel.setProperty("/available", false);
353
- setScannerAPIUnAvailable("ZXing");
354
316
  setScannerAPIUnAvailable("ZXingCPP");
355
- Log.debug("BarcodeScanner.disableFeatureAPIs: Set status of Feature scanner APIs (ZXing, ZXingCPP) to unavailable!");
317
+ Log.debug("BarcodeScanner.disableFeatureAPIs: Set status of Feature scanner APIs (ZXingCPP) to unavailable!");
356
318
  }
357
319
 
358
320
  /**
@@ -361,7 +323,7 @@ sap.ui.define([
361
323
  */
362
324
  function initScannerAPIs() {
363
325
  try {
364
- // check cordova plugin, if exists, no need to check ZXingCPP or ZXing
326
+ // check cordova plugin, if exists, no need to check ZXingCPP
365
327
  var oCordovaScannerAPI = cordova.plugins.barcodeScanner;
366
328
  if (oCordovaScannerAPI) {
367
329
  oModel.setProperty("/apis/Cordova/scannerAPI", oCordovaScannerAPI);
@@ -371,7 +333,7 @@ sap.ui.define([
371
333
  setCurrentScannerAPI("Cordova");
372
334
  }
373
335
  Log.debug("BarcodeScanner.initScannerAPIs: Cordova BarcodeScanner plugin is available!");
374
- // disable feature scanner APIs (ZXingCPP, ZXing)
336
+ // disable feature scanner APIs (ZXingCPP)
375
337
  disableFeatureAPIs();
376
338
  } else {
377
339
  Log.debug("BarcodeScanner.initScannerAPIs: Cordova BarcodeScanner plugin is unavailable!");
@@ -398,61 +360,14 @@ sap.ui.define([
398
360
  loadZXingCPPAPI();
399
361
  }
400
362
 
401
- /**
402
- * Load ZXing scanner API
403
- * @param {function} fnSuccess The callback function if load success
404
- * @param {function} fnFail The callback function if load failed
405
- * @private
406
- */
407
- function loadZXingAPI(fnSuccess, fnFail) {
408
- updateScannerAPI("ZXing", oScannerAPIStatus.Loading);
409
- sap.ui.require([
410
- "sap/ndc/thirdparty/ZXing"
411
- ], function (ZXing) {
412
- var oZXing = ZXing;
413
- if (oZXing) {
414
- oModel.setProperty("/apis/ZXing/instance", ZXing);
415
- var oZXingScannerAPI = new oZXing.BrowserMultiFormatReader();
416
- if (oZXingScannerAPI) {
417
- oModel.setProperty("/apis/ZXing/scannerAPI", oZXingScannerAPI);
418
- setScannerAPIAvailable("ZXing");
419
- Log.debug("BarcodeScanner.loadZXingAPI: ZXing BrowserMultiFormatReader API is available!");
420
- fnSuccess();
421
- } else {
422
- setScannerAPIUnAvailable("ZXing");
423
- Log.error("BarcodeScanner.loadZXingAPI: ZXing BrowserMultiFormatReader API is unavailable");
424
- fnFail();
425
- }
426
- } else {
427
- setScannerAPIUnAvailable("ZXing");
428
- Log.error("BarcodeScanner.loadZXingAPI: ZXing API is unavailable");
429
- fnFail();
430
- }
431
- }, function (oError) {
432
- setScannerAPIUnAvailable("ZXing");
433
- Log.error("BarcodeScanner.loadZXingAPI: ZXing API is unavailable.\n" + oError);
434
- fnFail();
435
- });
436
- }
437
-
438
363
  /**
439
364
  * Callback for Load ZXingCPP scanner API or Instances failed
440
365
  * @private
441
366
  */
442
367
  function loadZXingCPPFailed(sMessage) {
443
368
  Log.error(sMessage);
444
- setScannerAPIUnAvailable("ZXingCPP");
445
- var sZXingStatus = getScannerAPIStatus("ZXing");
446
- if (sZXingStatus === oScannerAPIStatus.UnAvailable) {
447
- // set the feature available to false since both of ZXing and ZXingCPP are unavailable
448
- Log.warning("BarcodeScanner.loadZXingCPPFailed: ZXing is unavailable too, no feature scanner API available now.");
449
- oModel.setProperty("/available", false);
450
- oStatusModel.setProperty("/available", false);
451
- } else if (getCurrentScannerAPI() !== "ZebraEnterpriseBrowser"){
452
- // if current scanner API is not Zebra and ZXing is not unavailable, set ZXing as current scanner API
453
- Log.debug("BarcodeScanner.loadZXingCPPFailed: Zebra is not current scanner API, ZXing if NOT UnAvailable, so set ZXing as current scanner API.");
454
- setCurrentScannerAPI("ZXing");
455
- }
369
+ Log.warning("BarcodeScanner.loadZXingCPPFailed: no feature scanner API available now.");
370
+ disableFeatureAPIs();
456
371
  oModel.checkUpdate(true);
457
372
  }
458
373
 
@@ -464,11 +379,9 @@ sap.ui.define([
464
379
  Log.info("BarcodeScanner.loadZXingCPPAPI: load ZXingCPP API");
465
380
  updateScannerAPI("ZXingCPP", oScannerAPIStatus.Loading);
466
381
  sap.ui.require([
467
- "sap/ndc/thirdparty/zxingcpp/zxing_reader",
468
- "sap/ndc/thirdparty/opencv/opencv_js"
469
- ], function (ZXing, cv) {
382
+ "sap/ndc/thirdparty/zxingcpp/zxing_reader"
383
+ ], function (ZXing) {
470
384
  oModel.setProperty("/apis/ZXingCPP/instance", ZXing);
471
- oModel.setProperty("/apis/ZXingCPP/openCV/instance", cv);
472
385
  if (getCurrentScannerAPI() === "unknown") {
473
386
  // set current scanner API to ZXingCPP if Zebra is unavailable
474
387
  setCurrentScannerAPI("ZXingCPP");
@@ -481,30 +394,38 @@ sap.ui.define([
481
394
  }
482
395
 
483
396
  /**
484
- * Load ZXingCPP scanner Instances.
397
+ * Load ZXingCPP scanner Instance.
485
398
  * @param {function} fnSuccess The callback function if load success
486
399
  * @param {function} fnFail The callback function if load failed
487
400
  * @private
488
401
  */
489
- function loadZXingCPPInstances(fnSuccess, fnFail) {
490
- // since the size or opencv.wasm is about 6.5M, we need to open a busy dialog to lock the current frame/page
402
+ function loadZXingCPPInstance(fnSuccess, fnFail) {
403
+ // since the size of zxing_reader.wasm is about 1M, we need to open a busy dialog to lock the current frame/page
491
404
  var oBusyDialog = new BusyDialog({
492
405
  title: oResourceModel.getProperty("BARCODE_DIALOG_BUSY_TITLE"),
493
406
  text: oResourceModel.getProperty("BARCODE_DIALOG_BUSY_TEXT_ZXINGCPP")
494
407
  });
495
408
  oBusyDialog.open();
496
409
  updateScannerAPI("ZXingCPP", oScannerAPIStatus.Loading);
497
- Promise.all([loadZXingCPPInstance(), loadOpenCVInstance()]).then(function() {
410
+ var oZXingCPPConfig = {
411
+ "locateFile": function(sPath, sScriptDictionary) {
412
+ return locateFile(sPath, sScriptDictionary, "zxingcpp");
413
+ }
414
+ };
415
+ var oZXingCPP = oModel.getProperty("/apis/ZXingCPP/instance");
416
+ oZXingCPP(oZXingCPPConfig).then(function(instance) {
417
+ oModel.setProperty("/apis/ZXingCPP/scannerAPI", instance);
418
+ Log.debug("BarcodeScanner.loadZXingCPPInstance: wasm lib instance of ZXingCPP is available!");
498
419
  setScannerAPIAvailable("ZXingCPP");
499
420
  if (getCurrentScannerAPI() === "unknown") {
500
421
  // set current scanner API to ZXingCPP if Zebra is unavailable
501
422
  setCurrentScannerAPI("ZXingCPP");
502
423
  }
503
- Log.debug("BarcodeScanner.loadZXingCPPInstances: ZXingCPP API is available!");
424
+ Log.debug("BarcodeScanner.loadZXingCPPInstance: ZXingCPP API is available!");
504
425
  oBusyDialog.close();
505
426
  fnSuccess();
506
- }, function(sMessage) {
507
- loadZXingCPPFailed(sMessage);
427
+ }, function(oError) {
428
+ loadZXingCPPFailed("BarcodeScanner.loadZXingCPPInstance: can not load wasm lib instance of ZXingCPP.\n" + oError);
508
429
  oBusyDialog.close();
509
430
  fnFail();
510
431
  });
@@ -525,60 +446,6 @@ sap.ui.define([
525
446
  return sScriptDictionary + sPath;
526
447
  }
527
448
 
528
- /**
529
- * Load ZXingCPP wasm file
530
- * @returns {Promise} Promise object which loads the ZXingCPP instance
531
- * @private
532
- */
533
- function loadZXingCPPInstance() {
534
- return new Promise(function (resolve, reject) {
535
- var oZXingCPPConfig = {
536
- "locateFile": function(sPath, sScriptDictionary) {
537
- return locateFile(sPath, sScriptDictionary, "zxingcpp");
538
- }
539
- };
540
- var oZXingCPP = oModel.getProperty("/apis/ZXingCPP/instance");
541
- oZXingCPP(oZXingCPPConfig).then(function(instance) {
542
- if (isScannerAPIUnAvailable("ZXingCPP")) {
543
- Log.warning("BarcodeScanner.loadZXingCPPInstance: ZXingCPP is set to unavailable by failure of loading opencv instance!");
544
- } else {
545
- oModel.setProperty("/apis/ZXingCPP/scannerAPI", instance);
546
- Log.debug("BarcodeScanner.loadZXingCPPInstance: wasm lib instance of ZXingCPP is available!");
547
- }
548
- resolve();
549
- }, function(oError) {
550
- reject("BarcodeScanner.loadZXingCPPInstance: can not load wasm lib instance of ZXingCPP.\n" + oError);
551
- });
552
- });
553
- }
554
-
555
- /**
556
- * Load opencv wasm file
557
- * @returns {Promise} Promise object which loads the OpenCV instance
558
- * @private
559
- */
560
- function loadOpenCVInstance() {
561
- return new Promise(function (resolve, reject) {
562
- var oOpenCVConfig = {
563
- "locateFile": function(sPath, sScriptDictionary) {
564
- return locateFile(sPath, sScriptDictionary, "opencv");
565
- }
566
- };
567
- var oCV = oModel.getProperty("/apis/ZXingCPP/openCV/instance");
568
- oCV(oOpenCVConfig).then(function(instance) {
569
- if (isScannerAPIUnAvailable("ZXingCPP")) {
570
- Log.warning("BarcodeScanner.loadOpenCVInstance: ZXingCPP is set to unavailable by failure of loading zxingcpp instance!");
571
- } else {
572
- oModel.setProperty("/apis/ZXingCPP/openCV/scannerAPI", instance);
573
- Log.debug("BarcodeScanner.loadOpenCVInstance: wasm lib instance of opencv is available!");
574
- }
575
- resolve();
576
- }, function(oError) {
577
- reject("BarcodeScanner.loadOpenCVInstance: can not load wasm lib instance of opencv.\n" + oError);
578
- });
579
- });
580
- }
581
-
582
449
  /**
583
450
  * Used to detect if browser support enumerate devices
584
451
  * @private
@@ -685,12 +552,7 @@ sap.ui.define([
685
552
  updateDevicesInStatusModel();
686
553
  Log.debug("BarcodeScanner.findMainCamera: the main camera is " + oCamera.deviceId);
687
554
  oStream = stream;
688
- // use ZXingCPP or ZXing to scan the barcode directly if :
689
- // current scanner API is ZXing, and ZXing is available
690
- // or
691
- // current scanner API is NOT ZXing, ZXingCPP is available, and the video stream is not null
692
- if ((getCurrentScannerAPI() !== "ZXing" && isScannerAPIAvailable("ZXingCPP"))
693
- || (getCurrentScannerAPI() === "ZXing" && isScannerAPIAvailable("ZXing"))) {
555
+ if (oStream) {
694
556
  openBarcodeScannerDialogContains();
695
557
  } else {
696
558
  oScanDialog.getModel().setProperty("/isNoScanner", true);
@@ -953,7 +815,7 @@ sap.ui.define([
953
815
  if (!oModel.getProperty("/config/preferFrontCamera")) {
954
816
  delete oModel.getProperty("/config/defaultConstraints/video").facingMode;
955
817
  var oDevices = oModel.getProperty("/devices");
956
- if (isUserMediaAccessSupported() && !oModel.getProperty("/config/deviceId") && !oDevices.mainCamera && !Device.os.ios && oDevices.needCheck && oDevices.all.length > 1) {
818
+ if (!oModel.getProperty("/config/deviceId") && !oDevices.mainCamera && !Device.os.ios && oDevices.needCheck && oDevices.all.length > 1) {
957
819
  var oCameras = oDevices.back.length > 1 ? oDevices.back : oDevices.all;
958
820
  var sCategory = oDevices.back.length > 1 ? "back" : "all";
959
821
  Log.debug("BarcodeScanner.openBarcodeScannerDialog: start to find the main camera in " + sCategory + " camera list.");
@@ -989,12 +851,7 @@ sap.ui.define([
989
851
  .then(
990
852
  function(stream) {
991
853
  oStream = stream;
992
- // use ZXingCPP or ZXing to scan the barcode if :
993
- // current scanner API is ZXing, and ZXing is available
994
- // or
995
- // current scanner API is NOT ZXing, ZXingCPP is available, and the video stream is not null
996
- if ((getCurrentScannerAPI() !== "ZXing" && isScannerAPIAvailable("ZXingCPP") && oStream)
997
- || (getCurrentScannerAPI() === "ZXing" && isScannerAPIAvailable("ZXing"))) {
854
+ if (oStream) {
998
855
  openBarcodeScannerDialogContains();
999
856
  } else {
1000
857
  oModel.setProperty("/scanDialog/isNoScanner", true);
@@ -1052,7 +909,7 @@ sap.ui.define([
1052
909
  oScanDialog.setModel(oResourceModel, "i18n");
1053
910
  }
1054
911
 
1055
- if ((isScannerAPIAvailable("ZXingCPP") || isScannerAPIAvailable("ZXing")) && isUserMediaAccessSupported()) {
912
+ if (isScannerAPIAvailable("ZXingCPP") && isUserMediaAccessSupported()) {
1056
913
  openBarcodeScannerDialog();
1057
914
  } else {
1058
915
  if (oModel.getProperty("/available")) {
@@ -1118,42 +975,6 @@ sap.ui.define([
1118
975
  );
1119
976
  }
1120
977
 
1121
- /**
1122
- * Scan the barcode via ZXing
1123
- * @private
1124
- */
1125
- function scanWithZXing() {
1126
- if (checkScannerAPIStatus("ZXing", oScannerAPIStatus.Initial)) {
1127
- Log.debug("BarcodeScanner.scanWithZXing: ZXing is not loaded, start to load it.");
1128
- loadZXingAPI(function() {
1129
- getScanDialog();
1130
- }, function() {
1131
- if (isScannerAPIUnAvailable("ZXingCPP")) {
1132
- Log.warning("BarcodeScanner.scanWithZXing: ZXingCPP is unavailable too, no feature scanner API available now.");
1133
- // set the feature available to false since both of ZXing and ZXingCPP are unavailable
1134
- oModel.setProperty("/available", false);
1135
- oStatusModel.setProperty("/available", false);
1136
- Log.warning("BarcodeScanner.scanWithZXing: Set feature available to False");
1137
- if (isScannerAPIAvailable("ZebraEnterpriseBrowser")) {
1138
- setCurrentScannerAPI("ZebraEnterpriseBrowser");
1139
- Log.debug("BarcodeScanner.scanWithZXing: Zebra is available, set the current scanner API to Zebra.");
1140
- } else {
1141
- setCurrentScannerAPI("unknown");
1142
- Log.warning("BarcodeScanner.scanWithZXing: Zebra is unavailable too, set the current scanner API to unknown.");
1143
- }
1144
- getScanDialog();
1145
- } else {
1146
- // if ZXingCPP scanner API is NOT UnAvailable, set ZXingCPP as current scanner API, and use it to scan bacode.
1147
- setCurrentScannerAPI("ZXingCPP");
1148
- Log.debug("BarcodeScanner.scanWithZXing: ZXingCPP is NOT UnAvailable, switch to ZXingCPP to scan barcode.");
1149
- scanWithZXingCPP();
1150
- }
1151
- });
1152
- } else {
1153
- getScanDialog();
1154
- }
1155
- }
1156
-
1157
978
  /**
1158
979
  * Scan the barcode via ZXingCPP
1159
980
  * @private
@@ -1161,28 +982,17 @@ sap.ui.define([
1161
982
  function scanWithZXingCPP() {
1162
983
  if (checkScannerAPIStatus("ZXingCPP", oScannerAPIStatus.Initial)) {
1163
984
  Log.debug("BarcodeScanner.scanWithZXingCPP: ZXingCPP instances is not loaded, start to load them.");
1164
- loadZXingCPPInstances(function() {
985
+ loadZXingCPPInstance(function() {
1165
986
  getScanDialog();
1166
987
  }, function() {
1167
- if (isScannerAPIUnAvailable("ZXing")) {
1168
- Log.warning("BarcodeScanner.scanWithZXingCPP: ZXing is unavailable too, no feature scanner API available now.");
1169
- // set the feature available to false since both of ZXing and ZXingCPP are unavailable
1170
- oModel.setProperty("/available", false);
1171
- oStatusModel.setProperty("/available", false);
1172
- Log.warning("BarcodeScanner.scanWithZXingCPP: Set feature available to False");
1173
- if (isScannerAPIAvailable("ZebraEnterpriseBrowser")) {
1174
- setCurrentScannerAPI("ZebraEnterpriseBrowser");
1175
- Log.debug("BarcodeScanner.scanWithZXingCPP: Zebra is available, set the current scanner API to Zebra.");
1176
- } else {
1177
- setCurrentScannerAPI("unknown");
1178
- Log.warning("BarcodeScanner.scanWithZXingCPP: Zebra is unavailable too, set the current scanner API to unknown.");
1179
- }
1180
- getScanDialog();
988
+ if (isScannerAPIAvailable("ZebraEnterpriseBrowser")) {
989
+ setCurrentScannerAPI("ZebraEnterpriseBrowser");
990
+ Log.debug("BarcodeScanner.scanWithZXingCPP: Zebra is available, set the current scanner API to Zebra.");
1181
991
  } else {
1182
- // if ZXing scanner API is NOT UnAvailable, use ZXing to scan the barcode.
1183
- Log.debug("BarcodeScanner.scanWithZXingCPP: ZXing is NOT UnAvailable, switch to ZXing to scan barcode.");
1184
- scanWithZXing();
992
+ setCurrentScannerAPI("unknown");
993
+ Log.warning("BarcodeScanner.scanWithZXingCPP: Zebra is unavailable too, set the current scanner API to unknown.");
1185
994
  }
995
+ getScanDialog();
1186
996
  });
1187
997
  } else {
1188
998
  getScanDialog();
@@ -1195,65 +1005,48 @@ sap.ui.define([
1195
1005
  */
1196
1006
  function openBarcodeScannerDialogContains() {
1197
1007
  var oBarcodeScannerUIContainer;
1198
- if (getCurrentScannerAPI() !== "ZXing") {
1199
- Log.debug("BarcodeScanner.openBarcodeScannerDialogContains: Use ZXingCPP to read the barcode.");
1200
- oScanDialog.attachAfterOpen(function() {
1201
- // Dev note: if video element dom reference is unavailable at this point (console exception)
1202
- // some error happened during dialog creation and may not be directly related to video element
1203
- oScanDialog.getEndButton().setEnabled(true);
1204
- oScanDialog.setBusy(false);
1205
-
1206
- if (!oBarcodeHighlightDOM) {
1207
- oBarcodeHighlightDOM = oBarcodeScannerUIContainer.getDomRef('highlight');
1208
- }
1209
- if (!oBarcodeVideoDOM) {
1210
- oBarcodeVideoDOM = oBarcodeScannerUIContainer ? oBarcodeScannerUIContainer.getDomRef('video') : undefined;
1211
- }
1212
- try {
1213
- oBarcodeVideoDOM.srcObject = oStream;
1214
- oBarcodeVideoDOM
1215
- .play()
1216
- .then(function() {
1217
- if (!oSrc) {
1218
- oBarcodeVideoDOM.width = oBarcodeVideoDOM.videoWidth;
1219
- oBarcodeVideoDOM.height = oBarcodeVideoDOM.videoHeight;
1220
- var oCVInstance = oModel.getProperty("/apis/ZXingCPP/openCV/scannerAPI");
1221
- oSrc = new oCVInstance.Mat(oBarcodeVideoDOM.videoHeight, oBarcodeVideoDOM.videoWidth, oCVInstance.CV_8UC4);
1222
- oCap = new oCVInstance.VideoCapture(oBarcodeVideoDOM);
1223
- }
1224
- decodeWithZXingCPP();
1225
- });
1226
- } catch (err) {
1227
- Log.debug("BarcodeScanner.openBarcodeScannerDialogContains is failed. error: " + err);
1228
- }
1229
- });
1230
- } else {
1231
- Log.debug("BarcodeScanner.openBarcodeScannerDialogContains: Use zxing to read the barcode.");
1232
- if (Device.os.ios && Device.os.versionStr.split('.')[0] === '16' && oStream) {
1233
- // When decoding QR-code by iPhone (iOS 16), this stream will clash with another stream from ZXing-js.
1234
- var videoTrack = typeof oStream.stop === "function" ? oStream : oStream.getTracks()[0];
1235
- videoTrack.stop();
1008
+ Log.debug("BarcodeScanner.openBarcodeScannerDialogContains: Use ZXingCPP to read the barcode.");
1009
+ oScanDialog.attachAfterOpen(function() {
1010
+ // Dev note: if video element dom reference is unavailable at this point (console exception)
1011
+ // some error happened during dialog creation and may not be directly related to video element
1012
+ oScanDialog.getEndButton().setEnabled(true);
1013
+ oScanDialog.setBusy(false);
1014
+
1015
+ if (!oBarcodeHighlightDOM) {
1016
+ oBarcodeHighlightDOM = oBarcodeScannerUIContainer.getDomRef('highlight');
1236
1017
  }
1237
- oScanDialog.attachAfterOpen(function() {
1238
- // Dev note: if video element dom reference is unavailable at this point (console exception)
1239
- // some error happened during dialog creation and may not be directly related to video element
1240
- oScanDialog.getEndButton().setEnabled(true);
1241
- oScanDialog.setBusy(false);
1242
-
1243
- if (!oBarcodeHighlightDOM) {
1244
- oBarcodeHighlightDOM = oBarcodeScannerUIContainer ? oBarcodeScannerUIContainer.getDomRef('highlight') : undefined;
1018
+ if (!oBarcodeVideoDOM) {
1019
+ oBarcodeVideoDOM = oBarcodeScannerUIContainer ? document.createElement("video") : undefined;
1020
+ if (oBarcodeVideoDOM) {
1021
+ oBarcodeVideoDOM.setAttribute("id", "video");
1022
+ oBarcodeVideoDOM.setAttribute("autoplay", "autoplay");
1023
+ oBarcodeVideoDOM.setAttribute("webkit-playsinline", "webkit-playsinline");
1024
+ oBarcodeVideoDOM.setAttribute("playsinline", "playsinline");
1245
1025
  }
1246
- if (!oBarcodeVideoDOM) {
1247
- oBarcodeVideoDOM = oBarcodeScannerUIContainer ? oBarcodeScannerUIContainer.getDomRef('video') : undefined;
1248
- }
1249
- decodeWithZXing();
1250
- });
1251
- }
1026
+ }
1027
+ if (!oBarcodeCanvasDOM) {
1028
+ oBarcodeCanvasDOM = oBarcodeScannerUIContainer ? oBarcodeScannerUIContainer.getDomRef('canvas') : undefined;
1029
+ oContext = oBarcodeCanvasDOM.getContext("2d", { willReadFrequently: true });
1030
+ }
1031
+ try {
1032
+ oBarcodeVideoDOM.srcObject = oStream;
1033
+ oBarcodeVideoDOM.play().then(function() {
1034
+ oBarcodeCanvasDOM.width = oBarcodeVideoDOM.videoWidth;
1035
+ oBarcodeCanvasDOM.height = oBarcodeVideoDOM.videoHeight;
1036
+ decodeWithZXingCPP();
1037
+ });
1038
+ } catch (err) {
1039
+ Log.debug("BarcodeScanner.openBarcodeScannerDialogContains is failed. error: " + err);
1040
+ }
1041
+ });
1252
1042
  oScanDialog.destroyContent();
1253
1043
  oBarcodeHighlightDOM = undefined;
1254
1044
  oBarcodeOverlayDOM = undefined;
1255
1045
  oBarcodeVideoDOM = undefined;
1256
1046
 
1047
+ oBarcodeCanvasDOM = undefined;
1048
+ oContext = undefined;
1049
+
1257
1050
  oBarcodeScannerUIContainer = new BarcodeScannerUIContainer();
1258
1051
  oScanDialog.addContent(oBarcodeScannerUIContainer);
1259
1052
 
@@ -1271,20 +1064,18 @@ sap.ui.define([
1271
1064
  * @private
1272
1065
  */
1273
1066
  function decodeWithZXingCPP() {
1274
- if (!oBarcodeVideoDOM.srcObject && oSrc) {
1275
- oSrc.delete();
1067
+ if (!oBarcodeVideoDOM || !oBarcodeVideoDOM.srcObject) {
1276
1068
  return;
1277
1069
  }
1278
- scanFrame(oBarcodeVideoDOM);
1279
- var oData;
1280
- try {
1281
- oCap.read(oSrc);
1282
- oData = oSrc.data;
1283
- } catch (err) {
1284
- Log.info("BarcodeScanner.decodeWithZXingCPP: cap.read error: " + err);
1285
- }
1070
+ scanFrame();
1286
1071
 
1287
1072
  try {
1073
+ oContext.drawImage(oBarcodeVideoDOM, 0, 0, oBarcodeCanvasDOM.width, oBarcodeCanvasDOM.height);
1074
+
1075
+ var imgWidth = oBarcodeCanvasDOM.width;
1076
+ var imgHeight = oBarcodeCanvasDOM.height;
1077
+ var imageData = oBarcodeCanvasDOM.getContext('2d').getImageData(0, 0, imgWidth, imgHeight);
1078
+ var oData = imageData.data;
1288
1079
  var buffer;
1289
1080
  var oZXingCPPScannerAPI = oModel.getProperty("/apis/ZXingCPP/scannerAPI");
1290
1081
  try {
@@ -1293,12 +1084,11 @@ sap.ui.define([
1293
1084
  } catch (err) {
1294
1085
  Log.info("BarcodeScanner.decodeWithZXingCPP: zxing.HEAPU8 error: " + err);
1295
1086
  }
1296
- var width = oSrc.cols;
1297
- var height = oSrc.rows;
1298
- var result;
1299
- result = oZXingCPPScannerAPI.readBarcodeFromPixmap(buffer, width,height, true, "");
1087
+ var results = oZXingCPPScannerAPI.readBarcodesFromPixmap(buffer, imgWidth, imgHeight, true, "", 1);
1300
1088
  oZXingCPPScannerAPI._free(buffer);
1301
- if (result.format) {
1089
+ var iSize = results.size();
1090
+ if (iSize > 0 && results.get(0).format) {
1091
+ var result = results.get(0);
1302
1092
  highlightResult(result);
1303
1093
  if (result.cancelled === "false" || !result.cancelled) {
1304
1094
  result.cancelled = false;
@@ -1328,56 +1118,6 @@ sap.ui.define([
1328
1118
  }
1329
1119
  }
1330
1120
 
1331
- /**
1332
- * Decode the barcode via ZXing scanner API
1333
- * @private
1334
- */
1335
- function decodeWithZXing() {
1336
- var hints = new Map();
1337
- var oZXing = oModel.getProperty("/apis/ZXing/instance");
1338
- hints.set(oZXing.DecodeHintType.ASSUME_GS1, true);
1339
- var oZXingScannerAPI = oModel.getProperty("/apis/ZXing/scannerAPI");
1340
- oZXingScannerAPI.reader.setHints(hints);
1341
-
1342
- var callBackHandler = function (result, err) {
1343
- scanFrame(oBarcodeVideoDOM);
1344
- if (result) {
1345
- highlightResult(result);
1346
- if (result.cancelled === "false" || !result.cancelled) {
1347
- result.cancelled = false;
1348
- var onFnSuccess = oModel.getProperty("/callBackHandler/onFnSuccess");
1349
- if (typeof onFnSuccess === "function") {
1350
- result.scanningTime = "unknown";
1351
- if (oModel.getProperty("/scanDialog/scanningStartTime") > 0) {
1352
- var scanningStopTime = Date.now();
1353
- result.scanningTime = scanningStopTime - oModel.getProperty("/scanDialog/scanningStartTime");
1354
- }
1355
- if (!oModel.getProperty("/config/enableGS1Header") && result.text.indexOf("]C1") === 0) {
1356
- // Remove the prefix from GS1-128 barcode result of ZXing-js
1357
- result.text = result.text.split("]C1")[1];
1358
- }
1359
- onFnSuccess(result);
1360
- }
1361
- BarcodeScanner.closeScanDialog();
1362
- }
1363
- } else if (oBarcodeHighlightDOM && oModel.getProperty("/scanDialog/barcodeOverlaySetup")) {
1364
- hideHightLight();
1365
- }
1366
-
1367
- if (err && oZXing && !(err instanceof oZXing.NotFoundException)) {
1368
- Log.warning("BarcodeScanner.decodeWithZXing: Started continuous decode failed.");
1369
- var onFnFail = oModel.getProperty("/callBackHandler/onFnFail");
1370
- if (typeof onFnFail === "function") {
1371
- onFnFail(err);
1372
- oModel.setProperty("/scanDialog/isNoScanner", true);
1373
- openBarcodeInputDialog();
1374
- }
1375
- }
1376
- };
1377
-
1378
- oZXingScannerAPI.decodeFromConstraints(oModel.getProperty("/config/defaultConstraints"), oBarcodeVideoDOM.id, callBackHandler);
1379
- }
1380
-
1381
1121
  /**
1382
1122
  * Highlight the scan result area
1383
1123
  * @param {object} result The scan result object
@@ -1397,8 +1137,8 @@ sap.ui.define([
1397
1137
  }
1398
1138
 
1399
1139
  if (oBarcodeHighlightDOM) {
1400
- scaleX = oBarcodeVideoDOM.clientWidth / oBarcodeVideoDOM.videoWidth;
1401
- scaleY = oBarcodeVideoDOM.clientHeight / oBarcodeVideoDOM.videoHeight;
1140
+ scaleX = oBarcodeCanvasDOM.clientWidth / oBarcodeVideoDOM.videoWidth;
1141
+ scaleY = oBarcodeCanvasDOM.clientHeight / oBarcodeVideoDOM.videoHeight;
1402
1142
  if (result.position) {
1403
1143
  result.resultPoints = [
1404
1144
  result.position.topLeft,
@@ -1448,8 +1188,8 @@ sap.ui.define([
1448
1188
  oBarcodeHighlightDOM.style.height = '0';
1449
1189
  }
1450
1190
 
1451
- function scanFrame(video) {
1452
- if (!oScanDialog || !video || !video.videoHeight || !video.videoWidth) {
1191
+ function scanFrame() {
1192
+ if (!oScanDialog || !oBarcodeCanvasDOM) {
1453
1193
  return;
1454
1194
  }
1455
1195
  var iInactiveZonePercent = 0.15;
@@ -1459,11 +1199,11 @@ sap.ui.define([
1459
1199
  oBarcodeOverlayDOM = oBarcodeScannerUIContainer.getDomRef('overlay');
1460
1200
  }
1461
1201
 
1462
- updateZoom(video);
1202
+ updateZoom();
1463
1203
 
1464
1204
  if (oBarcodeOverlayDOM) {
1465
- var oBarcodeOverlayWidthTemp = video.clientWidth * (1 - 2 * iInactiveZonePercent);
1466
- var oBarcodeOverlayHeightTemp = video.clientHeight * (1 - 2 * iInactiveZonePercent);
1205
+ var oBarcodeOverlayWidthTemp = oBarcodeCanvasDOM.clientWidth * (1 - 2 * iInactiveZonePercent);
1206
+ var oBarcodeOverlayHeightTemp = oBarcodeCanvasDOM.clientHeight * (1 - 2 * iInactiveZonePercent);
1467
1207
 
1468
1208
  if (oBarcodeOverlayWidthTemp <= oBarcodeOverlayHeightTemp) {
1469
1209
  oBarcodeOverlayHeightTemp = oBarcodeOverlayWidthTemp * (1 - 2 * iInactiveZonePercent);
@@ -1477,14 +1217,14 @@ sap.ui.define([
1477
1217
 
1478
1218
  oBarcodeOverlayDOM.style.width = oBarcodeOverlayWidthTemp + 'px';
1479
1219
  oBarcodeOverlayDOM.style.height = oBarcodeOverlayHeightTemp + 'px';
1480
- oBarcodeOverlayDOM.style.borderWidth = (video.clientHeight - oBarcodeOverlayHeightTemp) / 2 + 'px ' + (video.clientWidth - oBarcodeOverlayWidthTemp) / 2 + 'px';
1220
+ oBarcodeOverlayDOM.style.borderWidth = (oBarcodeCanvasDOM.clientHeight - oBarcodeOverlayHeightTemp) / 2 + 'px ' + (oBarcodeCanvasDOM.clientWidth - oBarcodeOverlayWidthTemp) / 2 + 'px';
1481
1221
  }
1482
1222
  }
1483
1223
  }
1484
1224
 
1485
- function updateZoom(video) {
1486
- if (oModel.getProperty("/config/zoom") !== "skipUpdateZoom" && video) {
1487
- var videoTrack = video.srcObject.getVideoTracks();
1225
+ function updateZoom() {
1226
+ if (oModel.getProperty("/config/zoom") !== "skipUpdateZoom" && oBarcodeVideoDOM) {
1227
+ var videoTrack = oBarcodeVideoDOM.srcObject.getVideoTracks();
1488
1228
  var oSupport = window.navigator.mediaDevices.getSupportedConstraints();
1489
1229
  var capabilities = videoTrack[0].getCapabilities();
1490
1230
  // Verify the permission about updating zoom
@@ -1538,22 +1278,11 @@ sap.ui.define([
1538
1278
  }
1539
1279
 
1540
1280
  function closeScannerContain() {
1541
- if (getCurrentScannerAPI() === "ZXing" && isScannerAPIAvailable("ZXing")) {
1542
- var oZXingScannerAPI = oModel.getProperty("/apis/ZXing/scannerAPI");
1543
- oZXingScannerAPI.reset();
1544
- oZXingScannerAPI.stopContinuousDecode();
1545
- oZXingScannerAPI.reader.reset();
1546
- }
1547
1281
  if (oStream) {
1548
1282
  var videoTrack = typeof oStream.stop === "function" ? oStream : oStream.getTracks()[0];
1549
1283
  videoTrack.stop();
1550
1284
  oStream = undefined;
1551
1285
  }
1552
- if (oSrc) {
1553
- oSrc.delete();
1554
- oSrc = undefined;
1555
- }
1556
- oCap = undefined;
1557
1286
  }
1558
1287
 
1559
1288
  function zebraEBScanEnable() {
@@ -1732,8 +1461,6 @@ sap.ui.define([
1732
1461
  scanWithZebra();
1733
1462
  } else if (isScannerAPIAvailable("Cordova")) {
1734
1463
  scanWithCordova();
1735
- } else if (getCurrentScannerAPI() === "ZXing") {
1736
- scanWithZXing();
1737
1464
  } else {
1738
1465
  scanWithZXingCPP();
1739
1466
  }
@@ -1776,10 +1503,6 @@ sap.ui.define([
1776
1503
  * {
1777
1504
  * key: "ZXingCPP",
1778
1505
  * status: "Available"
1779
- * },
1780
- * {
1781
- * key: "ZXing",
1782
- * status: "Initial"
1783
1506
  * }
1784
1507
  * ]
1785
1508
  * }
@@ -1804,7 +1527,7 @@ sap.ui.define([
1804
1527
  /**
1805
1528
  * Returns the scanner API info that will be used to scan the barcode.
1806
1529
  *
1807
- * @returns {string} The Barcode Scanner API info. (e.g. ZebraEnterpriseBrowser, Cordova, ZXingCPP, ZXing or unknown)
1530
+ * @returns {string} The Barcode Scanner API info. (e.g. ZebraEnterpriseBrowser, Cordova, ZXingCPP or unknown)
1808
1531
  * @public
1809
1532
  * @static
1810
1533
  */
@@ -1816,10 +1539,10 @@ sap.ui.define([
1816
1539
  /**
1817
1540
  * Set the scanner API info that will be used to scan the barcode.
1818
1541
  *
1819
- * IMPORTANT: The status of the scanner API must be <strong>"Available"</strong>(for ZXingCPP and ZXing, status is <strong>NOT "UnAvailable"</strong>), or will return False. Scanner APIs with status value can be got by using {@link #getStatusModel}.
1820
- * By default, Barcode Scanner will select the scanner API(Available) with priority: ZebraEnterpriseBrowser > Cordova > ZXingCPP > ZXing.
1542
+ * IMPORTANT: The status of the scanner API must be <strong>"Available"</strong>(for ZXingCPP, status is <strong>NOT "UnAvailable"</strong>), or will return False. Scanner APIs with status value can be got by using {@link #getStatusModel}.
1543
+ * By default, Barcode Scanner will select the scanner API(Available) with priority: ZebraEnterpriseBrowser > Cordova > ZXingCPP.
1821
1544
  *
1822
- * @param {string} [scannerAPI] Defines the scanner API to scan the barcode. Scanner API can be "ZebraEnterpriseBrowser", "Cordova", "ZXingCPP" or "ZXing".
1545
+ * @param {string} [scannerAPI] Defines the scanner API to scan the barcode. Scanner API can be "ZebraEnterpriseBrowser", "Cordova", "ZXingCPP".
1823
1546
  * @returns {boolean} Return True if set success.
1824
1547
  * @public
1825
1548
  * @static
@@ -1835,7 +1558,7 @@ sap.ui.define([
1835
1558
  if (!oScannerAPI) {
1836
1559
  Log.error("BarcodeScanner.scan: The scanner API '" + scannerAPI + "' doesn't exist, will use current scanner API '" + oModel.getProperty("/apis/" + getCurrentScannerAPI() + "/description") + "' to scan the barcode.");
1837
1560
  return false;
1838
- } else if (scannerAPI === "ZXing" || scannerAPI === "ZXingCPP") {
1561
+ } else if (scannerAPI === "ZXingCPP") {
1839
1562
  if (isScannerAPIUnAvailable(scannerAPI)) {
1840
1563
  Log.error("BarcodeScanner.scan: The scanner API '" + scannerAPI + "' is unavailable, will use current scanner API '" + oModel.getProperty("/apis/" + getCurrentScannerAPI() + "/description") + "' to scan the barcode.");
1841
1564
  return false;