@iotize/device-com-nfc.cordova 3.1.3 → 3.1.6

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.
@@ -72,7 +72,7 @@
72
72
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
73
73
  return Reflect.metadata(metadataKey, metadataValue);
74
74
  }
75
- function __awaiter(thisArg, _arguments, P, generator) {
75
+ function __awaiter$1(thisArg, _arguments, P, generator) {
76
76
  return new (P || (P = Promise))(function (resolve, reject) {
77
77
  function fulfilled(value) { try {
78
78
  step(generator.next(value));
@@ -281,6 +281,9 @@
281
281
  NfcError.unknownError = function (errString) {
282
282
  throw new NfcError(NfcError.ErrorCode.Unknown, errString);
283
283
  };
284
+ NfcError.tagConnectionFailed = function () {
285
+ throw new NfcError(NfcError.ErrorCode.NotConnectedError, "Tag connection failed");
286
+ };
284
287
  NfcError.internalError = function (message) {
285
288
  throw new NfcError(NfcError.ErrorCode.InternalError, message);
286
289
  };
@@ -298,78 +301,165 @@
298
301
 
299
302
  var debug = debug$1.createDebugger("@iotize/device-com-nfc.cordova");
300
303
 
304
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
305
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
306
+ return new (P || (P = Promise))(function (resolve, reject) {
307
+ function fulfilled(value) { try {
308
+ step(generator.next(value));
309
+ }
310
+ catch (e) {
311
+ reject(e);
312
+ } }
313
+ function rejected(value) { try {
314
+ step(generator["throw"](value));
315
+ }
316
+ catch (e) {
317
+ reject(e);
318
+ } }
319
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
320
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
321
+ });
322
+ };
301
323
  var NFCComProtocol = /** @class */ (function (_super) {
302
324
  __extends(NFCComProtocol, _super);
303
325
  function NFCComProtocol(options) {
304
326
  if (options === void 0) { options = {
305
327
  connect: {
306
- timeout: 2000
328
+ timeout: 2000,
307
329
  },
308
330
  disconnect: {
309
- timeout: 1000
331
+ timeout: 1000,
310
332
  },
311
333
  send: {
312
- timeout: 1000
313
- }
334
+ timeout: 1000,
335
+ },
314
336
  }; }
315
337
  var _this = _super.call(this) || this;
316
338
  _this.options = options;
317
339
  if (typeof nfc == undefined) {
318
- console.warn("NFC plugin has not been setup properly. Global variable NFC does not exist");
340
+ console.warn('NFC plugin has not been setup properly. Global variable NFC does not exist');
319
341
  }
320
342
  return _this;
321
343
  }
322
344
  NFCComProtocol.iOSProtocol = function () {
323
345
  return new NFCComProtocol({
324
346
  connect: {
325
- timeout: 10000 // bigger timer on connect as connect launches a reading session
347
+ timeout: 10000, // bigger timer on connect as connect launches a reading session
326
348
  },
327
349
  disconnect: {
328
- timeout: 1000
350
+ timeout: 1000,
329
351
  },
330
352
  send: {
331
- timeout: 1000
332
- }
353
+ timeout: 1000,
354
+ },
333
355
  });
334
356
  };
357
+ /**
358
+ * We force tag connection with nfc as we need to refresh tag
359
+ * @param options
360
+ * @returns
361
+ */
362
+ NFCComProtocol.prototype.connect = function (options) {
363
+ this.connectionState = api.ConnectionState.CONNECTING; // Hack to force NFC tag connect call even if we are already connected
364
+ return _super.prototype.connect.call(this, options);
365
+ };
366
+ /**
367
+ * Not used as we have rewrote "connect()" function
368
+ * @param options
369
+ * @returns
370
+ */
335
371
  NFCComProtocol.prototype._connect = function (options) {
336
- debug('_connect', options);
337
- var connectPromise = nfc.connect("android.nfc.tech.NfcV", this.options.connect.timeout);
338
- return rxjs.from(connectPromise);
372
+ var _this = this;
373
+ return rxjs.defer(function () { return __awaiter(_this, void 0, void 0, function () {
374
+ var err_1;
375
+ return __generator(this, function (_a) {
376
+ switch (_a.label) {
377
+ case 0:
378
+ debug('_connect', options);
379
+ _a.label = 1;
380
+ case 1:
381
+ _a.trys.push([1, 3, , 4]);
382
+ return [4 /*yield*/, nfc.connect('android.nfc.tech.NfcV', this.options.connect.timeout)];
383
+ case 2:
384
+ _a.sent();
385
+ return [3 /*break*/, 4];
386
+ case 3:
387
+ err_1 = _a.sent();
388
+ if (typeof err_1 === 'string') {
389
+ if (err_1 === 'Tag connection failed') {
390
+ throw exports.NfcError.tagConnectionFailed();
391
+ }
392
+ else {
393
+ throw exports.NfcError.unknownError(err_1);
394
+ }
395
+ }
396
+ throw err_1;
397
+ case 4: return [2 /*return*/];
398
+ }
399
+ });
400
+ }); });
339
401
  };
340
402
  NFCComProtocol.prototype._disconnect = function (options) {
341
- return rxjs.from(nfc.close());
403
+ return rxjs.defer(function () { return nfc.close(); });
342
404
  };
405
+ /**
406
+ * Not used
407
+ * @param options
408
+ * @returns
409
+ */
343
410
  NFCComProtocol.prototype.write = function (data) {
344
- throw new Error("Method not implemented.");
411
+ return __awaiter(this, void 0, void 0, function () {
412
+ return __generator(this, function (_a) {
413
+ throw new Error('Method not implemented.');
414
+ });
415
+ });
345
416
  };
417
+ /**
418
+ * Not used
419
+ * @param options
420
+ * @returns
421
+ */
346
422
  NFCComProtocol.prototype.read = function () {
347
- throw new Error("Method not implemented.");
423
+ return __awaiter(this, void 0, void 0, function () {
424
+ return __generator(this, function (_a) {
425
+ throw new Error('Method not implemented.');
426
+ });
427
+ });
348
428
  };
349
429
  NFCComProtocol.prototype.send = function (data, options) {
350
430
  var _this = this;
351
- var promise = nfc
352
- .transceive(byteConverter.bufferToHexString(data))
353
- .then(function (response) {
354
- if (typeof response != "string") {
355
- throw exports.NfcError.internalError("Internal error. Plugin should respond a hexadecimal string");
356
- }
357
- debug('NFC plugin response: ', response);
358
- return byteConverter.hexStringToBuffer(response);
359
- })
360
- .catch(function (errString) {
361
- if (typeof errString === "string") {
362
- var error = stringToError(errString);
363
- if (error.code === exports.NfcError.ErrorCode.NotConnectedError || error.code === exports.NfcError.ErrorCode.TagLostError) {
364
- _this._onConnectionLost(error);
431
+ return rxjs.defer(function () { return __awaiter(_this, void 0, void 0, function () {
432
+ var response, errString_1, error;
433
+ return __generator(this, function (_a) {
434
+ switch (_a.label) {
435
+ case 0:
436
+ _a.trys.push([0, 2, , 3]);
437
+ return [4 /*yield*/, nfc.transceive(byteConverter.bufferToHexString(data))];
438
+ case 1:
439
+ response = _a.sent();
440
+ if (typeof response != 'string') {
441
+ throw exports.NfcError.internalError("Internal error. Plugin should respond a hexadecimal string");
442
+ }
443
+ debug('NFC plugin response: ', response);
444
+ return [2 /*return*/, byteConverter.hexStringToBuffer(response)];
445
+ case 2:
446
+ errString_1 = _a.sent();
447
+ if (typeof errString_1 === 'string') {
448
+ error = stringToError(errString_1);
449
+ if (error.code === exports.NfcError.ErrorCode.NotConnectedError ||
450
+ error.code === exports.NfcError.ErrorCode.TagLostError) {
451
+ this._onConnectionLost(error);
452
+ }
453
+ throw error;
454
+ }
455
+ else {
456
+ throw errString_1;
457
+ }
458
+ return [3 /*break*/, 3];
459
+ case 3: return [2 /*return*/];
365
460
  }
366
- throw error;
367
- }
368
- else {
369
- throw errString;
370
- }
371
- });
372
- return rxjs.from(promise);
461
+ });
462
+ }); });
373
463
  };
374
464
  NFCComProtocol.prototype._onConnectionLost = function (error) {
375
465
  if (this.connectionState !== api.ConnectionState.DISCONNECTED) {
@@ -378,7 +468,6 @@
378
468
  };
379
469
  return NFCComProtocol;
380
470
  }(core.QueueComProtocol));
381
- ;
382
471
  /**
383
472
  * Convert error string returned by the plugin into an error object
384
473
  * It only checks a few Android error string for now
@@ -1 +1 @@
1
- {"version":3,"file":"iotize-device-com-nfc.cordova.umd.js","sources":["../../../../node_modules/tslib/tslib.es6.js","../../../../src/www/errors.ts","../../../../src/www/logger.ts","../../../../src/www/nfc-com-protocol.ts","../../../../src/www/tap-ndef/parse-ndef-message.ts","../../../../src/iotize-device-com-nfc.cordova.ts"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation. All rights reserved.\r\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use\r\nthis file except in compliance with the License. You may obtain a copy of the\r\nLicense at http://www.apache.org/licenses/LICENSE-2.0\r\n\r\nTHIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r\nKIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED\r\nWARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,\r\nMERCHANTABLITY OR NON-INFRINGEMENT.\r\n\r\nSee the Apache Version 2.0 License for specific language governing permissions\r\nand limitations under the License.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)\r\n t[p[i]] = s[p[i]];\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport function __exportStar(m, exports) {\r\n for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];\r\n}\r\n\r\nexport function __values(o) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator], i = 0;\r\n if (m) return m.call(o);\r\n return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];\r\n result.default = mod;\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n","export class NfcError extends Error {\r\n\r\n constructor(public code: NfcError.ErrorCode, message: string){\r\n super(message);\r\n }\r\n\r\n public static tagLostError(){\r\n return new NfcError(\r\n NfcError.ErrorCode.TagLostError,\r\n 'NFC tag lost'\r\n );\r\n }\r\n\r\n public static notConnectedError(){\r\n return new NfcError(\r\n NfcError.ErrorCode.NotConnectedError,\r\n 'NFC tag is not connected'\r\n );\r\n } \r\n\r\n public static unknownError(errString: string): NfcError {\r\n throw new NfcError(\r\n NfcError.ErrorCode.Unknown,\r\n errString\r\n )\r\n }\r\n \r\n public static internalError(message: string) {\r\n throw new NfcError(\r\n NfcError.ErrorCode.InternalError,\r\n message\r\n )\r\n }\r\n}\r\n\r\nexport namespace NfcError {\r\n export enum ErrorCode {\r\n Unknown = \"NfcUnknownError\",\r\n InternalError = \"NfcInternalError\",\r\n TagLostError = \"NfcTagLostError\",\r\n NotConnectedError = \"NfcNotConnectedError\"\r\n }\r\n}","import { createDebugger } from '@iotize/common/debug';\r\n\r\nexport const debug = createDebugger(`@iotize/device-com-nfc.cordova`);","//\r\n// Copyright 2018 IoTize SAS Inc. Licensed under the MIT license. \r\n//\r\n// ble-com-protocol.ts\r\n// device-com-ble.cordova BLE Cordova Plugin\r\n//\r\nimport { bufferToHexString, hexStringToBuffer } from '@iotize/common/byte-converter';\r\nimport {\r\n ComProtocolConnectOptions,\r\n ComProtocolDisconnectOptions,\r\n ComProtocolOptions,\r\n ComProtocolSendOptions,\r\n ConnectionState,\r\n} from '@iotize/tap/protocol/api';\r\nimport { QueueComProtocol } from '@iotize/tap/protocol/core';\r\nimport { from, Observable } from 'rxjs';\r\n\r\nimport { CordovaInterface } from './cordova-interface';\r\nimport { NfcError } from './errors';\r\nimport { debug } from './logger';\r\n\r\n\r\ndeclare var nfc: CordovaInterface;\r\n\r\nexport class NFCComProtocol extends QueueComProtocol {\r\n\r\n constructor(options: ComProtocolOptions = {\r\n connect: {\r\n timeout: 2000\r\n },\r\n disconnect: {\r\n timeout: 1000\r\n },\r\n send: {\r\n timeout: 1000\r\n }\r\n }) {\r\n super();\r\n this.options = options;\r\n if (typeof nfc == undefined) {\r\n console.warn(\"NFC plugin has not been setup properly. Global variable NFC does not exist\");\r\n }\r\n }\r\n\r\n public static iOSProtocol(): NFCComProtocol {\r\n return new NFCComProtocol({\r\n connect: {\r\n timeout: 10000 // bigger timer on connect as connect launches a reading session\r\n },\r\n disconnect: {\r\n timeout: 1000\r\n },\r\n send: {\r\n timeout: 1000\r\n }\r\n })\r\n }\r\n\r\n _connect(options?: ComProtocolConnectOptions): Observable<any> {\r\n debug('_connect', options);\r\n const connectPromise = nfc.connect(\"android.nfc.tech.NfcV\", this.options.connect.timeout)\r\n return from(connectPromise);\r\n }\r\n\r\n _disconnect(options?: ComProtocolDisconnectOptions): Observable<any> {\r\n return from(nfc.close());\r\n }\r\n\r\n write(data: Uint8Array): Promise<any> {\r\n throw new Error(\"Method not implemented.\");\r\n }\r\n\r\n read(): Promise<Uint8Array> {\r\n throw new Error(\"Method not implemented.\");\r\n }\r\n\r\n send(data: Uint8Array, options?: ComProtocolSendOptions): Observable<Uint8Array> {\r\n const promise = nfc\r\n .transceive(bufferToHexString(data))\r\n .then((response: string) => {\r\n if (typeof response != \"string\") {\r\n throw NfcError.internalError(`Internal error. Plugin should respond a hexadecimal string`);\r\n }\r\n debug('NFC plugin response: ', response)\r\n return hexStringToBuffer(response)\r\n })\r\n .catch((errString) => {\r\n if (typeof errString === \"string\") {\r\n const error = stringToError(errString);\r\n if (error.code === NfcError.ErrorCode.NotConnectedError || error.code === NfcError.ErrorCode.TagLostError) {\r\n this._onConnectionLost(error);\r\n }\r\n throw error;\r\n }\r\n else {\r\n throw errString;\r\n }\r\n });\r\n return from(promise);\r\n }\r\n\r\n _onConnectionLost(error: NfcError) {\r\n if (this.connectionState !== ConnectionState.DISCONNECTED) {\r\n this.setConnectionState(ConnectionState.DISCONNECTED);\r\n }\r\n }\r\n\r\n};\r\n\r\n/**\r\n * Convert error string returned by the plugin into an error object\r\n * It only checks a few Android error string for now\r\n * \r\n * TODO complete implementation with other error types\r\n * \r\n * @param errString \r\n */\r\nfunction stringToError(errString: string): NfcError {\r\n const errStringLc = errString.toLowerCase();\r\n if (errStringLc.indexOf('tag was lost') >= 0) {\r\n return NfcError.tagLostError();\r\n }\r\n else if (errStringLc.indexOf('not connected') >= 0) {\r\n return NfcError.notConnectedError();\r\n }\r\n else {\r\n return NfcError.unknownError(errString);\r\n }\r\n}\r\n","import { bufferToAsciiString } from '@iotize/common/byte-converter';\r\n\r\nimport { NdefRecord, TapNfcTagPayload } from './definitions';\r\n\r\n/**\r\n * We manage only on NDEF message with 3 records:\r\n * record 0 = URI; record 1 = AAR; record 2 = BLE MAC ADDRESS / BSSID; record 3: universal link\r\n */\r\nexport function parseTapNdefMessage(messages: NdefRecord[]): TapNfcTagPayload {\r\n let result: TapNfcTagPayload = {};\r\n if (messages.length >= 1) {\r\n let asciiUri = messages[0].payload;\r\n result.uri = toAsciiString(asciiUri);\r\n }\r\n if (messages.length >= 2) {\r\n result.aar = toAsciiString(messages[1].payload);\r\n }\r\n if (messages.length >= 3) {\r\n let payload3 = messages[2].payload;\r\n let type = payload3[0];\r\n let content = payload3.slice(1);\r\n result.type = type;\r\n\r\n switch (type) {\r\n case TapNdefProtocolType.BLE:\r\n result.macAddress = convertBytesToBLEAddress(content);\r\n break;\r\n case TapNdefProtocolType.WiFi:\r\n result.ssid = toAsciiString(content);\r\n break;\r\n }\r\n }\r\n if (messages.length >= 4) {\r\n result.name = toAsciiString(messages[3].payload);\r\n }\r\n return result;\r\n}\r\n\r\nenum TapNdefProtocolType {\r\n WiFi = 0x20,\r\n BLE = 0x40\r\n}\r\n\r\nfunction toAsciiString(payload: number[]): string {\r\n if (payload.length > 0 && payload[0] === 0) {\r\n payload = payload.slice(1);\r\n }\r\n return bufferToAsciiString(payload as any as Uint8Array);\r\n}\r\n\r\nfunction convertBytesToBLEAddress(bytes: number[]): string {\r\n return bytes.map(byte => {\r\n if (byte < 0) {\r\n byte += 256;\r\n }\r\n let byteString = '0' + byte.toString(16).toUpperCase();\r\n byteString = byteString.slice(-2);\r\n return byteString;\r\n })\r\n .reverse()\r\n .join(':')\r\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":["NfcError","createDebugger","from","bufferToHexString","hexStringToBuffer","ConnectionState","QueueComProtocol","bufferToAsciiString"],"mappings":";;;;;;IAAA;;;;;;;;;;;;;;IAcA;IAEA,IAAI,aAAa,GAAG,UAAS,CAAC,EAAE,CAAC;QAC7B,aAAa,GAAG,MAAM,CAAC,cAAc;aAChC,EAAE,SAAS,EAAE,EAAE,EAAE,YAAY,KAAK,IAAI,UAAU,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,EAAE,CAAC;YAC5E,UAAU,CAAC,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC;gBAAE,IAAI,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;oBAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/E,OAAO,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC/B,CAAC,CAAC;aAEc,SAAS,CAAC,CAAC,EAAE,CAAC;QAC1B,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACpB,SAAS,EAAE,KAAK,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC,EAAE;QACvC,CAAC,CAAC,SAAS,GAAG,CAAC,KAAK,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC,C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D,IAAI,QAAQ,CAAC,MAAM,IAAI,CAAC,EAAE;YACtB,MAAM,CAAC,IAAI,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;SACpD;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,IAAK,mBAGJ;IAHD,WAAK,mBAAmB;QACpB,8DAAW,CAAA;QACX,4DAAU,CAAA;IACd,CAAC,EAHI,mBAAmB,KAAnB,mBAAmB,QAGvB;IAED,SAAS,aAAa,CAAC,OAAiB;QACpC,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE;YACxC,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SAC9B;QACD,OAAOO,iCAAmB,CAAC,OAA4B,CAAC,CAAC;IAC7D,CAAC;IAED,SAAS,wBAAwB,CAAC,KAAe;QAC7C,OAAO,KAAK,CAAC,GAAG,CAAC,UAAA,IAAI;YACjB,IAAI,IAAI,GAAG,CAAC,EAAE;gBACV,IAAI,IAAI,GAAG,CAAC;aACf;YACD,IAAI,UAAU,GAAG,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;YACvD,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YAClC,OAAO,UAAU,CAAC;SACrB,CAAC;aACG,OAAO,EAAE;aACT,IAAI,CAAC,GAAG,CAAC,CAAA;IAClB;;IC7DA;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"iotize-device-com-nfc.cordova.umd.js","sources":["../../../../node_modules/tslib/tslib.es6.js","../../../../src/www/errors.ts","../../../../src/www/logger.ts","../../../../src/www/nfc-com-protocol.ts","../../../../src/www/tap-ndef/parse-ndef-message.ts","../../../../src/iotize-device-com-nfc.cordova.ts"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation. All rights reserved.\r\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use\r\nthis file except in compliance with the License. You may obtain a copy of the\r\nLicense at http://www.apache.org/licenses/LICENSE-2.0\r\n\r\nTHIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r\nKIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED\r\nWARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,\r\nMERCHANTABLITY OR NON-INFRINGEMENT.\r\n\r\nSee the Apache Version 2.0 License for specific language governing permissions\r\nand limitations under the License.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)\r\n t[p[i]] = s[p[i]];\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport function __exportStar(m, exports) {\r\n for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];\r\n}\r\n\r\nexport function __values(o) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator], i = 0;\r\n if (m) return m.call(o);\r\n return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];\r\n result.default = mod;\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n","export class NfcError extends Error {\r\n constructor(public code: NfcError.ErrorCode, message: string) {\r\n super(message);\r\n }\r\n\r\n public static tagLostError() {\r\n return new NfcError(NfcError.ErrorCode.TagLostError, 'NFC tag lost');\r\n }\r\n\r\n public static notConnectedError() {\r\n return new NfcError(\r\n NfcError.ErrorCode.NotConnectedError,\r\n 'NFC tag is not connected'\r\n );\r\n }\r\n\r\n public static unknownError(errString: string): NfcError {\r\n throw new NfcError(NfcError.ErrorCode.Unknown, errString);\r\n }\r\n\r\n public static tagConnectionFailed() {\r\n throw new NfcError(\r\n NfcError.ErrorCode.NotConnectedError,\r\n `Tag connection failed`\r\n );\r\n }\r\n\r\n public static internalError(message: string) {\r\n throw new NfcError(NfcError.ErrorCode.InternalError, message);\r\n }\r\n}\r\n\r\nexport namespace NfcError {\r\n export enum ErrorCode {\r\n Unknown = 'NfcUnknownError',\r\n InternalError = 'NfcInternalError',\r\n TagLostError = 'NfcTagLostError',\r\n NotConnectedError = 'NfcNotConnectedError',\r\n }\r\n}\r\n","import { createDebugger } from '@iotize/common/debug';\r\n\r\nexport const debug = createDebugger(`@iotize/device-com-nfc.cordova`);","import {\r\n bufferToHexString,\r\n hexStringToBuffer,\r\n} from '@iotize/common/byte-converter';\r\nimport {\r\n ComProtocolConnectOptions,\r\n ComProtocolDisconnectOptions,\r\n ComProtocolOptions,\r\n ComProtocolSendOptions,\r\n ConnectionState,\r\n} from '@iotize/tap/protocol/api';\r\nimport { QueueComProtocol } from '@iotize/tap/protocol/core';\r\nimport { defer, Observable } from 'rxjs';\r\n\r\nimport { CordovaInterface } from './cordova-interface';\r\nimport { NfcError } from './errors';\r\nimport { debug } from './logger';\r\n\r\ndeclare var nfc: CordovaInterface;\r\n\r\nexport class NFCComProtocol extends QueueComProtocol {\r\n constructor(\r\n options: ComProtocolOptions = {\r\n connect: {\r\n timeout: 2000,\r\n },\r\n disconnect: {\r\n timeout: 1000,\r\n },\r\n send: {\r\n timeout: 1000,\r\n },\r\n }\r\n ) {\r\n super();\r\n this.options = options;\r\n if (typeof nfc == undefined) {\r\n console.warn(\r\n 'NFC plugin has not been setup properly. Global variable NFC does not exist'\r\n );\r\n }\r\n }\r\n\r\n public static iOSProtocol(): NFCComProtocol {\r\n return new NFCComProtocol({\r\n connect: {\r\n timeout: 10000, // bigger timer on connect as connect launches a reading session\r\n },\r\n disconnect: {\r\n timeout: 1000,\r\n },\r\n send: {\r\n timeout: 1000,\r\n },\r\n });\r\n }\r\n\r\n /**\r\n * We force tag connection with nfc as we need to refresh tag\r\n * @param options\r\n * @returns\r\n */\r\n connect(options?: ComProtocolConnectOptions): Observable<void> {\r\n this.connectionState = ConnectionState.CONNECTING; // Hack to force NFC tag connect call even if we are already connected\r\n return super.connect(options);\r\n }\r\n\r\n /**\r\n * Not used as we have rewrote \"connect()\" function\r\n * @param options\r\n * @returns\r\n */\r\n _connect(options?: ComProtocolConnectOptions): Observable<any> {\r\n return defer(async () => {\r\n debug('_connect', options);\r\n try {\r\n await nfc.connect(\r\n 'android.nfc.tech.NfcV',\r\n this.options.connect.timeout\r\n );\r\n } catch (err) {\r\n if (typeof err === 'string') {\r\n if (err === 'Tag connection failed') {\r\n throw NfcError.tagConnectionFailed();\r\n } else {\r\n throw NfcError.unknownError(err);\r\n }\r\n }\r\n throw err;\r\n }\r\n });\r\n }\r\n\r\n _disconnect(options?: ComProtocolDisconnectOptions): Observable<any> {\r\n return defer(() => nfc.close());\r\n }\r\n\r\n /**\r\n * Not used\r\n * @param options\r\n * @returns\r\n */\r\n async write(data: Uint8Array): Promise<any> {\r\n throw new Error('Method not implemented.');\r\n }\r\n\r\n /**\r\n * Not used\r\n * @param options\r\n * @returns\r\n */\r\n async read(): Promise<Uint8Array> {\r\n throw new Error('Method not implemented.');\r\n }\r\n\r\n send(\r\n data: Uint8Array,\r\n options?: ComProtocolSendOptions\r\n ): Observable<Uint8Array> {\r\n return defer(async () => {\r\n try {\r\n const response = await nfc.transceive(bufferToHexString(data));\r\n if (typeof response != 'string') {\r\n throw NfcError.internalError(\r\n `Internal error. Plugin should respond a hexadecimal string`\r\n );\r\n }\r\n debug('NFC plugin response: ', response);\r\n return hexStringToBuffer(response);\r\n } catch (errString) {\r\n if (typeof errString === 'string') {\r\n const error = stringToError(errString);\r\n if (\r\n error.code === NfcError.ErrorCode.NotConnectedError ||\r\n error.code === NfcError.ErrorCode.TagLostError\r\n ) {\r\n this._onConnectionLost(error);\r\n }\r\n throw error;\r\n } else {\r\n throw errString;\r\n }\r\n }\r\n });\r\n }\r\n\r\n _onConnectionLost(error: NfcError) {\r\n if (this.connectionState !== ConnectionState.DISCONNECTED) {\r\n this.setConnectionState(ConnectionState.DISCONNECTED);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Convert error string returned by the plugin into an error object\r\n * It only checks a few Android error string for now\r\n *\r\n * TODO complete implementation with other error types\r\n *\r\n * @param errString\r\n */\r\nfunction stringToError(errString: string): NfcError {\r\n const errStringLc = errString.toLowerCase();\r\n if (errStringLc.indexOf('tag was lost') >= 0) {\r\n return NfcError.tagLostError();\r\n } else if (errStringLc.indexOf('not connected') >= 0) {\r\n return NfcError.notConnectedError();\r\n } else {\r\n return NfcError.unknownError(errString);\r\n }\r\n}\r\n","import { bufferToAsciiString } from '@iotize/common/byte-converter';\r\n\r\nimport { NdefRecord, TapNfcTagPayload } from './definitions';\r\n\r\n/**\r\n * We manage only on NDEF message with 3 records:\r\n * record 0 = URI; record 1 = AAR; record 2 = BLE MAC ADDRESS / BSSID; record 3: universal link\r\n */\r\nexport function parseTapNdefMessage(messages: NdefRecord[]): TapNfcTagPayload {\r\n let result: TapNfcTagPayload = {};\r\n if (messages.length >= 1) {\r\n let asciiUri = messages[0].payload;\r\n result.uri = toAsciiString(asciiUri);\r\n }\r\n if (messages.length >= 2) {\r\n result.aar = toAsciiString(messages[1].payload);\r\n }\r\n if (messages.length >= 3) {\r\n let payload3 = messages[2].payload;\r\n let type = payload3[0];\r\n let content = payload3.slice(1);\r\n result.type = type;\r\n\r\n switch (type) {\r\n case TapNdefProtocolType.BLE:\r\n result.macAddress = convertBytesToBLEAddress(content);\r\n break;\r\n case TapNdefProtocolType.WiFi:\r\n result.ssid = toAsciiString(content);\r\n break;\r\n }\r\n }\r\n if (messages.length >= 4) {\r\n result.name = toAsciiString(messages[3].payload);\r\n }\r\n return result;\r\n}\r\n\r\nenum TapNdefProtocolType {\r\n WiFi = 0x20,\r\n BLE = 0x40\r\n}\r\n\r\nfunction toAsciiString(payload: number[]): string {\r\n if (payload.length > 0 && payload[0] === 0) {\r\n payload = payload.slice(1);\r\n }\r\n return bufferToAsciiString(payload as any as Uint8Array);\r\n}\r\n\r\nfunction convertBytesToBLEAddress(bytes: number[]): string {\r\n return bytes.map(byte => {\r\n if (byte < 0) {\r\n byte += 256;\r\n }\r\n let byteString = '0' + byte.toString(16).toUpperCase();\r\n byteString = byteString.slice(-2);\r\n return byteString;\r\n })\r\n .reverse()\r\n .join(':')\r\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":["__awaiter","NfcError","createDebugger","ConnectionState","defer","bufferToHexString","hexStringToBuffer","QueueComProtocol","bufferToAsciiString"],"mappings":";;;;;;IAAA;;;;;;;;;;;;;IAagF;IAChF;IAEA,IAAI,aAAa,GAAG,UAAS,CAAC,EAAE,CAAC,EAAA;QAC7B,aAAa,GAAG,MAAM,CAAC,cAAc;aAChC,EAAE,SAAS,EAAE,EAAE,EAAE,YAAY,KAAK,IAAI,UAAU,CAAC,EAAE,CAAC,EAAA,EAAI,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,E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CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE;IACxC,QAAA,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC9B,KAAA;IACD,IAAA,OAAOO,iCAAmB,CAAC,OAA4B,CAAC,CAAC;IAC7D,CAAC;IAED,SAAS,wBAAwB,CAAC,KAAe,EAAA;IAC7C,IAAA,OAAO,KAAK,CAAC,GAAG,CAAC,UAAA,IAAI,EAAA;YACjB,IAAI,IAAI,GAAG,CAAC,EAAE;gBACV,IAAI,IAAI,GAAG,CAAC;IACf,SAAA;IACD,QAAA,IAAI,UAAU,GAAG,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;YACvD,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAClC,QAAA,OAAO,UAAU,CAAC;IACtB,KAAC,CAAC;IACG,SAAA,OAAO,EAAE;aACT,IAAI,CAAC,GAAG,CAAC,CAAA;IAClB;;IC7DA;;IAEG;;;;;;;;;;;"}
@@ -1,4 +1,4 @@
1
- !function(o,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@iotize/common/byte-converter"),require("@iotize/tap/protocol/api"),require("@iotize/tap/protocol/core"),require("rxjs"),require("@iotize/common/debug")):"function"==typeof define&&define.amd?define("@iotize/device-com-nfc.cordova",["exports","@iotize/common/byte-converter","@iotize/tap/protocol/api","@iotize/tap/protocol/core","rxjs","@iotize/common/debug"],r):r(((o="undefined"!=typeof globalThis?globalThis:o||self).iotize=o.iotize||{},o.iotize["device-com-nfc"]=o.iotize["device-com-nfc"]||{},o.iotize["device-com-nfc"].cordova={}),o.byteConverter,o.api,o.core,o.rxjs,o.debug$1)}(this,(function(o,r,e,t,n,i){"use strict";
1
+ !function(o,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@iotize/common/byte-converter"),require("@iotize/tap/protocol/api"),require("@iotize/tap/protocol/core"),require("rxjs"),require("@iotize/common/debug")):"function"==typeof define&&define.amd?define("@iotize/device-com-nfc.cordova",["exports","@iotize/common/byte-converter","@iotize/tap/protocol/api","@iotize/tap/protocol/core","rxjs","@iotize/common/debug"],e):e(((o="undefined"!=typeof globalThis?globalThis:o||self).iotize=o.iotize||{},o.iotize["device-com-nfc"]=o.iotize["device-com-nfc"]||{},o.iotize["device-com-nfc"].cordova={}),o.byteConverter,o.api,o.core,o.rxjs,o.debug$1)}(this,(function(o,e,r,t,n,i){"use strict";
2
2
  /*! *****************************************************************************
3
3
  Copyright (c) Microsoft Corporation. All rights reserved.
4
4
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use
@@ -12,5 +12,5 @@
12
12
 
13
13
  See the Apache Version 2.0 License for specific language governing permissions
14
14
  and limitations under the License.
15
- ***************************************************************************** */var c=function(o,r){return(c=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(o,r){o.__proto__=r}||function(o,r){for(var e in r)r.hasOwnProperty(e)&&(o[e]=r[e])})(o,r)};function a(o,r){function e(){this.constructor=o}c(o,r),o.prototype=null===r?Object.create(r):(e.prototype=r.prototype,new e)}var f,u;o.NfcError=function(o){function r(r,e){var t=o.call(this,e)||this;return t.code=r,t}return a(r,o),r.tagLostError=function(){return new r(r.ErrorCode.TagLostError,"NFC tag lost")},r.notConnectedError=function(){return new r(r.ErrorCode.NotConnectedError,"NFC tag is not connected")},r.unknownError=function(o){throw new r(r.ErrorCode.Unknown,o)},r.internalError=function(o){throw new r(r.ErrorCode.InternalError,o)},r}(Error),u=o.NfcError||(o.NfcError={}),(f=u.ErrorCode||(u.ErrorCode={})).Unknown="NfcUnknownError",f.InternalError="NfcInternalError",f.TagLostError="NfcTagLostError",f.NotConnectedError="NfcNotConnectedError";var s,d=i.createDebugger("@iotize/device-com-nfc.cordova"),p=function(t){function i(o){void 0===o&&(o={connect:{timeout:2e3},disconnect:{timeout:1e3},send:{timeout:1e3}});var r=t.call(this)||this;return r.options=o,null==typeof nfc&&console.warn("NFC plugin has not been setup properly. Global variable NFC does not exist"),r}return a(i,t),i.iOSProtocol=function(){return new i({connect:{timeout:1e4},disconnect:{timeout:1e3},send:{timeout:1e3}})},i.prototype._connect=function(o){d("_connect",o);var r=nfc.connect("android.nfc.tech.NfcV",this.options.connect.timeout);return n.from(r)},i.prototype._disconnect=function(o){return n.from(nfc.close())},i.prototype.write=function(o){throw new Error("Method not implemented.")},i.prototype.read=function(){throw new Error("Method not implemented.")},i.prototype.send=function(e,t){var i=this,c=nfc.transceive(r.bufferToHexString(e)).then((function(e){if("string"!=typeof e)throw o.NfcError.internalError("Internal error. Plugin should respond a hexadecimal string");return d("NFC plugin response: ",e),r.hexStringToBuffer(e)})).catch((function(r){if("string"==typeof r){var e=function(r){var e=r.toLowerCase();return e.indexOf("tag was lost")>=0?o.NfcError.tagLostError():e.indexOf("not connected")>=0?o.NfcError.notConnectedError():o.NfcError.unknownError(r)}(r);throw e.code!==o.NfcError.ErrorCode.NotConnectedError&&e.code!==o.NfcError.ErrorCode.TagLostError||i._onConnectionLost(e),e}throw r}));return n.from(c)},i.prototype._onConnectionLost=function(o){this.connectionState!==e.ConnectionState.DISCONNECTED&&this.setConnectionState(e.ConnectionState.DISCONNECTED)},i}(t.QueueComProtocol);function l(o){return o.length>0&&0===o[0]&&(o=o.slice(1)),r.bufferToAsciiString(o)}!function(o){o[o.WiFi=32]="WiFi",o[o.BLE=64]="BLE"}(s||(s={})),o.NFCComProtocol=p,o.parseTapNdefMessage=function(o){var r={};if(o.length>=1){var e=o[0].payload;r.uri=l(e)}if(o.length>=2&&(r.aar=l(o[1].payload)),o.length>=3){var t=o[2].payload,n=t[0],i=t.slice(1);switch(r.type=n,n){case s.BLE:r.macAddress=i.map((function(o){o<0&&(o+=256);var r="0"+o.toString(16).toUpperCase();return r=r.slice(-2)})).reverse().join(":");break;case s.WiFi:r.ssid=l(i)}}return o.length>=4&&(r.name=l(o[3].payload)),r},Object.defineProperty(o,"__esModule",{value:!0})}));
15
+ ***************************************************************************** */var c=function(o,e){return(c=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(o,e){o.__proto__=e}||function(o,e){for(var r in e)e.hasOwnProperty(r)&&(o[r]=e[r])})(o,e)};function a(o,e){function r(){this.constructor=o}c(o,e),o.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var u,s;function f(o,e){var r,t,n,i,c={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;c;)try{if(r=1,t&&(n=2&i[0]?t.return:i[0]?t.throw||((n=t.return)&&n.call(t),0):t.next)&&!(n=n.call(t,i[1])).done)return n;switch(t=0,n&&(i=[2&i[0],n.value]),i[0]){case 0:case 1:n=i;break;case 4:return c.label++,{value:i[1],done:!1};case 5:c.label++,t=i[1],i=[0];continue;case 7:i=c.ops.pop(),c.trys.pop();continue;default:if(!(n=c.trys,(n=n.length>0&&n[n.length-1])||6!==i[0]&&2!==i[0])){c=0;continue}if(3===i[0]&&(!n||i[1]>n[0]&&i[1]<n[3])){c.label=i[1];break}if(6===i[0]&&c.label<n[1]){c.label=n[1],n=i;break}if(n&&c.label<n[2]){c.label=n[2],c.ops.push(i);break}n[2]&&c.ops.pop(),c.trys.pop();continue}i=e.call(o,c)}catch(o){i=[6,o],t=0}finally{r=n=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}o.NfcError=function(o){function e(e,r){var t=o.call(this,r)||this;return t.code=e,t}return a(e,o),e.tagLostError=function(){return new e(e.ErrorCode.TagLostError,"NFC tag lost")},e.notConnectedError=function(){return new e(e.ErrorCode.NotConnectedError,"NFC tag is not connected")},e.unknownError=function(o){throw new e(e.ErrorCode.Unknown,o)},e.tagConnectionFailed=function(){throw new e(e.ErrorCode.NotConnectedError,"Tag connection failed")},e.internalError=function(o){throw new e(e.ErrorCode.InternalError,o)},e}(Error),s=o.NfcError||(o.NfcError={}),(u=s.ErrorCode||(s.ErrorCode={})).Unknown="NfcUnknownError",u.InternalError="NfcInternalError",u.TagLostError="NfcTagLostError",u.NotConnectedError="NfcNotConnectedError";var l,d=i.createDebugger("@iotize/device-com-nfc.cordova"),p=this&&this.__awaiter||function(o,e,r,t){return new(r||(r=Promise))((function(n,i){function c(o){try{u(t.next(o))}catch(o){i(o)}}function a(o){try{u(t.throw(o))}catch(o){i(o)}}function u(o){var e;o.done?n(o.value):(e=o.value,e instanceof r?e:new r((function(o){o(e)}))).then(c,a)}u((t=t.apply(o,e||[])).next())}))},h=function(t){function i(o){void 0===o&&(o={connect:{timeout:2e3},disconnect:{timeout:1e3},send:{timeout:1e3}});var e=t.call(this)||this;return e.options=o,null==typeof nfc&&console.warn("NFC plugin has not been setup properly. Global variable NFC does not exist"),e}return a(i,t),i.iOSProtocol=function(){return new i({connect:{timeout:1e4},disconnect:{timeout:1e3},send:{timeout:1e3}})},i.prototype.connect=function(o){return this.connectionState=r.ConnectionState.CONNECTING,t.prototype.connect.call(this,o)},i.prototype._connect=function(e){var r=this;return n.defer((function(){return p(r,void 0,void 0,(function(){var r;return f(this,(function(t){switch(t.label){case 0:d("_connect",e),t.label=1;case 1:return t.trys.push([1,3,,4]),[4,nfc.connect("android.nfc.tech.NfcV",this.options.connect.timeout)];case 2:return t.sent(),[3,4];case 3:if("string"==typeof(r=t.sent()))throw"Tag connection failed"===r?o.NfcError.tagConnectionFailed():o.NfcError.unknownError(r);throw r;case 4:return[2]}}))}))}))},i.prototype._disconnect=function(o){return n.defer((function(){return nfc.close()}))},i.prototype.write=function(o){return p(this,void 0,void 0,(function(){return f(this,(function(o){throw new Error("Method not implemented.")}))}))},i.prototype.read=function(){return p(this,void 0,void 0,(function(){return f(this,(function(o){throw new Error("Method not implemented.")}))}))},i.prototype.send=function(r,t){var i=this;return n.defer((function(){return p(i,void 0,void 0,(function(){var t,n,i;return f(this,(function(c){switch(c.label){case 0:return c.trys.push([0,2,,3]),[4,nfc.transceive(e.bufferToHexString(r))];case 1:if("string"!=typeof(t=c.sent()))throw o.NfcError.internalError("Internal error. Plugin should respond a hexadecimal string");return d("NFC plugin response: ",t),[2,e.hexStringToBuffer(t)];case 2:throw"string"==typeof(n=c.sent())?(u=(a=n).toLowerCase(),(i=u.indexOf("tag was lost")>=0?o.NfcError.tagLostError():u.indexOf("not connected")>=0?o.NfcError.notConnectedError():o.NfcError.unknownError(a)).code!==o.NfcError.ErrorCode.NotConnectedError&&i.code!==o.NfcError.ErrorCode.TagLostError||this._onConnectionLost(i),i):n;case 3:return[2]}var a,u}))}))}))},i.prototype._onConnectionLost=function(o){this.connectionState!==r.ConnectionState.DISCONNECTED&&this.setConnectionState(r.ConnectionState.DISCONNECTED)},i}(t.QueueComProtocol);function E(o){return o.length>0&&0===o[0]&&(o=o.slice(1)),e.bufferToAsciiString(o)}!function(o){o[o.WiFi=32]="WiFi",o[o.BLE=64]="BLE"}(l||(l={})),o.NFCComProtocol=h,o.parseTapNdefMessage=function(o){var e={};if(o.length>=1){var r=o[0].payload;e.uri=E(r)}if(o.length>=2&&(e.aar=E(o[1].payload)),o.length>=3){var t=o[2].payload,n=t[0],i=t.slice(1);switch(e.type=n,n){case l.BLE:e.macAddress=i.map((function(o){o<0&&(o+=256);var e="0"+o.toString(16).toUpperCase();return e=e.slice(-2)})).reverse().join(":");break;case l.WiFi:e.ssid=E(i)}}return o.length>=4&&(e.name=E(o[3].payload)),e},Object.defineProperty(o,"__esModule",{value:!0})}));
16
16
  //# sourceMappingURL=iotize-device-com-nfc.cordova.umd.min.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../node_modules/tslib/tslib.es6.js","../../../../src/www/errors.ts","../../../../src/www/logger.ts","../../../../src/www/tap-ndef/parse-ndef-message.ts","../../../../src/www/nfc-com-protocol.ts"],"names":["extendStatics","d","b","Object","setPrototypeOf","__proto__","Array","p","hasOwnProperty","__extends","__","this","constructor","prototype","create","ErrorCode","NfcError","code","message","_this","_super","call","tagLostError","TagLostError","notConnectedError","NotConnectedError","unknownError","errString","Unknown","internalError","InternalError","Error","TapNdefProtocolType","debug","createDebugger","NFCComProtocol","options","connect","timeout","disconnect","send","undefined","nfc","console","warn","iOSProtocol","_connect","connectPromise","from","_disconnect","close","write","data","read","promise","transceive","bufferToHexString","then","response","hexStringToBuffer","catch","error","errStringLc","toLowerCase","indexOf","stringToError","_onConnectionLost","connectionState","ConnectionState","DISCONNECTED","setConnectionState","QueueComProtocol","toAsciiString","payload","length","slice","bufferToAsciiString","messages","result","asciiUri","uri","aar","payload3","type","content","BLE","macAddress","map","byte","byteString","toString","toUpperCase","reverse","join","WiFi","ssid","name"],"mappings":";;;;;;;;;;;;;;oFAgBA,IAAIA,EAAgB,SAASC,EAAGC,GAI5B,OAHAF,EAAgBG,OAAOC,gBAClB,CAAEC,UAAW,cAAgBC,OAAS,SAAUL,EAAGC,GAAKD,EAAEI,UAAYH,IACvE,SAAUD,EAAGC,GAAK,IAAK,IAAIK,KAAKL,EAAOA,EAAEM,eAAeD,KAAIN,EAAEM,GAAKL,EAAEK,MACpDN,EAAGC,aAGZO,EAAUR,EAAGC,GAEzB,SAASQ,IAAOC,KAAKC,YAAcX,EADnCD,EAAcC,EAAGC,GAEjBD,EAAEY,UAAkB,OAANX,EAAaC,OAAOW,OAAOZ,IAAMQ,EAAGG,UAAYX,EAAEW,UAAW,IAAIH,GAG5E,ICOSK,EADCC,yBAjCb,SAAAA,EAAmBC,EAA0BC,GAA7C,IAAAC,EACIC,EAAAC,KAAAV,KAAMO,IAAQP,YADCQ,EAAAF,KAAAA,WAFOR,EAAAO,EAAAI,GAMZJ,EAAAM,aAAP,WACH,OAAO,IAAIN,EACPA,EAASD,UAAUQ,aACnB,iBAIMP,EAAAQ,kBAAP,WACH,OAAO,IAAIR,EACPA,EAASD,UAAUU,kBACnB,6BAIMT,EAAAU,aAAP,SAAoBC,G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,GACJ,KAAKnD,EAAoBqD,IACrBP,EAAOQ,WAAsCF,EA0B5CG,KAAI,SAAAC,GACTA,EAAO,IACPA,GAAQ,KAEZ,IAAIC,EAAa,IAAMD,EAAKE,SAAS,IAAIC,cAEzC,OADAF,EAAaA,EAAWd,OAAO,MAG9BiB,UACAC,KAAK,KAlCE,MACJ,KAAK7D,EAAoB8D,KACrBhB,EAAOiB,KAAOvB,EAAcY,IAOxC,OAHIP,EAASH,QAAU,IACnBI,EAAOkB,KAAOxB,EAAcK,EAAS,GAAGJ,UAErCK","sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation. All rights reserved.\r\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use\r\nthis file except in compliance with the License. You may obtain a copy of the\r\nLicense at http://www.apache.org/licenses/LICENSE-2.0\r\n\r\nTHIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r\nKIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED\r\nWARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,\r\nMERCHANTABLITY OR NON-INFRINGEMENT.\r\n\r\nSee the Apache Version 2.0 License for specific language governing permissions\r\nand limitations under the License.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)\r\n t[p[i]] = s[p[i]];\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport function __exportStar(m, exports) {\r\n for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];\r\n}\r\n\r\nexport function __values(o) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator], i = 0;\r\n if (m) return m.call(o);\r\n return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];\r\n result.default = mod;\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n","export class NfcError extends Error {\r\n\r\n constructor(public code: NfcError.ErrorCode, message: string){\r\n super(message);\r\n }\r\n\r\n public static tagLostError(){\r\n return new NfcError(\r\n NfcError.ErrorCode.TagLostError,\r\n 'NFC tag lost'\r\n );\r\n }\r\n\r\n public static notConnectedError(){\r\n return new NfcError(\r\n NfcError.ErrorCode.NotConnectedError,\r\n 'NFC tag is not connected'\r\n );\r\n } \r\n\r\n public static unknownError(errString: string): NfcError {\r\n throw new NfcError(\r\n NfcError.ErrorCode.Unknown,\r\n errString\r\n )\r\n }\r\n \r\n public static internalError(message: string) {\r\n throw new NfcError(\r\n NfcError.ErrorCode.InternalError,\r\n message\r\n )\r\n }\r\n}\r\n\r\nexport namespace NfcError {\r\n export enum ErrorCode {\r\n Unknown = \"NfcUnknownError\",\r\n InternalError = \"NfcInternalError\",\r\n TagLostError = \"NfcTagLostError\",\r\n NotConnectedError = \"NfcNotConnectedError\"\r\n }\r\n}","import { createDebugger } from '@iotize/common/debug';\r\n\r\nexport const debug = createDebugger(`@iotize/device-com-nfc.cordova`);","import { bufferToAsciiString } from '@iotize/common/byte-converter';\r\n\r\nimport { NdefRecord, TapNfcTagPayload } from './definitions';\r\n\r\n/**\r\n * We manage only on NDEF message with 3 records:\r\n * record 0 = URI; record 1 = AAR; record 2 = BLE MAC ADDRESS / BSSID; record 3: universal link\r\n */\r\nexport function parseTapNdefMessage(messages: NdefRecord[]): TapNfcTagPayload {\r\n let result: TapNfcTagPayload = {};\r\n if (messages.length >= 1) {\r\n let asciiUri = messages[0].payload;\r\n result.uri = toAsciiString(asciiUri);\r\n }\r\n if (messages.length >= 2) {\r\n result.aar = toAsciiString(messages[1].payload);\r\n }\r\n if (messages.length >= 3) {\r\n let payload3 = messages[2].payload;\r\n let type = payload3[0];\r\n let content = payload3.slice(1);\r\n result.type = type;\r\n\r\n switch (type) {\r\n case TapNdefProtocolType.BLE:\r\n result.macAddress = convertBytesToBLEAddress(content);\r\n break;\r\n case TapNdefProtocolType.WiFi:\r\n result.ssid = toAsciiString(content);\r\n break;\r\n }\r\n }\r\n if (messages.length >= 4) {\r\n result.name = toAsciiString(messages[3].payload);\r\n }\r\n return result;\r\n}\r\n\r\nenum TapNdefProtocolType {\r\n WiFi = 0x20,\r\n BLE = 0x40\r\n}\r\n\r\nfunction toAsciiString(payload: number[]): string {\r\n if (payload.length > 0 && payload[0] === 0) {\r\n payload = payload.slice(1);\r\n }\r\n return bufferToAsciiString(payload as any as Uint8Array);\r\n}\r\n\r\nfunction convertBytesToBLEAddress(bytes: number[]): string {\r\n return bytes.map(byte => {\r\n if (byte < 0) {\r\n byte += 256;\r\n }\r\n let byteString = '0' + byte.toString(16).toUpperCase();\r\n byteString = byteString.slice(-2);\r\n return byteString;\r\n })\r\n .reverse()\r\n .join(':')\r\n}","//\r\n// Copyright 2018 IoTize SAS Inc. Licensed under the MIT license. \r\n//\r\n// ble-com-protocol.ts\r\n// device-com-ble.cordova BLE Cordova Plugin\r\n//\r\nimport { bufferToHexString, hexStringToBuffer } from '@iotize/common/byte-converter';\r\nimport {\r\n ComProtocolConnectOptions,\r\n ComProtocolDisconnectOptions,\r\n ComProtocolOptions,\r\n ComProtocolSendOptions,\r\n ConnectionState,\r\n} from '@iotize/tap/protocol/api';\r\nimport { QueueComProtocol } from '@iotize/tap/protocol/core';\r\nimport { from, Observable } from 'rxjs';\r\n\r\nimport { CordovaInterface } from './cordova-interface';\r\nimport { NfcError } from './errors';\r\nimport { debug } from './logger';\r\n\r\n\r\ndeclare var nfc: CordovaInterface;\r\n\r\nexport class NFCComProtocol extends QueueComProtocol {\r\n\r\n constructor(options: ComProtocolOptions = {\r\n connect: {\r\n timeout: 2000\r\n },\r\n disconnect: {\r\n timeout: 1000\r\n },\r\n send: {\r\n timeout: 1000\r\n }\r\n }) {\r\n super();\r\n this.options = options;\r\n if (typeof nfc == undefined) {\r\n console.warn(\"NFC plugin has not been setup properly. Global variable NFC does not exist\");\r\n }\r\n }\r\n\r\n public static iOSProtocol(): NFCComProtocol {\r\n return new NFCComProtocol({\r\n connect: {\r\n timeout: 10000 // bigger timer on connect as connect launches a reading session\r\n },\r\n disconnect: {\r\n timeout: 1000\r\n },\r\n send: {\r\n timeout: 1000\r\n }\r\n })\r\n }\r\n\r\n _connect(options?: ComProtocolConnectOptions): Observable<any> {\r\n debug('_connect', options);\r\n const connectPromise = nfc.connect(\"android.nfc.tech.NfcV\", this.options.connect.timeout)\r\n return from(connectPromise);\r\n }\r\n\r\n _disconnect(options?: ComProtocolDisconnectOptions): Observable<any> {\r\n return from(nfc.close());\r\n }\r\n\r\n write(data: Uint8Array): Promise<any> {\r\n throw new Error(\"Method not implemented.\");\r\n }\r\n\r\n read(): Promise<Uint8Array> {\r\n throw new Error(\"Method not implemented.\");\r\n }\r\n\r\n send(data: Uint8Array, options?: ComProtocolSendOptions): Observable<Uint8Array> {\r\n const promise = nfc\r\n .transceive(bufferToHexString(data))\r\n .then((response: string) => {\r\n if (typeof response != \"string\") {\r\n throw NfcError.internalError(`Internal error. Plugin should respond a hexadecimal string`);\r\n }\r\n debug('NFC plugin response: ', response)\r\n return hexStringToBuffer(response)\r\n })\r\n .catch((errString) => {\r\n if (typeof errString === \"string\") {\r\n const error = stringToError(errString);\r\n if (error.code === NfcError.ErrorCode.NotConnectedError || error.code === NfcError.ErrorCode.TagLostError) {\r\n this._onConnectionLost(error);\r\n }\r\n throw error;\r\n }\r\n else {\r\n throw errString;\r\n }\r\n });\r\n return from(promise);\r\n }\r\n\r\n _onConnectionLost(error: NfcError) {\r\n if (this.connectionState !== ConnectionState.DISCONNECTED) {\r\n this.setConnectionState(ConnectionState.DISCONNECTED);\r\n }\r\n }\r\n\r\n};\r\n\r\n/**\r\n * Convert error string returned by the plugin into an error object\r\n * It only checks a few Android error string for now\r\n * \r\n * TODO complete implementation with other error types\r\n * \r\n * @param errString \r\n */\r\nfunction stringToError(errString: string): NfcError {\r\n const errStringLc = errString.toLowerCase();\r\n if (errStringLc.indexOf('tag was lost') >= 0) {\r\n return NfcError.tagLostError();\r\n }\r\n else if (errStringLc.indexOf('not connected') >= 0) {\r\n return NfcError.notConnectedError();\r\n }\r\n else {\r\n return NfcError.unknownError(errString);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"sources":["../../../../node_modules/tslib/tslib.es6.js","../../../../src/www/errors.ts","../../../../src/www/logger.ts","../../../../src/www/tap-ndef/parse-ndef-message.ts","../../../../src/www/nfc-com-protocol.ts"],"names":["extendStatics","d","b","Object","setPrototypeOf","__proto__","Array","p","hasOwnProperty","__extends","__","this","constructor","prototype","create","ErrorCode","NfcError","__generator","thisArg","body","f","y","t","g","_","label","sent","trys","ops","next","verb","throw","return","Symbol","iterator","n","v","op","TypeError","call","done","value","pop","length","push","e","step","_super","code","message","_this","tagLostError","TagLostError","notConnectedError","NotConnectedError","unknownError","errString","Unknown","tagConnectionFailed","internalError","InternalError","Error","TapNdefProtocolType","debug","createDebugger","NFCComProtocol","options","connect","timeout","disconnect","send","undefined","nfc","console","warn","iOSProtocol","connectionState","ConnectionState","CONNECTING","_connect","defer","__awaiter","_a","err_1","_disconnect","close","write","data","read","transceive","bufferToHexString","response","hexStringToBuffer","errStringLc","errString_1","toLowerCase","error","indexOf","_onConnectionLost","DISCONNECTED","setConnectionState","QueueComProtocol","toAsciiString","payload","slice","bufferToAsciiString","messages","result","asciiUri","uri","aar","payload3","type","content","BLE","macAddress","map","byte","byteString","toString","toUpperCase","reverse","join","WiFi","ssid","name"],"mappings":";;;;;;;;;;;;;;oFAgBA,IAAIA,EAAgB,SAASC,EAAGC,GAI5B,OAHAF,EAAgBG,OAAOC,gBAClB,CAAEC,UAAW,cAAgBC,OAAS,SAAUL,EAAGC,GAAKD,EAAEI,UAAYH,IACvE,SAAUD,EAAGC,GAAK,IAAK,IAAIK,KAAKL,EAAOA,EAAEM,eAAeD,KAAIN,EAAEM,GAAKL,EAAEK,MACpDN,EAAGC,IAGZ,SAAAO,EAAUR,EAAGC,GAEzB,SAASQ,IAAOC,KAAKC,YAAcX,EADnCD,EAAcC,EAAGC,GAEjBD,EAAEY,UAAkB,OAANX,EAAaC,OAAOW,OAAOZ,IAAMQ,EAAGG,UAAYX,EAAEW,UAAW,IAAIH,GAG5E,ICIOK,EADGC,ED0CD,SAAAC,EAAYC,EAASC,GACjC,IAAsGC,EAAGC,EAAGC,EAAGC,EAA3GC,EAAI,CAAEC,MAAO,EAAGC,KAAM,WAAa,GAAW,EAAPJ,EAAE,GAAQ,MAAMA,EAAE,GAAI,OAAOA,EAAE,IAAOK,KAAM,GAAIC,IAAK,IAChG,OAAOL,EAAI,CAAEM,KAAMC,EAAK,GAAIC,MAASD,EAAK,GAAIE,OAAUF,EAAK,IAAwB,mBAAXG,SAA0BV,EAAEU,OAAOC,UAAY,WAAa,OAAOvB,OAAUY,EACvJ,SAASO,EAAKK,GAAK,OAAO,SAAUC,GAAK,OACzC,SAAcC,GACV,GAAIjB,EAAG,MAAM,IAAIkB,UAAU,mCA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AAK,KAlCE,MACJ,KAAK5D,EAAoB6D,KACrBhB,EAAOiB,KAAOtB,EAAcW,IAOxC,OAHIP,EAAS/D,QAAU,IACnBgE,EAAOkB,KAAOvB,EAAcI,EAAS,GAAGH,UAErCI","sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation. All rights reserved.\r\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use\r\nthis file except in compliance with the License. You may obtain a copy of the\r\nLicense at http://www.apache.org/licenses/LICENSE-2.0\r\n\r\nTHIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r\nKIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED\r\nWARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,\r\nMERCHANTABLITY OR NON-INFRINGEMENT.\r\n\r\nSee the Apache Version 2.0 License for specific language governing permissions\r\nand limitations under the License.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)\r\n t[p[i]] = s[p[i]];\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport function __exportStar(m, exports) {\r\n for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];\r\n}\r\n\r\nexport function __values(o) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator], i = 0;\r\n if (m) return m.call(o);\r\n return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];\r\n result.default = mod;\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n","export class NfcError extends Error {\r\n constructor(public code: NfcError.ErrorCode, message: string) {\r\n super(message);\r\n }\r\n\r\n public static tagLostError() {\r\n return new NfcError(NfcError.ErrorCode.TagLostError, 'NFC tag lost');\r\n }\r\n\r\n public static notConnectedError() {\r\n return new NfcError(\r\n NfcError.ErrorCode.NotConnectedError,\r\n 'NFC tag is not connected'\r\n );\r\n }\r\n\r\n public static unknownError(errString: string): NfcError {\r\n throw new NfcError(NfcError.ErrorCode.Unknown, errString);\r\n }\r\n\r\n public static tagConnectionFailed() {\r\n throw new NfcError(\r\n NfcError.ErrorCode.NotConnectedError,\r\n `Tag connection failed`\r\n );\r\n }\r\n\r\n public static internalError(message: string) {\r\n throw new NfcError(NfcError.ErrorCode.InternalError, message);\r\n }\r\n}\r\n\r\nexport namespace NfcError {\r\n export enum ErrorCode {\r\n Unknown = 'NfcUnknownError',\r\n InternalError = 'NfcInternalError',\r\n TagLostError = 'NfcTagLostError',\r\n NotConnectedError = 'NfcNotConnectedError',\r\n }\r\n}\r\n","import { createDebugger } from '@iotize/common/debug';\r\n\r\nexport const debug = createDebugger(`@iotize/device-com-nfc.cordova`);","import { bufferToAsciiString } from '@iotize/common/byte-converter';\r\n\r\nimport { NdefRecord, TapNfcTagPayload } from './definitions';\r\n\r\n/**\r\n * We manage only on NDEF message with 3 records:\r\n * record 0 = URI; record 1 = AAR; record 2 = BLE MAC ADDRESS / BSSID; record 3: universal link\r\n */\r\nexport function parseTapNdefMessage(messages: NdefRecord[]): TapNfcTagPayload {\r\n let result: TapNfcTagPayload = {};\r\n if (messages.length >= 1) {\r\n let asciiUri = messages[0].payload;\r\n result.uri = toAsciiString(asciiUri);\r\n }\r\n if (messages.length >= 2) {\r\n result.aar = toAsciiString(messages[1].payload);\r\n }\r\n if (messages.length >= 3) {\r\n let payload3 = messages[2].payload;\r\n let type = payload3[0];\r\n let content = payload3.slice(1);\r\n result.type = type;\r\n\r\n switch (type) {\r\n case TapNdefProtocolType.BLE:\r\n result.macAddress = convertBytesToBLEAddress(content);\r\n break;\r\n case TapNdefProtocolType.WiFi:\r\n result.ssid = toAsciiString(content);\r\n break;\r\n }\r\n }\r\n if (messages.length >= 4) {\r\n result.name = toAsciiString(messages[3].payload);\r\n }\r\n return result;\r\n}\r\n\r\nenum TapNdefProtocolType {\r\n WiFi = 0x20,\r\n BLE = 0x40\r\n}\r\n\r\nfunction toAsciiString(payload: number[]): string {\r\n if (payload.length > 0 && payload[0] === 0) {\r\n payload = payload.slice(1);\r\n }\r\n return bufferToAsciiString(payload as any as Uint8Array);\r\n}\r\n\r\nfunction convertBytesToBLEAddress(bytes: number[]): string {\r\n return bytes.map(byte => {\r\n if (byte < 0) {\r\n byte += 256;\r\n }\r\n let byteString = '0' + byte.toString(16).toUpperCase();\r\n byteString = byteString.slice(-2);\r\n return byteString;\r\n })\r\n .reverse()\r\n .join(':')\r\n}","import {\r\n bufferToHexString,\r\n hexStringToBuffer,\r\n} from '@iotize/common/byte-converter';\r\nimport {\r\n ComProtocolConnectOptions,\r\n ComProtocolDisconnectOptions,\r\n ComProtocolOptions,\r\n ComProtocolSendOptions,\r\n ConnectionState,\r\n} from '@iotize/tap/protocol/api';\r\nimport { QueueComProtocol } from '@iotize/tap/protocol/core';\r\nimport { defer, Observable } from 'rxjs';\r\n\r\nimport { CordovaInterface } from './cordova-interface';\r\nimport { NfcError } from './errors';\r\nimport { debug } from './logger';\r\n\r\ndeclare var nfc: CordovaInterface;\r\n\r\nexport class NFCComProtocol extends QueueComProtocol {\r\n constructor(\r\n options: ComProtocolOptions = {\r\n connect: {\r\n timeout: 2000,\r\n },\r\n disconnect: {\r\n timeout: 1000,\r\n },\r\n send: {\r\n timeout: 1000,\r\n },\r\n }\r\n ) {\r\n super();\r\n this.options = options;\r\n if (typeof nfc == undefined) {\r\n console.warn(\r\n 'NFC plugin has not been setup properly. Global variable NFC does not exist'\r\n );\r\n }\r\n }\r\n\r\n public static iOSProtocol(): NFCComProtocol {\r\n return new NFCComProtocol({\r\n connect: {\r\n timeout: 10000, // bigger timer on connect as connect launches a reading session\r\n },\r\n disconnect: {\r\n timeout: 1000,\r\n },\r\n send: {\r\n timeout: 1000,\r\n },\r\n });\r\n }\r\n\r\n /**\r\n * We force tag connection with nfc as we need to refresh tag\r\n * @param options\r\n * @returns\r\n */\r\n connect(options?: ComProtocolConnectOptions): Observable<void> {\r\n this.connectionState = ConnectionState.CONNECTING; // Hack to force NFC tag connect call even if we are already connected\r\n return super.connect(options);\r\n }\r\n\r\n /**\r\n * Not used as we have rewrote \"connect()\" function\r\n * @param options\r\n * @returns\r\n */\r\n _connect(options?: ComProtocolConnectOptions): Observable<any> {\r\n return defer(async () => {\r\n debug('_connect', options);\r\n try {\r\n await nfc.connect(\r\n 'android.nfc.tech.NfcV',\r\n this.options.connect.timeout\r\n );\r\n } catch (err) {\r\n if (typeof err === 'string') {\r\n if (err === 'Tag connection failed') {\r\n throw NfcError.tagConnectionFailed();\r\n } else {\r\n throw NfcError.unknownError(err);\r\n }\r\n }\r\n throw err;\r\n }\r\n });\r\n }\r\n\r\n _disconnect(options?: ComProtocolDisconnectOptions): Observable<any> {\r\n return defer(() => nfc.close());\r\n }\r\n\r\n /**\r\n * Not used\r\n * @param options\r\n * @returns\r\n */\r\n async write(data: Uint8Array): Promise<any> {\r\n throw new Error('Method not implemented.');\r\n }\r\n\r\n /**\r\n * Not used\r\n * @param options\r\n * @returns\r\n */\r\n async read(): Promise<Uint8Array> {\r\n throw new Error('Method not implemented.');\r\n }\r\n\r\n send(\r\n data: Uint8Array,\r\n options?: ComProtocolSendOptions\r\n ): Observable<Uint8Array> {\r\n return defer(async () => {\r\n try {\r\n const response = await nfc.transceive(bufferToHexString(data));\r\n if (typeof response != 'string') {\r\n throw NfcError.internalError(\r\n `Internal error. Plugin should respond a hexadecimal string`\r\n );\r\n }\r\n debug('NFC plugin response: ', response);\r\n return hexStringToBuffer(response);\r\n } catch (errString) {\r\n if (typeof errString === 'string') {\r\n const error = stringToError(errString);\r\n if (\r\n error.code === NfcError.ErrorCode.NotConnectedError ||\r\n error.code === NfcError.ErrorCode.TagLostError\r\n ) {\r\n this._onConnectionLost(error);\r\n }\r\n throw error;\r\n } else {\r\n throw errString;\r\n }\r\n }\r\n });\r\n }\r\n\r\n _onConnectionLost(error: NfcError) {\r\n if (this.connectionState !== ConnectionState.DISCONNECTED) {\r\n this.setConnectionState(ConnectionState.DISCONNECTED);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Convert error string returned by the plugin into an error object\r\n * It only checks a few Android error string for now\r\n *\r\n * TODO complete implementation with other error types\r\n *\r\n * @param errString\r\n */\r\nfunction stringToError(errString: string): NfcError {\r\n const errStringLc = errString.toLowerCase();\r\n if (errStringLc.indexOf('tag was lost') >= 0) {\r\n return NfcError.tagLostError();\r\n } else if (errStringLc.indexOf('not connected') >= 0) {\r\n return NfcError.notConnectedError();\r\n } else {\r\n return NfcError.unknownError(errString);\r\n }\r\n}\r\n"]}
@@ -12,6 +12,9 @@ export class NfcError extends Error {
12
12
  static unknownError(errString) {
13
13
  throw new NfcError(NfcError.ErrorCode.Unknown, errString);
14
14
  }
15
+ static tagConnectionFailed() {
16
+ throw new NfcError(NfcError.ErrorCode.NotConnectedError, `Tag connection failed`);
17
+ }
15
18
  static internalError(message) {
16
19
  throw new NfcError(NfcError.ErrorCode.InternalError, message);
17
20
  }
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../../src/www/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,QAAS,SAAQ,KAAK;IAE/B,YAAmB,IAAwB,EAAE,OAAe;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;QADA,SAAI,GAAJ,IAAI,CAAoB;IAE3C,CAAC;IAEM,MAAM,CAAC,YAAY;QACtB,OAAO,IAAI,QAAQ,CACf,QAAQ,CAAC,SAAS,CAAC,YAAY,EAC/B,cAAc,CACjB,CAAC;IACN,CAAC;IAEM,MAAM,CAAC,iBAAiB;QAC3B,OAAO,IAAI,QAAQ,CACf,QAAQ,CAAC,SAAS,CAAC,iBAAiB,EACpC,0BAA0B,CAC7B,CAAC;IACN,CAAC;IAEM,MAAM,CAAC,YAAY,CAAC,SAAiB;QACxC,MAAM,IAAI,QAAQ,CACd,QAAQ,CAAC,SAAS,CAAC,OAAO,EAC1B,SAAS,CACZ,CAAA;IACL,CAAC;IAEM,MAAM,CAAC,aAAa,CAAC,OAAe;QACvC,MAAM,IAAI,QAAQ,CACd,QAAQ,CAAC,SAAS,CAAC,aAAa,EAChC,OAAO,CACV,CAAA;IACL,CAAC;CACJ;AAED,WAAiB,QAAQ;IACrB,IAAY,SAKX;IALD,WAAY,SAAS;QACjB,wCAA2B,CAAA;QAC3B,+CAAkC,CAAA;QAClC,6CAAgC,CAAA;QAChC,uDAA0C,CAAA;IAC9C,CAAC,EALW,SAAS,GAAT,kBAAS,KAAT,kBAAS,QAKpB;AACL,CAAC,EAPgB,QAAQ,KAAR,QAAQ,QAOxB","sourcesContent":["export class NfcError extends Error {\r\n\r\n constructor(public code: NfcError.ErrorCode, message: string){\r\n super(message);\r\n }\r\n\r\n public static tagLostError(){\r\n return new NfcError(\r\n NfcError.ErrorCode.TagLostError,\r\n 'NFC tag lost'\r\n );\r\n }\r\n\r\n public static notConnectedError(){\r\n return new NfcError(\r\n NfcError.ErrorCode.NotConnectedError,\r\n 'NFC tag is not connected'\r\n );\r\n } \r\n\r\n public static unknownError(errString: string): NfcError {\r\n throw new NfcError(\r\n NfcError.ErrorCode.Unknown,\r\n errString\r\n )\r\n }\r\n \r\n public static internalError(message: string) {\r\n throw new NfcError(\r\n NfcError.ErrorCode.InternalError,\r\n message\r\n )\r\n }\r\n}\r\n\r\nexport namespace NfcError {\r\n export enum ErrorCode {\r\n Unknown = \"NfcUnknownError\",\r\n InternalError = \"NfcInternalError\",\r\n TagLostError = \"NfcTagLostError\",\r\n NotConnectedError = \"NfcNotConnectedError\"\r\n }\r\n}"]}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../../src/www/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,QAAS,SAAQ,KAAK;IACjC,YAAmB,IAAwB,EAAE,OAAe;QAC1D,KAAK,CAAC,OAAO,CAAC,CAAC;QADE,SAAI,GAAJ,IAAI,CAAoB;IAE3C,CAAC;IAEM,MAAM,CAAC,YAAY;QACxB,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;IACvE,CAAC;IAEM,MAAM,CAAC,iBAAiB;QAC7B,OAAO,IAAI,QAAQ,CACjB,QAAQ,CAAC,SAAS,CAAC,iBAAiB,EACpC,0BAA0B,CAC3B,CAAC;IACJ,CAAC;IAEM,MAAM,CAAC,YAAY,CAAC,SAAiB;QAC1C,MAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAC5D,CAAC;IAEM,MAAM,CAAC,mBAAmB;QAC/B,MAAM,IAAI,QAAQ,CAChB,QAAQ,CAAC,SAAS,CAAC,iBAAiB,EACpC,uBAAuB,CACxB,CAAC;IACJ,CAAC;IAEM,MAAM,CAAC,aAAa,CAAC,OAAe;QACzC,MAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IAChE,CAAC;CACF;AAED,WAAiB,QAAQ;IACvB,IAAY,SAKX;IALD,WAAY,SAAS;QACnB,wCAA2B,CAAA;QAC3B,+CAAkC,CAAA;QAClC,6CAAgC,CAAA;QAChC,uDAA0C,CAAA;IAC5C,CAAC,EALW,SAAS,GAAT,kBAAS,KAAT,kBAAS,QAKpB;AACH,CAAC,EAPgB,QAAQ,KAAR,QAAQ,QAOxB","sourcesContent":["export class NfcError extends Error {\r\n constructor(public code: NfcError.ErrorCode, message: string) {\r\n super(message);\r\n }\r\n\r\n public static tagLostError() {\r\n return new NfcError(NfcError.ErrorCode.TagLostError, 'NFC tag lost');\r\n }\r\n\r\n public static notConnectedError() {\r\n return new NfcError(\r\n NfcError.ErrorCode.NotConnectedError,\r\n 'NFC tag is not connected'\r\n );\r\n }\r\n\r\n public static unknownError(errString: string): NfcError {\r\n throw new NfcError(NfcError.ErrorCode.Unknown, errString);\r\n }\r\n\r\n public static tagConnectionFailed() {\r\n throw new NfcError(\r\n NfcError.ErrorCode.NotConnectedError,\r\n `Tag connection failed`\r\n );\r\n }\r\n\r\n public static internalError(message: string) {\r\n throw new NfcError(NfcError.ErrorCode.InternalError, message);\r\n }\r\n}\r\n\r\nexport namespace NfcError {\r\n export enum ErrorCode {\r\n Unknown = 'NfcUnknownError',\r\n InternalError = 'NfcInternalError',\r\n TagLostError = 'NfcTagLostError',\r\n NotConnectedError = 'NfcNotConnectedError',\r\n }\r\n}\r\n"]}
@@ -1,83 +1,129 @@
1
- //
2
- // Copyright 2018 IoTize SAS Inc. Licensed under the MIT license.
3
- //
4
- // ble-com-protocol.ts
5
- // device-com-ble.cordova BLE Cordova Plugin
6
- //
7
- import { bufferToHexString, hexStringToBuffer } from '@iotize/common/byte-converter';
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { bufferToHexString, hexStringToBuffer, } from '@iotize/common/byte-converter';
8
11
  import { ConnectionState, } from '@iotize/tap/protocol/api';
9
12
  import { QueueComProtocol } from '@iotize/tap/protocol/core';
10
- import { from } from 'rxjs';
13
+ import { defer } from 'rxjs';
11
14
  import { NfcError } from './errors';
12
15
  import { debug } from './logger';
13
16
  export class NFCComProtocol extends QueueComProtocol {
14
17
  constructor(options = {
15
18
  connect: {
16
- timeout: 2000
19
+ timeout: 2000,
17
20
  },
18
21
  disconnect: {
19
- timeout: 1000
22
+ timeout: 1000,
20
23
  },
21
24
  send: {
22
- timeout: 1000
23
- }
25
+ timeout: 1000,
26
+ },
24
27
  }) {
25
28
  super();
26
29
  this.options = options;
27
30
  if (typeof nfc == undefined) {
28
- console.warn("NFC plugin has not been setup properly. Global variable NFC does not exist");
31
+ console.warn('NFC plugin has not been setup properly. Global variable NFC does not exist');
29
32
  }
30
33
  }
31
34
  static iOSProtocol() {
32
35
  return new NFCComProtocol({
33
36
  connect: {
34
- timeout: 10000 // bigger timer on connect as connect launches a reading session
37
+ timeout: 10000, // bigger timer on connect as connect launches a reading session
35
38
  },
36
39
  disconnect: {
37
- timeout: 1000
40
+ timeout: 1000,
38
41
  },
39
42
  send: {
40
- timeout: 1000
41
- }
43
+ timeout: 1000,
44
+ },
42
45
  });
43
46
  }
47
+ /**
48
+ * We force tag connection with nfc as we need to refresh tag
49
+ * @param options
50
+ * @returns
51
+ */
52
+ connect(options) {
53
+ this.connectionState = ConnectionState.CONNECTING; // Hack to force NFC tag connect call even if we are already connected
54
+ return super.connect(options);
55
+ }
56
+ /**
57
+ * Not used as we have rewrote "connect()" function
58
+ * @param options
59
+ * @returns
60
+ */
44
61
  _connect(options) {
45
- debug('_connect', options);
46
- const connectPromise = nfc.connect("android.nfc.tech.NfcV", this.options.connect.timeout);
47
- return from(connectPromise);
62
+ return defer(() => __awaiter(this, void 0, void 0, function* () {
63
+ debug('_connect', options);
64
+ try {
65
+ yield nfc.connect('android.nfc.tech.NfcV', this.options.connect.timeout);
66
+ }
67
+ catch (err) {
68
+ if (typeof err === 'string') {
69
+ if (err === 'Tag connection failed') {
70
+ throw NfcError.tagConnectionFailed();
71
+ }
72
+ else {
73
+ throw NfcError.unknownError(err);
74
+ }
75
+ }
76
+ throw err;
77
+ }
78
+ }));
48
79
  }
49
80
  _disconnect(options) {
50
- return from(nfc.close());
81
+ return defer(() => nfc.close());
51
82
  }
83
+ /**
84
+ * Not used
85
+ * @param options
86
+ * @returns
87
+ */
52
88
  write(data) {
53
- throw new Error("Method not implemented.");
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ throw new Error('Method not implemented.');
91
+ });
54
92
  }
93
+ /**
94
+ * Not used
95
+ * @param options
96
+ * @returns
97
+ */
55
98
  read() {
56
- throw new Error("Method not implemented.");
99
+ return __awaiter(this, void 0, void 0, function* () {
100
+ throw new Error('Method not implemented.');
101
+ });
57
102
  }
58
103
  send(data, options) {
59
- const promise = nfc
60
- .transceive(bufferToHexString(data))
61
- .then((response) => {
62
- if (typeof response != "string") {
63
- throw NfcError.internalError(`Internal error. Plugin should respond a hexadecimal string`);
64
- }
65
- debug('NFC plugin response: ', response);
66
- return hexStringToBuffer(response);
67
- })
68
- .catch((errString) => {
69
- if (typeof errString === "string") {
70
- const error = stringToError(errString);
71
- if (error.code === NfcError.ErrorCode.NotConnectedError || error.code === NfcError.ErrorCode.TagLostError) {
72
- this._onConnectionLost(error);
104
+ return defer(() => __awaiter(this, void 0, void 0, function* () {
105
+ try {
106
+ const response = yield nfc.transceive(bufferToHexString(data));
107
+ if (typeof response != 'string') {
108
+ throw NfcError.internalError(`Internal error. Plugin should respond a hexadecimal string`);
73
109
  }
74
- throw error;
110
+ debug('NFC plugin response: ', response);
111
+ return hexStringToBuffer(response);
75
112
  }
76
- else {
77
- throw errString;
113
+ catch (errString) {
114
+ if (typeof errString === 'string') {
115
+ const error = stringToError(errString);
116
+ if (error.code === NfcError.ErrorCode.NotConnectedError ||
117
+ error.code === NfcError.ErrorCode.TagLostError) {
118
+ this._onConnectionLost(error);
119
+ }
120
+ throw error;
121
+ }
122
+ else {
123
+ throw errString;
124
+ }
78
125
  }
79
- });
80
- return from(promise);
126
+ }));
81
127
  }
82
128
  _onConnectionLost(error) {
83
129
  if (this.connectionState !== ConnectionState.DISCONNECTED) {
@@ -85,7 +131,6 @@ export class NFCComProtocol extends QueueComProtocol {
85
131
  }
86
132
  }
87
133
  }
88
- ;
89
134
  /**
90
135
  * Convert error string returned by the plugin into an error object
91
136
  * It only checks a few Android error string for now
@@ -1 +1 @@
1
- {"version":3,"file":"nfc-com-protocol.js","sourceRoot":"","sources":["../../../../../src/www/nfc-com-protocol.ts"],"names":[],"mappings":"AAAA,EAAE;AACF,oEAAoE;AACpE,EAAE;AACF,uBAAuB;AACvB,6CAA6C;AAC7C,EAAE;AACF,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACrF,OAAO,EAKH,eAAe,GAClB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAc,MAAM,MAAM,CAAC;AAGxC,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAKjC,MAAM,OAAO,cAAe,SAAQ,gBAAgB;IAEhD,YAAY,UAA8B;QACtC,OAAO,EAAE;YACL,OAAO,EAAE,IAAI;SAChB;QACD,UAAU,EAAE;YACR,OAAO,EAAE,I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Copyright 2018 IoTize SAS Inc. Licensed under the MIT license. \r\n//\r\n// ble-com-protocol.ts\r\n// device-com-ble.cordova BLE Cordova Plugin\r\n//\r\nimport { bufferToHexString, hexStringToBuffer } from '@iotize/common/byte-converter';\r\nimport {\r\n ComProtocolConnectOptions,\r\n ComProtocolDisconnectOptions,\r\n ComProtocolOptions,\r\n ComProtocolSendOptions,\r\n ConnectionState,\r\n} from '@iotize/tap/protocol/api';\r\nimport { QueueComProtocol } from '@iotize/tap/protocol/core';\r\nimport { from, Observable } from 'rxjs';\r\n\r\nimport { CordovaInterface } from './cordova-interface';\r\nimport { NfcError } from './errors';\r\nimport { debug } from './logger';\r\n\r\n\r\ndeclare var nfc: CordovaInterface;\r\n\r\nexport class NFCComProtocol extends QueueComProtocol {\r\n\r\n constructor(options: ComProtocolOptions = {\r\n connect: {\r\n timeout: 2000\r\n },\r\n disconnect: {\r\n timeout: 1000\r\n },\r\n send: {\r\n timeout: 1000\r\n }\r\n }) {\r\n super();\r\n this.options = options;\r\n if (typeof nfc == undefined) {\r\n console.warn(\"NFC plugin has not been setup properly. Global variable NFC does not exist\");\r\n }\r\n }\r\n\r\n public static iOSProtocol(): NFCComProtocol {\r\n return new NFCComProtocol({\r\n connect: {\r\n timeout: 10000 // bigger timer on connect as connect launches a reading session\r\n },\r\n disconnect: {\r\n timeout: 1000\r\n },\r\n send: {\r\n timeout: 1000\r\n }\r\n })\r\n }\r\n\r\n _connect(options?: ComProtocolConnectOptions): Observable<any> {\r\n debug('_connect', options);\r\n const connectPromise = nfc.connect(\"android.nfc.tech.NfcV\", this.options.connect.timeout)\r\n return from(connectPromise);\r\n }\r\n\r\n _disconnect(options?: ComProtocolDisconnectOptions): Observable<any> {\r\n return from(nfc.close());\r\n }\r\n\r\n write(data: Uint8Array): Promise<any> {\r\n throw new Error(\"Method not implemented.\");\r\n }\r\n\r\n read(): Promise<Uint8Array> {\r\n throw new Error(\"Method not implemented.\");\r\n }\r\n\r\n send(data: Uint8Array, options?: ComProtocolSendOptions): Observable<Uint8Array> {\r\n const promise = nfc\r\n .transceive(bufferToHexString(data))\r\n .then((response: string) => {\r\n if (typeof response != \"string\") {\r\n throw NfcError.internalError(`Internal error. Plugin should respond a hexadecimal string`);\r\n }\r\n debug('NFC plugin response: ', response)\r\n return hexStringToBuffer(response)\r\n })\r\n .catch((errString) => {\r\n if (typeof errString === \"string\") {\r\n const error = stringToError(errString);\r\n if (error.code === NfcError.ErrorCode.NotConnectedError || error.code === NfcError.ErrorCode.TagLostError) {\r\n this._onConnectionLost(error);\r\n }\r\n throw error;\r\n }\r\n else {\r\n throw errString;\r\n }\r\n });\r\n return from(promise);\r\n }\r\n\r\n _onConnectionLost(error: NfcError) {\r\n if (this.connectionState !== ConnectionState.DISCONNECTED) {\r\n this.setConnectionState(ConnectionState.DISCONNECTED);\r\n }\r\n }\r\n\r\n};\r\n\r\n/**\r\n * Convert error string returned by the plugin into an error object\r\n * It only checks a few Android error string for now\r\n * \r\n * TODO complete implementation with other error types\r\n * \r\n * @param errString \r\n */\r\nfunction stringToError(errString: string): NfcError {\r\n const errStringLc = errString.toLowerCase();\r\n if (errStringLc.indexOf('tag was lost') >= 0) {\r\n return NfcError.tagLostError();\r\n }\r\n else if (errStringLc.indexOf('not connected') >= 0) {\r\n return NfcError.notConnectedError();\r\n }\r\n else {\r\n return NfcError.unknownError(errString);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"nfc-com-protocol.js","sourceRoot":"","sources":["../../../../../src/www/nfc-com-protocol.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACL,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAKL,eAAe,GAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAc,MAAM,MAAM,CAAC;AAGzC,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;A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M;oBACL,MAAM,SAAS,CAAC;iBACjB;aACF;QACH,CAAC,CAAA,CAAC,CAAC;IACL,CAAC;IAED,iBAAiB,CAAC,KAAe;QAC/B,IAAI,IAAI,CAAC,eAAe,KAAK,eAAe,CAAC,YAAY,EAAE;YACzD,IAAI,CAAC,kBAAkB,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;SACvD;IACH,CAAC;CACF;AAED;;;;;;;GAOG;AACH,SAAS,aAAa,CAAC,SAAiB;IACtC,MAAM,WAAW,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;IAC5C,IAAI,WAAW,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE;QAC5C,OAAO,QAAQ,CAAC,YAAY,EAAE,CAAC;KAChC;SAAM,IAAI,WAAW,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE;QACpD,OAAO,QAAQ,CAAC,iBAAiB,EAAE,CAAC;KACrC;SAAM;QACL,OAAO,QAAQ,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;KACzC;AACH,CAAC","sourcesContent":["import {\r\n bufferToHexString,\r\n hexStringToBuffer,\r\n} from '@iotize/common/byte-converter';\r\nimport {\r\n ComProtocolConnectOptions,\r\n ComProtocolDisconnectOptions,\r\n ComProtocolOptions,\r\n ComProtocolSendOptions,\r\n ConnectionState,\r\n} from '@iotize/tap/protocol/api';\r\nimport { QueueComProtocol } from '@iotize/tap/protocol/core';\r\nimport { defer, Observable } from 'rxjs';\r\n\r\nimport { CordovaInterface } from './cordova-interface';\r\nimport { NfcError } from './errors';\r\nimport { debug } from './logger';\r\n\r\ndeclare var nfc: CordovaInterface;\r\n\r\nexport class NFCComProtocol extends QueueComProtocol {\r\n constructor(\r\n options: ComProtocolOptions = {\r\n connect: {\r\n timeout: 2000,\r\n },\r\n disconnect: {\r\n timeout: 1000,\r\n },\r\n send: {\r\n timeout: 1000,\r\n },\r\n }\r\n ) {\r\n super();\r\n this.options = options;\r\n if (typeof nfc == undefined) {\r\n console.warn(\r\n 'NFC plugin has not been setup properly. Global variable NFC does not exist'\r\n );\r\n }\r\n }\r\n\r\n public static iOSProtocol(): NFCComProtocol {\r\n return new NFCComProtocol({\r\n connect: {\r\n timeout: 10000, // bigger timer on connect as connect launches a reading session\r\n },\r\n disconnect: {\r\n timeout: 1000,\r\n },\r\n send: {\r\n timeout: 1000,\r\n },\r\n });\r\n }\r\n\r\n /**\r\n * We force tag connection with nfc as we need to refresh tag\r\n * @param options\r\n * @returns\r\n */\r\n connect(options?: ComProtocolConnectOptions): Observable<void> {\r\n this.connectionState = ConnectionState.CONNECTING; // Hack to force NFC tag connect call even if we are already connected\r\n return super.connect(options);\r\n }\r\n\r\n /**\r\n * Not used as we have rewrote \"connect()\" function\r\n * @param options\r\n * @returns\r\n */\r\n _connect(options?: ComProtocolConnectOptions): Observable<any> {\r\n return defer(async () => {\r\n debug('_connect', options);\r\n try {\r\n await nfc.connect(\r\n 'android.nfc.tech.NfcV',\r\n this.options.connect.timeout\r\n );\r\n } catch (err) {\r\n if (typeof err === 'string') {\r\n if (err === 'Tag connection failed') {\r\n throw NfcError.tagConnectionFailed();\r\n } else {\r\n throw NfcError.unknownError(err);\r\n }\r\n }\r\n throw err;\r\n }\r\n });\r\n }\r\n\r\n _disconnect(options?: ComProtocolDisconnectOptions): Observable<any> {\r\n return defer(() => nfc.close());\r\n }\r\n\r\n /**\r\n * Not used\r\n * @param options\r\n * @returns\r\n */\r\n async write(data: Uint8Array): Promise<any> {\r\n throw new Error('Method not implemented.');\r\n }\r\n\r\n /**\r\n * Not used\r\n * @param options\r\n * @returns\r\n */\r\n async read(): Promise<Uint8Array> {\r\n throw new Error('Method not implemented.');\r\n }\r\n\r\n send(\r\n data: Uint8Array,\r\n options?: ComProtocolSendOptions\r\n ): Observable<Uint8Array> {\r\n return defer(async () => {\r\n try {\r\n const response = await nfc.transceive(bufferToHexString(data));\r\n if (typeof response != 'string') {\r\n throw NfcError.internalError(\r\n `Internal error. Plugin should respond a hexadecimal string`\r\n );\r\n }\r\n debug('NFC plugin response: ', response);\r\n return hexStringToBuffer(response);\r\n } catch (errString) {\r\n if (typeof errString === 'string') {\r\n const error = stringToError(errString);\r\n if (\r\n error.code === NfcError.ErrorCode.NotConnectedError ||\r\n error.code === NfcError.ErrorCode.TagLostError\r\n ) {\r\n this._onConnectionLost(error);\r\n }\r\n throw error;\r\n } else {\r\n throw errString;\r\n }\r\n }\r\n });\r\n }\r\n\r\n _onConnectionLost(error: NfcError) {\r\n if (this.connectionState !== ConnectionState.DISCONNECTED) {\r\n this.setConnectionState(ConnectionState.DISCONNECTED);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Convert error string returned by the plugin into an error object\r\n * It only checks a few Android error string for now\r\n *\r\n * TODO complete implementation with other error types\r\n *\r\n * @param errString\r\n */\r\nfunction stringToError(errString: string): NfcError {\r\n const errStringLc = errString.toLowerCase();\r\n if (errStringLc.indexOf('tag was lost') >= 0) {\r\n return NfcError.tagLostError();\r\n } else if (errStringLc.indexOf('not connected') >= 0) {\r\n return NfcError.notConnectedError();\r\n } else {\r\n return NfcError.unknownError(errString);\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- [{"__symbolic":"module","version":4,"metadata":{"NFCComProtocol":{"__symbolic":"class","extends":{"__symbolic":"reference","module":"@iotize/tap/protocol/core","name":"QueueComProtocol","line":24,"character":36},"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@iotize/tap/protocol/api","name":"ComProtocolOptions","line":26,"character":25}]}],"_connect":[{"__symbolic":"method"}],"_disconnect":[{"__symbolic":"method"}],"write":[{"__symbolic":"method"}],"read":[{"__symbolic":"method"}],"send":[{"__symbolic":"method"}],"_onConnectionLost":[{"__symbolic":"method"}]},"statics":{"iOSProtocol":{"__symbolic":"function","parameters":[],"value":{"__symbolic":"new","expression":{"__symbolic":"reference","name":"NFCComProtocol"},"arguments":[{"connect":{"timeout":10000},"disconnect":{"timeout":1000},"send":{"timeout":1000}}]}}}}}}]
1
+ [{"__symbolic":"module","version":4,"metadata":{"NFCComProtocol":{"__symbolic":"class","extends":{"__symbolic":"reference","module":"@iotize/tap/protocol/core","name":"QueueComProtocol","line":20,"character":36},"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@iotize/tap/protocol/api","name":"ComProtocolOptions","line":22,"character":13}]}],"connect":[{"__symbolic":"method"}],"_connect":[{"__symbolic":"method"}],"_disconnect":[{"__symbolic":"method"}],"write":[{"__symbolic":"method"}],"read":[{"__symbolic":"method"}],"send":[{"__symbolic":"method"}],"_onConnectionLost":[{"__symbolic":"method"}]},"statics":{"iOSProtocol":{"__symbolic":"function","parameters":[],"value":{"__symbolic":"new","expression":{"__symbolic":"reference","name":"NFCComProtocol"},"arguments":[{"connect":{"timeout":10000},"disconnect":{"timeout":1000},"send":{"timeout":1000}}]}}}}}}]
@@ -1 +1 @@
1
- {"moduleName":null,"summaries":[{"symbol":{"__symbol":0,"members":[]},"metadata":{"__symbolic":"class","extends":{"__symbol":1,"members":[]},"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbol":2,"members":[]}]}],"_connect":[{"__symbolic":"method"}],"_disconnect":[{"__symbolic":"method"}],"write":[{"__symbolic":"method"}],"read":[{"__symbolic":"method"}],"send":[{"__symbolic":"method"}],"_onConnectionLost":[{"__symbolic":"method"}]},"statics":{"iOSProtocol":{"__symbolic":"function","parameters":[],"value":{"__symbolic":"new","expression":{"__symbol":0,"members":[]},"arguments":[{"connect":{"timeout":10000},"disconnect":{"timeout":1000},"send":{"timeout":1000}}]}}}}}],"symbols":[{"__symbol":0,"name":"NFCComProtocol","filePath":"./nfc-com-protocol"},{"__symbol":1,"name":"QueueComProtocol","filePath":"@iotize/tap/protocol/core/iotize-tap-protocol-core"},{"__symbol":2,"name":"ComProtocolOptions","filePath":"@iotize/tap/protocol/api/iotize-tap-protocol-api"}]}
1
+ {"moduleName":null,"summaries":[{"symbol":{"__symbol":0,"members":[]},"metadata":{"__symbolic":"class","extends":{"__symbol":1,"members":[]},"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbol":2,"members":[]}]}],"connect":[{"__symbolic":"method"}],"_connect":[{"__symbolic":"method"}],"_disconnect":[{"__symbolic":"method"}],"write":[{"__symbolic":"method"}],"read":[{"__symbolic":"method"}],"send":[{"__symbolic":"method"}],"_onConnectionLost":[{"__symbolic":"method"}]},"statics":{"iOSProtocol":{"__symbolic":"function","parameters":[],"value":{"__symbolic":"new","expression":{"__symbol":0,"members":[]},"arguments":[{"connect":{"timeout":10000},"disconnect":{"timeout":1000},"send":{"timeout":1000}}]}}}}}],"symbols":[{"__symbol":0,"name":"NFCComProtocol","filePath":"./nfc-com-protocol"},{"__symbol":1,"name":"QueueComProtocol","filePath":"@iotize/tap/protocol/core/iotize-tap-protocol-core"},{"__symbol":2,"name":"ComProtocolOptions","filePath":"@iotize/tap/protocol/api/iotize-tap-protocol-api"}]}
@@ -1,7 +1,7 @@
1
1
  import { bufferToHexString, hexStringToBuffer, bufferToAsciiString } from '@iotize/common/byte-converter';
2
2
  import { ConnectionState } from '@iotize/tap/protocol/api';
3
3
  import { QueueComProtocol } from '@iotize/tap/protocol/core';
4
- import { from } from 'rxjs';
4
+ import { defer } from 'rxjs';
5
5
  import { createDebugger } from '@iotize/common/debug';
6
6
 
7
7
  class NfcError extends Error {
@@ -18,6 +18,9 @@ class NfcError extends Error {
18
18
  static unknownError(errString) {
19
19
  throw new NfcError(NfcError.ErrorCode.Unknown, errString);
20
20
  }
21
+ static tagConnectionFailed() {
22
+ throw new NfcError(NfcError.ErrorCode.NotConnectedError, `Tag connection failed`);
23
+ }
21
24
  static internalError(message) {
22
25
  throw new NfcError(NfcError.ErrorCode.InternalError, message);
23
26
  }
@@ -34,75 +37,126 @@ class NfcError extends Error {
34
37
 
35
38
  const debug = createDebugger(`@iotize/device-com-nfc.cordova`);
36
39
 
37
- //
40
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
41
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
42
+ return new (P || (P = Promise))(function (resolve, reject) {
43
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
44
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
45
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
46
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
47
+ });
48
+ };
38
49
  class NFCComProtocol extends QueueComProtocol {
39
50
  constructor(options = {
40
51
  connect: {
41
- timeout: 2000
52
+ timeout: 2000,
42
53
  },
43
54
  disconnect: {
44
- timeout: 1000
55
+ timeout: 1000,
45
56
  },
46
57
  send: {
47
- timeout: 1000
48
- }
58
+ timeout: 1000,
59
+ },
49
60
  }) {
50
61
  super();
51
62
  this.options = options;
52
63
  if (typeof nfc == undefined) {
53
- console.warn("NFC plugin has not been setup properly. Global variable NFC does not exist");
64
+ console.warn('NFC plugin has not been setup properly. Global variable NFC does not exist');
54
65
  }
55
66
  }
56
67
  static iOSProtocol() {
57
68
  return new NFCComProtocol({
58
69
  connect: {
59
- timeout: 10000 // bigger timer on connect as connect launches a reading session
70
+ timeout: 10000, // bigger timer on connect as connect launches a reading session
60
71
  },
61
72
  disconnect: {
62
- timeout: 1000
73
+ timeout: 1000,
63
74
  },
64
75
  send: {
65
- timeout: 1000
66
- }
76
+ timeout: 1000,
77
+ },
67
78
  });
68
79
  }
80
+ /**
81
+ * We force tag connection with nfc as we need to refresh tag
82
+ * @param options
83
+ * @returns
84
+ */
85
+ connect(options) {
86
+ this.connectionState = ConnectionState.CONNECTING; // Hack to force NFC tag connect call even if we are already connected
87
+ return super.connect(options);
88
+ }
89
+ /**
90
+ * Not used as we have rewrote "connect()" function
91
+ * @param options
92
+ * @returns
93
+ */
69
94
  _connect(options) {
70
- debug('_connect', options);
71
- const connectPromise = nfc.connect("android.nfc.tech.NfcV", this.options.connect.timeout);
72
- return from(connectPromise);
95
+ return defer(() => __awaiter(this, void 0, void 0, function* () {
96
+ debug('_connect', options);
97
+ try {
98
+ yield nfc.connect('android.nfc.tech.NfcV', this.options.connect.timeout);
99
+ }
100
+ catch (err) {
101
+ if (typeof err === 'string') {
102
+ if (err === 'Tag connection failed') {
103
+ throw NfcError.tagConnectionFailed();
104
+ }
105
+ else {
106
+ throw NfcError.unknownError(err);
107
+ }
108
+ }
109
+ throw err;
110
+ }
111
+ }));
73
112
  }
74
113
  _disconnect(options) {
75
- return from(nfc.close());
114
+ return defer(() => nfc.close());
76
115
  }
116
+ /**
117
+ * Not used
118
+ * @param options
119
+ * @returns
120
+ */
77
121
  write(data) {
78
- throw new Error("Method not implemented.");
122
+ return __awaiter(this, void 0, void 0, function* () {
123
+ throw new Error('Method not implemented.');
124
+ });
79
125
  }
126
+ /**
127
+ * Not used
128
+ * @param options
129
+ * @returns
130
+ */
80
131
  read() {
81
- throw new Error("Method not implemented.");
132
+ return __awaiter(this, void 0, void 0, function* () {
133
+ throw new Error('Method not implemented.');
134
+ });
82
135
  }
83
136
  send(data, options) {
84
- const promise = nfc
85
- .transceive(bufferToHexString(data))
86
- .then((response) => {
87
- if (typeof response != "string") {
88
- throw NfcError.internalError(`Internal error. Plugin should respond a hexadecimal string`);
89
- }
90
- debug('NFC plugin response: ', response);
91
- return hexStringToBuffer(response);
92
- })
93
- .catch((errString) => {
94
- if (typeof errString === "string") {
95
- const error = stringToError(errString);
96
- if (error.code === NfcError.ErrorCode.NotConnectedError || error.code === NfcError.ErrorCode.TagLostError) {
97
- this._onConnectionLost(error);
137
+ return defer(() => __awaiter(this, void 0, void 0, function* () {
138
+ try {
139
+ const response = yield nfc.transceive(bufferToHexString(data));
140
+ if (typeof response != 'string') {
141
+ throw NfcError.internalError(`Internal error. Plugin should respond a hexadecimal string`);
98
142
  }
99
- throw error;
143
+ debug('NFC plugin response: ', response);
144
+ return hexStringToBuffer(response);
100
145
  }
101
- else {
102
- throw errString;
146
+ catch (errString) {
147
+ if (typeof errString === 'string') {
148
+ const error = stringToError(errString);
149
+ if (error.code === NfcError.ErrorCode.NotConnectedError ||
150
+ error.code === NfcError.ErrorCode.TagLostError) {
151
+ this._onConnectionLost(error);
152
+ }
153
+ throw error;
154
+ }
155
+ else {
156
+ throw errString;
157
+ }
103
158
  }
104
- });
105
- return from(promise);
159
+ }));
106
160
  }
107
161
  _onConnectionLost(error) {
108
162
  if (this.connectionState !== ConnectionState.DISCONNECTED) {
@@ -110,7 +164,6 @@ class NFCComProtocol extends QueueComProtocol {
110
164
  }
111
165
  }
112
166
  }
113
- ;
114
167
  /**
115
168
  * Convert error string returned by the plugin into an error object
116
169
  * It only checks a few Android error string for now
@@ -1 +1 @@
1
- {"version":3,"file":"iotize-device-com-nfc.cordova.js","sources":["../../../../src/www/errors.ts","../../../../src/www/logger.ts","../../../../src/www/nfc-com-protocol.ts","../../../../src/www/tap-ndef/parse-ndef-message.ts","../../../../src/iotize-device-com-nfc.cordova.ts"],"sourcesContent":["export class NfcError extends Error {\r\n\r\n constructor(public code: NfcError.ErrorCode, message: string){\r\n super(message);\r\n }\r\n\r\n public static tagLostError(){\r\n return new NfcError(\r\n NfcError.ErrorCode.TagLostError,\r\n 'NFC tag lost'\r\n );\r\n }\r\n\r\n public static notConnectedError(){\r\n return new NfcError(\r\n NfcError.ErrorCode.NotConnectedError,\r\n 'NFC tag is not connected'\r\n );\r\n } \r\n\r\n public static unknownError(errString: string): NfcError {\r\n throw new NfcError(\r\n NfcError.ErrorCode.Unknown,\r\n errString\r\n )\r\n }\r\n \r\n public static internalError(message: string) {\r\n throw new NfcError(\r\n NfcError.ErrorCode.InternalError,\r\n message\r\n )\r\n }\r\n}\r\n\r\nexport namespace NfcError {\r\n export enum ErrorCode {\r\n Unknown = \"NfcUnknownError\",\r\n InternalError = \"NfcInternalError\",\r\n TagLostError = \"NfcTagLostError\",\r\n NotConnectedError = \"NfcNotConnectedError\"\r\n }\r\n}","import { createDebugger } from '@iotize/common/debug';\r\n\r\nexport const debug = createDebugger(`@iotize/device-com-nfc.cordova`);","//\r\n// Copyright 2018 IoTize SAS Inc. Licensed under the MIT license. \r\n//\r\n// ble-com-protocol.ts\r\n// device-com-ble.cordova BLE Cordova Plugin\r\n//\r\nimport { bufferToHexString, hexStringToBuffer } from '@iotize/common/byte-converter';\r\nimport {\r\n ComProtocolConnectOptions,\r\n ComProtocolDisconnectOptions,\r\n ComProtocolOptions,\r\n ComProtocolSendOptions,\r\n ConnectionState,\r\n} from '@iotize/tap/protocol/api';\r\nimport { QueueComProtocol } from '@iotize/tap/protocol/core';\r\nimport { from, Observable } from 'rxjs';\r\n\r\nimport { CordovaInterface } from './cordova-interface';\r\nimport { NfcError } from './errors';\r\nimport { debug } from './logger';\r\n\r\n\r\ndeclare var nfc: CordovaInterface;\r\n\r\nexport class NFCComProtocol extends QueueComProtocol {\r\n\r\n constructor(options: ComProtocolOptions = {\r\n connect: {\r\n timeout: 2000\r\n },\r\n disconnect: {\r\n timeout: 1000\r\n },\r\n send: {\r\n timeout: 1000\r\n }\r\n }) {\r\n super();\r\n this.options = options;\r\n if (typeof nfc == undefined) {\r\n console.warn(\"NFC plugin has not been setup properly. Global variable NFC does not exist\");\r\n }\r\n }\r\n\r\n public static iOSProtocol(): NFCComProtocol {\r\n return new NFCComProtocol({\r\n connect: {\r\n timeout: 10000 // bigger timer on connect as connect launches a reading session\r\n },\r\n disconnect: {\r\n timeout: 1000\r\n },\r\n send: {\r\n timeout: 1000\r\n }\r\n })\r\n }\r\n\r\n _connect(options?: ComProtocolConnectOptions): Observable<any> {\r\n debug('_connect', options);\r\n const connectPromise = nfc.connect(\"android.nfc.tech.NfcV\", this.options.connect.timeout)\r\n return from(connectPromise);\r\n }\r\n\r\n _disconnect(options?: ComProtocolDisconnectOptions): Observable<any> {\r\n return from(nfc.close());\r\n }\r\n\r\n write(data: Uint8Array): Promise<any> {\r\n throw new Error(\"Method not implemented.\");\r\n }\r\n\r\n read(): Promise<Uint8Array> {\r\n throw new Error(\"Method not implemented.\");\r\n }\r\n\r\n send(data: Uint8Array, options?: ComProtocolSendOptions): Observable<Uint8Array> {\r\n const promise = nfc\r\n .transceive(bufferToHexString(data))\r\n .then((response: string) => {\r\n if (typeof response != \"string\") {\r\n throw NfcError.internalError(`Internal error. Plugin should respond a hexadecimal string`);\r\n }\r\n debug('NFC plugin response: ', response)\r\n return hexStringToBuffer(response)\r\n })\r\n .catch((errString) => {\r\n if (typeof errString === \"string\") {\r\n const error = stringToError(errString);\r\n if (error.code === NfcError.ErrorCode.NotConnectedError || error.code === NfcError.ErrorCode.TagLostError) {\r\n this._onConnectionLost(error);\r\n }\r\n throw error;\r\n }\r\n else {\r\n throw errString;\r\n }\r\n });\r\n return from(promise);\r\n }\r\n\r\n _onConnectionLost(error: NfcError) {\r\n if (this.connectionState !== ConnectionState.DISCONNECTED) {\r\n this.setConnectionState(ConnectionState.DISCONNECTED);\r\n }\r\n }\r\n\r\n};\r\n\r\n/**\r\n * Convert error string returned by the plugin into an error object\r\n * It only checks a few Android error string for now\r\n * \r\n * TODO complete implementation with other error types\r\n * \r\n * @param errString \r\n */\r\nfunction stringToError(errString: string): NfcError {\r\n const errStringLc = errString.toLowerCase();\r\n if (errStringLc.indexOf('tag was lost') >= 0) {\r\n return NfcError.tagLostError();\r\n }\r\n else if (errStringLc.indexOf('not connected') >= 0) {\r\n return NfcError.notConnectedError();\r\n }\r\n else {\r\n return NfcError.unknownError(errString);\r\n }\r\n}\r\n","import { bufferToAsciiString } from '@iotize/common/byte-converter';\r\n\r\nimport { NdefRecord, TapNfcTagPayload } from './definitions';\r\n\r\n/**\r\n * We manage only on NDEF message with 3 records:\r\n * record 0 = URI; record 1 = AAR; record 2 = BLE MAC ADDRESS / BSSID; record 3: universal link\r\n */\r\nexport function parseTapNdefMessage(messages: NdefRecord[]): TapNfcTagPayload {\r\n let result: TapNfcTagPayload = {};\r\n if (messages.length >= 1) {\r\n let asciiUri = messages[0].payload;\r\n result.uri = toAsciiString(asciiUri);\r\n }\r\n if (messages.length >= 2) {\r\n result.aar = toAsciiString(messages[1].payload);\r\n }\r\n if (messages.length >= 3) {\r\n let payload3 = messages[2].payload;\r\n let type = payload3[0];\r\n let content = payload3.slice(1);\r\n result.type = type;\r\n\r\n switch (type) {\r\n case TapNdefProtocolType.BLE:\r\n result.macAddress = convertBytesToBLEAddress(content);\r\n break;\r\n case TapNdefProtocolType.WiFi:\r\n result.ssid = toAsciiString(content);\r\n break;\r\n }\r\n }\r\n if (messages.length >= 4) {\r\n result.name = toAsciiString(messages[3].payload);\r\n }\r\n return result;\r\n}\r\n\r\nenum TapNdefProtocolType {\r\n WiFi = 0x20,\r\n BLE = 0x40\r\n}\r\n\r\nfunction toAsciiString(payload: number[]): string {\r\n if (payload.length > 0 && payload[0] === 0) {\r\n payload = payload.slice(1);\r\n }\r\n return bufferToAsciiString(payload as any as Uint8Array);\r\n}\r\n\r\nfunction convertBytesToBLEAddress(bytes: number[]): string {\r\n return bytes.map(byte => {\r\n if (byte < 0) {\r\n byte += 256;\r\n }\r\n let byteString = '0' + byte.toString(16).toUpperCase();\r\n byteString = byteString.slice(-2);\r\n return byteString;\r\n })\r\n .reverse()\r\n .join(':')\r\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;;MAAa,QAAS,SAAQ,KAAK;IAE/B,YAAmB,IAAwB,EAAE,OAAe;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;QADA,SAAI,GAAJ,IAAI,CAAoB;KAE1C;IAEM,OAAO,YAAY;QACtB,OAAO,IAAI,QAAQ,CACf,QAAQ,CAAC,SAAS,CAAC,YAAY,EAC/B,cAAc,CACjB,CAAC;KACL;IAEM,OAAO,iBAAiB;QAC3B,OAAO,IAAI,QAAQ,CACf,QAAQ,CAAC,SAAS,CAAC,iBAAiB,EACpC,0BAA0B,CAC7B,CAAC;KACL;IAEM,OAAO,YAAY,CAAC,SAAiB;QACxC,MAAM,IAAI,QA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www/logger.ts","../../../../src/www/nfc-com-protocol.ts","../../../../src/www/tap-ndef/parse-ndef-message.ts","../../../../src/iotize-device-com-nfc.cordova.ts"],"sourcesContent":["export class NfcError extends Error {\r\n constructor(public code: NfcError.ErrorCode, message: string) {\r\n super(message);\r\n }\r\n\r\n public static tagLostError() {\r\n return new NfcError(NfcError.ErrorCode.TagLostError, 'NFC tag lost');\r\n }\r\n\r\n public static notConnectedError() {\r\n return new NfcError(\r\n NfcError.ErrorCode.NotConnectedError,\r\n 'NFC tag is not connected'\r\n );\r\n }\r\n\r\n public static unknownError(errString: string): NfcError {\r\n throw new NfcError(NfcError.ErrorCode.Unknown, errString);\r\n }\r\n\r\n public static tagConnectionFailed() {\r\n throw new NfcError(\r\n NfcError.ErrorCode.NotConnectedError,\r\n `Tag connection failed`\r\n );\r\n }\r\n\r\n public static internalError(message: string) {\r\n throw new NfcError(NfcError.ErrorCode.InternalError, message);\r\n }\r\n}\r\n\r\nexport namespace NfcError {\r\n export enum ErrorCode {\r\n Unknown = 'NfcUnknownError',\r\n InternalError = 'NfcInternalError',\r\n TagLostError = 'NfcTagLostError',\r\n NotConnectedError = 'NfcNotConnectedError',\r\n }\r\n}\r\n","import { createDebugger } from '@iotize/common/debug';\r\n\r\nexport const debug = createDebugger(`@iotize/device-com-nfc.cordova`);","import {\r\n bufferToHexString,\r\n hexStringToBuffer,\r\n} from '@iotize/common/byte-converter';\r\nimport {\r\n ComProtocolConnectOptions,\r\n ComProtocolDisconnectOptions,\r\n ComProtocolOptions,\r\n ComProtocolSendOptions,\r\n ConnectionState,\r\n} from '@iotize/tap/protocol/api';\r\nimport { QueueComProtocol } from '@iotize/tap/protocol/core';\r\nimport { defer, Observable } from 'rxjs';\r\n\r\nimport { CordovaInterface } from './cordova-interface';\r\nimport { NfcError } from './errors';\r\nimport { debug } from './logger';\r\n\r\ndeclare var nfc: CordovaInterface;\r\n\r\nexport class NFCComProtocol extends QueueComProtocol {\r\n constructor(\r\n options: ComProtocolOptions = {\r\n connect: {\r\n timeout: 2000,\r\n },\r\n disconnect: {\r\n timeout: 1000,\r\n },\r\n send: {\r\n timeout: 1000,\r\n },\r\n }\r\n ) {\r\n super();\r\n this.options = options;\r\n if (typeof nfc == undefined) {\r\n console.warn(\r\n 'NFC plugin has not been setup properly. Global variable NFC does not exist'\r\n );\r\n }\r\n }\r\n\r\n public static iOSProtocol(): NFCComProtocol {\r\n return new NFCComProtocol({\r\n connect: {\r\n timeout: 10000, // bigger timer on connect as connect launches a reading session\r\n },\r\n disconnect: {\r\n timeout: 1000,\r\n },\r\n send: {\r\n timeout: 1000,\r\n },\r\n });\r\n }\r\n\r\n /**\r\n * We force tag connection with nfc as we need to refresh tag\r\n * @param options\r\n * @returns\r\n */\r\n connect(options?: ComProtocolConnectOptions): Observable<void> {\r\n this.connectionState = ConnectionState.CONNECTING; // Hack to force NFC tag connect call even if we are already connected\r\n return super.connect(options);\r\n }\r\n\r\n /**\r\n * Not used as we have rewrote \"connect()\" function\r\n * @param options\r\n * @returns\r\n */\r\n _connect(options?: ComProtocolConnectOptions): Observable<any> {\r\n return defer(async () => {\r\n debug('_connect', options);\r\n try {\r\n await nfc.connect(\r\n 'android.nfc.tech.NfcV',\r\n this.options.connect.timeout\r\n );\r\n } catch (err) {\r\n if (typeof err === 'string') {\r\n if (err === 'Tag connection failed') {\r\n throw NfcError.tagConnectionFailed();\r\n } else {\r\n throw NfcError.unknownError(err);\r\n }\r\n }\r\n throw err;\r\n }\r\n });\r\n }\r\n\r\n _disconnect(options?: ComProtocolDisconnectOptions): Observable<any> {\r\n return defer(() => nfc.close());\r\n }\r\n\r\n /**\r\n * Not used\r\n * @param options\r\n * @returns\r\n */\r\n async write(data: Uint8Array): Promise<any> {\r\n throw new Error('Method not implemented.');\r\n }\r\n\r\n /**\r\n * Not used\r\n * @param options\r\n * @returns\r\n */\r\n async read(): Promise<Uint8Array> {\r\n throw new Error('Method not implemented.');\r\n }\r\n\r\n send(\r\n data: Uint8Array,\r\n options?: ComProtocolSendOptions\r\n ): Observable<Uint8Array> {\r\n return defer(async () => {\r\n try {\r\n const response = await nfc.transceive(bufferToHexString(data));\r\n if (typeof response != 'string') {\r\n throw NfcError.internalError(\r\n `Internal error. Plugin should respond a hexadecimal string`\r\n );\r\n }\r\n debug('NFC plugin response: ', response);\r\n return hexStringToBuffer(response);\r\n } catch (errString) {\r\n if (typeof errString === 'string') {\r\n const error = stringToError(errString);\r\n if (\r\n error.code === NfcError.ErrorCode.NotConnectedError ||\r\n error.code === NfcError.ErrorCode.TagLostError\r\n ) {\r\n this._onConnectionLost(error);\r\n }\r\n throw error;\r\n } else {\r\n throw errString;\r\n }\r\n }\r\n });\r\n }\r\n\r\n _onConnectionLost(error: NfcError) {\r\n if (this.connectionState !== ConnectionState.DISCONNECTED) {\r\n this.setConnectionState(ConnectionState.DISCONNECTED);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Convert error string returned by the plugin into an error object\r\n * It only checks a few Android error string for now\r\n *\r\n * TODO complete implementation with other error types\r\n *\r\n * @param errString\r\n */\r\nfunction stringToError(errString: string): NfcError {\r\n const errStringLc = errString.toLowerCase();\r\n if (errStringLc.indexOf('tag was lost') >= 0) {\r\n return NfcError.tagLostError();\r\n } else if (errStringLc.indexOf('not connected') >= 0) {\r\n return NfcError.notConnectedError();\r\n } else {\r\n return NfcError.unknownError(errString);\r\n }\r\n}\r\n","import { bufferToAsciiString } from '@iotize/common/byte-converter';\r\n\r\nimport { NdefRecord, TapNfcTagPayload } from './definitions';\r\n\r\n/**\r\n * We manage only on NDEF message with 3 records:\r\n * record 0 = URI; record 1 = AAR; record 2 = BLE MAC ADDRESS / BSSID; record 3: universal link\r\n */\r\nexport function parseTapNdefMessage(messages: NdefRecord[]): TapNfcTagPayload {\r\n let result: TapNfcTagPayload = {};\r\n if (messages.length >= 1) {\r\n let asciiUri = messages[0].payload;\r\n result.uri = toAsciiString(asciiUri);\r\n }\r\n if (messages.length >= 2) {\r\n result.aar = toAsciiString(messages[1].payload);\r\n }\r\n if (messages.length >= 3) {\r\n let payload3 = messages[2].payload;\r\n let type = payload3[0];\r\n let content = payload3.slice(1);\r\n result.type = type;\r\n\r\n switch (type) {\r\n case TapNdefProtocolType.BLE:\r\n result.macAddress = convertBytesToBLEAddress(content);\r\n break;\r\n case TapNdefProtocolType.WiFi:\r\n result.ssid = toAsciiString(content);\r\n break;\r\n }\r\n }\r\n if (messages.length >= 4) {\r\n result.name = toAsciiString(messages[3].payload);\r\n }\r\n return result;\r\n}\r\n\r\nenum TapNdefProtocolType {\r\n WiFi = 0x20,\r\n BLE = 0x40\r\n}\r\n\r\nfunction toAsciiString(payload: number[]): string {\r\n if (payload.length > 0 && payload[0] === 0) {\r\n payload = payload.slice(1);\r\n }\r\n return bufferToAsciiString(payload as any as Uint8Array);\r\n}\r\n\r\nfunction convertBytesToBLEAddress(bytes: number[]): string {\r\n return bytes.map(byte => {\r\n if (byte < 0) {\r\n byte += 256;\r\n }\r\n let byteString = '0' + byte.toString(16).toUpperCase();\r\n byteString = byteString.slice(-2);\r\n return byteString;\r\n })\r\n .reverse()\r\n .join(':')\r\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;;AAAM,MAAO,QAAS,SAAQ,KAAK,CAAA;IACjC,WAAmB,CAAA,IAAwB,EAAE,OAAe,EAAA;QAC1D,KAAK,CAAC,OAAO,CAAC,CAAC;QADE,IAAI,CAAA,IAAA,GAAJ,IAAI,CAAoB;KAE1C;AAEM,IAAA,OAAO,YAAY,GAAA;QACxB,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;KACtE;AAEM,IAAA,OAAO,iBAAiB,GAAA;QAC7B,OAAO,IAAI,QAAQ,CACjB,QAAQ,CAAC,SAAS,CAAC,iBAAiB,EACpC,0BAA0B,CAC3B,CAAC;KACH;IAEM,OAAO,YAAY,CAAC,SAAiB,EAAA;QAC1C,MAAM,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AiB,EAAA;AACpC,IAAA,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE;AACxC,QAAA,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC9B,KAAA;AACD,IAAA,OAAO,mBAAmB,CAAC,OAA4B,CAAC,CAAC;AAC7D,CAAC;AAED,SAAS,wBAAwB,CAAC,KAAe,EAAA;AAC7C,IAAA,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,IAAG;QACpB,IAAI,IAAI,GAAG,CAAC,EAAE;YACV,IAAI,IAAI,GAAG,CAAC;AACf,SAAA;AACD,QAAA,IAAI,UAAU,GAAG,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QACvD,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAClC,QAAA,OAAO,UAAU,CAAC;AACtB,KAAC,CAAC;AACG,SAAA,OAAO,EAAE;SACT,IAAI,CAAC,GAAG,CAAC,CAAA;AAClB;;AC7DA;;AAEG;;;;"}
@@ -1 +1 @@
1
- {"__symbolic":"module","version":4,"exports":[{"from":"./www/definitions"},{"from":"./www/parse-ndef-message"}],"metadata":{"NFCComProtocol":{"__symbolic":"class","extends":{"__symbolic":"reference","module":"@iotize/tap/protocol/core","name":"QueueComProtocol","line":24,"character":36},"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@iotize/tap/protocol/api","name":"ComProtocolOptions","line":26,"character":25}]}],"_connect":[{"__symbolic":"method"}],"_disconnect":[{"__symbolic":"method"}],"write":[{"__symbolic":"method"}],"read":[{"__symbolic":"method"}],"send":[{"__symbolic":"method"}],"_onConnectionLost":[{"__symbolic":"method"}]},"statics":{"iOSProtocol":{"__symbolic":"function","parameters":[],"value":{"__symbolic":"new","expression":{"__symbolic":"reference","name":"NFCComProtocol"},"arguments":[{"connect":{"timeout":10000},"disconnect":{"timeout":1000},"send":{"timeout":1000}}]}}}},"CordovaInterface":{"__symbolic":"interface"},"NfcError":{"__symbolic":"class","extends":{"__symbolic":"reference","name":"Error"},"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"select","expression":{"__symbolic":"reference","name":"NfcError"},"member":"ErrorCode"},{"__symbolic":"reference","name":"string"}]}]},"statics":{"tagLostError":{"__symbolic":"function","parameters":[],"value":{"__symbolic":"new","expression":{"__symbolic":"reference","name":"NfcError"},"arguments":[{"__symbolic":"select","expression":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"NfcError"},"member":"ErrorCode"},"member":"TagLostError"},"NFC tag lost"]}},"notConnectedError":{"__symbolic":"function","parameters":[],"value":{"__symbolic":"new","expression":{"__symbolic":"reference","name":"NfcError"},"arguments":[{"__symbolic":"select","expression":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"NfcError"},"member":"ErrorCode"},"member":"NotConnectedError"},"NFC tag is not connected"]}}}}},"origins":{"NFCComProtocol":"./www/nfc-com-protocol","CordovaInterface":"./www/cordova-interface","NfcError":"./www/errors"},"importAs":"@iotize/device-com-nfc.cordova"}
1
+ {"__symbolic":"module","version":4,"exports":[{"from":"./www/definitions"},{"from":"./www/parse-ndef-message"}],"metadata":{"NFCComProtocol":{"__symbolic":"class","extends":{"__symbolic":"reference","module":"@iotize/tap/protocol/core","name":"QueueComProtocol","line":20,"character":36},"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@iotize/tap/protocol/api","name":"ComProtocolOptions","line":22,"character":13}]}],"connect":[{"__symbolic":"method"}],"_connect":[{"__symbolic":"method"}],"_disconnect":[{"__symbolic":"method"}],"write":[{"__symbolic":"method"}],"read":[{"__symbolic":"method"}],"send":[{"__symbolic":"method"}],"_onConnectionLost":[{"__symbolic":"method"}]},"statics":{"iOSProtocol":{"__symbolic":"function","parameters":[],"value":{"__symbolic":"new","expression":{"__symbolic":"reference","name":"NFCComProtocol"},"arguments":[{"connect":{"timeout":10000},"disconnect":{"timeout":1000},"send":{"timeout":1000}}]}}}},"CordovaInterface":{"__symbolic":"interface"},"NfcError":{"__symbolic":"class","extends":{"__symbolic":"reference","name":"Error"},"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"select","expression":{"__symbolic":"reference","name":"NfcError"},"member":"ErrorCode"},{"__symbolic":"reference","name":"string"}]}]},"statics":{"tagLostError":{"__symbolic":"function","parameters":[],"value":{"__symbolic":"new","expression":{"__symbolic":"reference","name":"NfcError"},"arguments":[{"__symbolic":"select","expression":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"NfcError"},"member":"ErrorCode"},"member":"TagLostError"},"NFC tag lost"]}},"notConnectedError":{"__symbolic":"function","parameters":[],"value":{"__symbolic":"new","expression":{"__symbolic":"reference","name":"NfcError"},"arguments":[{"__symbolic":"select","expression":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"NfcError"},"member":"ErrorCode"},"member":"NotConnectedError"},"NFC tag is not connected"]}}}}},"origins":{"NFCComProtocol":"./www/nfc-com-protocol","CordovaInterface":"./www/cordova-interface","NfcError":"./www/errors"},"importAs":"@iotize/device-com-nfc.cordova"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@iotize/device-com-nfc.cordova",
3
3
  "main": "bundles/iotize-device-com-nfc.cordova.umd.js",
4
- "version": "3.1.3",
4
+ "version": "3.1.6",
5
5
  "description": "Near Field Communication (NFC) Plugin. Read and write NDEF messages to NFC tags and share NDEF messages with peers.",
6
6
  "cordova": {
7
7
  "id": "@iotize/device-com-nfc.cordova",
@@ -6,6 +6,7 @@ repositories{
6
6
  maven {
7
7
  // Add iotize repository url
8
8
  url "http://repo.iotize.com/artifactory/gradle-release"
9
+ allowInsecureProtocol = true
9
10
  }
10
11
  }
11
12
 
@@ -1093,27 +1093,12 @@ public class NfcPlugin extends CordovaPlugin implements NfcAdapter.OnNdefPushCom
1093
1093
 
1094
1094
  nfcProtocol.connect();
1095
1095
  setTimeout(timeout);
1096
- Log.d(TAG, "NFC Connection succesful");
1096
+ Log.d(TAG, "NFC Connection successful");
1097
1097
  callbackContext.success();
1098
-
1099
1098
  } catch (IOException ex) {
1100
1099
  Log.e(TAG, "Tag connection failed", ex);
1101
1100
  callbackContext.error("Tag connection failed");
1102
-
1103
- // Users should never get these reflection errors
1104
- } catch (ClassNotFoundException e) {
1105
- Log.e(TAG, e.getMessage(), e);
1106
- callbackContext.error(e.getMessage());
1107
- } catch (NoSuchMethodException e) {
1108
- Log.e(TAG, e.getMessage(), e);
1109
- callbackContext.error(e.getMessage());
1110
- } catch (IllegalAccessException e) {
1111
- Log.e(TAG, e.getMessage(), e);
1112
- callbackContext.error(e.getMessage());
1113
- } catch (InvocationTargetException e) {
1114
- Log.e(TAG, e.getMessage(), e);
1115
- callbackContext.error(e.getMessage());
1116
- } catch (Exception e) {
1101
+ } catch (Throwable e) {
1117
1102
  Log.e(TAG, e.getMessage(), e);
1118
1103
  callbackContext.error(e.getMessage());
1119
1104
  }
package/www/errors.d.ts CHANGED
@@ -4,6 +4,7 @@ export declare class NfcError extends Error {
4
4
  static tagLostError(): NfcError;
5
5
  static notConnectedError(): NfcError;
6
6
  static unknownError(errString: string): NfcError;
7
+ static tagConnectionFailed(): void;
7
8
  static internalError(message: string): void;
8
9
  }
9
10
  export declare namespace NfcError {
@@ -5,9 +5,30 @@ import { NfcError } from './errors';
5
5
  export declare class NFCComProtocol extends QueueComProtocol {
6
6
  constructor(options?: ComProtocolOptions);
7
7
  static iOSProtocol(): NFCComProtocol;
8
+ /**
9
+ * We force tag connection with nfc as we need to refresh tag
10
+ * @param options
11
+ * @returns
12
+ */
13
+ connect(options?: ComProtocolConnectOptions): Observable<void>;
14
+ /**
15
+ * Not used as we have rewrote "connect()" function
16
+ * @param options
17
+ * @returns
18
+ */
8
19
  _connect(options?: ComProtocolConnectOptions): Observable<any>;
9
20
  _disconnect(options?: ComProtocolDisconnectOptions): Observable<any>;
21
+ /**
22
+ * Not used
23
+ * @param options
24
+ * @returns
25
+ */
10
26
  write(data: Uint8Array): Promise<any>;
27
+ /**
28
+ * Not used
29
+ * @param options
30
+ * @returns
31
+ */
11
32
  read(): Promise<Uint8Array>;
12
33
  send(data: Uint8Array, options?: ComProtocolSendOptions): Observable<Uint8Array>;
13
34
  _onConnectionLost(error: NfcError): void;