@iotize/device-com-nfc.cordova 3.8.1 → 3.8.2

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.
Files changed (62) hide show
  1. package/LICENSE +30 -30
  2. package/README.md +673 -673
  3. package/bundles/iotize-device-com-nfc.cordova.umd.js +946 -967
  4. package/bundles/iotize-device-com-nfc.cordova.umd.js.map +1 -1
  5. package/bundles/iotize-device-com-nfc.cordova.umd.min.js +1 -1
  6. package/bundles/iotize-device-com-nfc.cordova.umd.min.js.map +1 -1
  7. package/esm2015/iotize-device-com-nfc.cordova.js +4 -4
  8. package/esm2015/public_api.js +1 -1
  9. package/esm2015/www/cordova-interface.js +1 -1
  10. package/esm2015/www/errors.js +30 -30
  11. package/esm2015/www/errors.js.map +1 -1
  12. package/esm2015/www/index.js +6 -6
  13. package/esm2015/www/index.js.map +1 -1
  14. package/esm2015/www/logger.js +2 -2
  15. package/esm2015/www/logger.js.map +1 -1
  16. package/esm2015/www/ndef/definitions.js +16 -16
  17. package/esm2015/www/ndef/definitions.js.map +1 -1
  18. package/esm2015/www/ndef/parse-ndef-message.js +164 -164
  19. package/esm2015/www/ndef/parse-ndef-message.js.map +1 -1
  20. package/esm2015/www/nfc-com-protocol.js +169 -169
  21. package/esm2015/www/tap-ndef/definitions.js +1 -1
  22. package/esm2015/www/tap-ndef/definitions.js.map +1 -1
  23. package/esm2015/www/tap-ndef/index.js +2 -2
  24. package/esm2015/www/tap-ndef/index.js.map +1 -1
  25. package/esm2015/www/tap-ndef/parse-ndef-message.js +51 -51
  26. package/esm2015/www/tap-ndef/parse-ndef-message.js.map +1 -1
  27. package/esm2015/www/utility.js +10 -10
  28. package/esm2015/www/utility.js.map +1 -1
  29. package/esm2015/www/utility.ngsummary.json +1 -1
  30. package/fesm2015/iotize-device-com-nfc.cordova.js +425 -425
  31. package/fesm2015/iotize-device-com-nfc.cordova.js.map +1 -1
  32. package/iotize-device-com-nfc.cordova.d.ts +4 -4
  33. package/package.json +1 -1
  34. package/public_api.d.ts +1 -1
  35. package/src/android/.gradle/4.10.1/fileChanges/last-build.bin +0 -0
  36. package/src/android/.gradle/4.10.1/fileHashes/fileHashes.bin +0 -0
  37. package/src/android/.gradle/4.10.1/fileHashes/fileHashes.lock +0 -0
  38. package/src/android/.gradle/4.10.1/gc.properties +0 -0
  39. package/src/android/.gradle/vcs-1/gc.properties +0 -0
  40. package/src/android/build.gradle +38 -38
  41. package/src/android/gradle/wrapper/gradle-wrapper.properties +6 -6
  42. package/src/android/gradlew +172 -172
  43. package/src/android/gradlew.bat +84 -84
  44. package/src/android/local.properties +8 -8
  45. package/src/android/src/com/chariotsolutions/nfc/plugin/JSONBuilder.java +60 -60
  46. package/src/android/src/com/chariotsolutions/nfc/plugin/NfcPlugin.java +92 -81
  47. package/src/android/src/com/chariotsolutions/nfc/plugin/NfcPluginError.java +15 -15
  48. package/src/android/src/com/chariotsolutions/nfc/plugin/PluginResponse.java +85 -85
  49. package/src/android/src/com/chariotsolutions/nfc/plugin/Util.java +140 -140
  50. package/src/ios/NFCTagReader.swift +32 -2
  51. package/src/ios/NFCTapPlugin.swift +57 -1
  52. package/www/cordova-interface.d.ts +34 -34
  53. package/www/errors.d.ts +17 -17
  54. package/www/index.d.ts +6 -6
  55. package/www/logger.d.ts +2 -2
  56. package/www/ndef/definitions.d.ts +15 -15
  57. package/www/ndef/parse-ndef-message.d.ts +69 -69
  58. package/www/nfc-com-protocol.d.ts +36 -36
  59. package/www/tap-ndef/definitions.d.ts +25 -25
  60. package/www/tap-ndef/index.d.ts +2 -2
  61. package/www/tap-ndef/parse-ndef-message.d.ts +6 -6
  62. package/www/utility.d.ts +2 -2
@@ -1,170 +1,170 @@
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';
11
- import { ConnectionState, } from '@iotize/tap/protocol/api';
12
- import { QueueComProtocol } from '@iotize/tap/protocol/core';
13
- import { defer } from 'rxjs';
14
- import { NfcError } from './errors';
15
- import { debug } from './logger';
16
- class PromiseQueue {
17
- constructor() {
18
- this.queue = Promise.resolve(true);
19
- }
20
- add(operation) {
21
- return new Promise((resolve, reject) => {
22
- this.queue = this.queue.then(operation).then(resolve).catch(reject);
23
- });
24
- }
25
- }
26
- export class NFCComProtocol extends QueueComProtocol {
27
- constructor(options = {
28
- connect: {
29
- timeout: 2000,
30
- },
31
- disconnect: {
32
- timeout: 1000,
33
- },
34
- send: {
35
- timeout: 1000,
36
- },
37
- }) {
38
- super();
39
- this._sendQueue = new PromiseQueue();
40
- this.options = options;
41
- if (typeof nfc == undefined) {
42
- console.warn('NFC plugin has not been setup properly. Global variable NFC does not exist');
43
- }
44
- }
45
- static iOSProtocol() {
46
- return new NFCComProtocol({
47
- connect: {
48
- timeout: 10000, // bigger timer on connect as connect launches a reading session
49
- },
50
- disconnect: {
51
- timeout: 1000,
52
- },
53
- send: {
54
- timeout: 1000,
55
- },
56
- });
57
- }
58
- /**
59
- * We force tag connection with nfc as we need to refresh tag
60
- * @param options
61
- * @returns
62
- */
63
- connect(options) {
64
- this.connectionState = ConnectionState.CONNECTING; // Hack to force NFC tag connect call even if we are already connected
65
- return super.connect(options);
66
- }
67
- /**
68
- * Not used as we have rewrote "connect()" function
69
- * @param options
70
- * @returns
71
- */
72
- _connect(options) {
73
- return defer(() => __awaiter(this, void 0, void 0, function* () {
74
- debug('_connect', options);
75
- try {
76
- yield nfc.connect('android.nfc.tech.NfcV', this.options.connect.timeout);
77
- }
78
- catch (err) {
79
- if (typeof err === 'string') {
80
- if (err === 'Tag connection failed') {
81
- throw NfcError.tagConnectionFailed();
82
- }
83
- else {
84
- throw NfcError.unknownError(err);
85
- }
86
- }
87
- throw err;
88
- }
89
- }));
90
- }
91
- _disconnect(options) {
92
- return defer(() => __awaiter(this, void 0, void 0, function* () {
93
- yield nfc.close();
94
- this._sendQueue = new PromiseQueue();
95
- }));
96
- }
97
- /**
98
- * Not used
99
- * @param options
100
- * @returns
101
- */
102
- write(data) {
103
- return __awaiter(this, void 0, void 0, function* () {
104
- throw new Error('Method not implemented.');
105
- });
106
- }
107
- /**
108
- * Not used
109
- * @param options
110
- * @returns
111
- */
112
- read() {
113
- return __awaiter(this, void 0, void 0, function* () {
114
- throw new Error('Method not implemented.');
115
- });
116
- }
117
- send(data, options) {
118
- return defer(() => __awaiter(this, void 0, void 0, function* () {
119
- return yield this._sendQueue.add(() => __awaiter(this, void 0, void 0, function* () {
120
- try {
121
- const response = yield nfc.transceiveTap(bufferToHexString(data));
122
- if (typeof response != 'string') {
123
- throw NfcError.internalError(`Internal error. Plugin should respond a hexadecimal string`);
124
- }
125
- debug('NFC plugin response: ', response);
126
- return hexStringToBuffer(response);
127
- }
128
- catch (errString) {
129
- if (typeof errString === 'string') {
130
- const error = stringToError(errString);
131
- if (error.code === NfcError.ErrorCode.NotConnectedError ||
132
- error.code === NfcError.ErrorCode.TagLostError) {
133
- this._onConnectionLost(error);
134
- }
135
- throw error;
136
- }
137
- else {
138
- throw errString;
139
- }
140
- }
141
- }));
142
- }));
143
- }
144
- _onConnectionLost(error) {
145
- if (this.connectionState !== ConnectionState.DISCONNECTED) {
146
- this.setConnectionState(ConnectionState.DISCONNECTED);
147
- }
148
- }
149
- }
150
- /**
151
- * Convert error string returned by the plugin into an error object
152
- * It only checks a few Android error string for now
153
- *
154
- * TODO complete implementation with other error types
155
- *
156
- * @param errString
157
- */
158
- function stringToError(errString) {
159
- const errStringLc = errString.toLowerCase();
160
- if (errStringLc.indexOf('tag was lost') >= 0) {
161
- return NfcError.tagLostError();
162
- }
163
- else if (errStringLc.indexOf('not connected') >= 0) {
164
- return NfcError.notConnectedError();
165
- }
166
- else {
167
- return NfcError.unknownError(errString);
168
- }
169
- }
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';
11
+ import { ConnectionState, } from '@iotize/tap/protocol/api';
12
+ import { QueueComProtocol } from '@iotize/tap/protocol/core';
13
+ import { defer } from 'rxjs';
14
+ import { NfcError } from './errors';
15
+ import { debug } from './logger';
16
+ class PromiseQueue {
17
+ constructor() {
18
+ this.queue = Promise.resolve(true);
19
+ }
20
+ add(operation) {
21
+ return new Promise((resolve, reject) => {
22
+ this.queue = this.queue.then(operation).then(resolve).catch(reject);
23
+ });
24
+ }
25
+ }
26
+ export class NFCComProtocol extends QueueComProtocol {
27
+ constructor(options = {
28
+ connect: {
29
+ timeout: 2000,
30
+ },
31
+ disconnect: {
32
+ timeout: 1000,
33
+ },
34
+ send: {
35
+ timeout: 1000,
36
+ },
37
+ }) {
38
+ super();
39
+ this._sendQueue = new PromiseQueue();
40
+ this.options = options;
41
+ if (typeof nfc == undefined) {
42
+ console.warn('NFC plugin has not been setup properly. Global variable NFC does not exist');
43
+ }
44
+ }
45
+ static iOSProtocol() {
46
+ return new NFCComProtocol({
47
+ connect: {
48
+ timeout: 10000, // bigger timer on connect as connect launches a reading session
49
+ },
50
+ disconnect: {
51
+ timeout: 1000,
52
+ },
53
+ send: {
54
+ timeout: 1000,
55
+ },
56
+ });
57
+ }
58
+ /**
59
+ * We force tag connection with nfc as we need to refresh tag
60
+ * @param options
61
+ * @returns
62
+ */
63
+ connect(options) {
64
+ this.connectionState = ConnectionState.CONNECTING; // Hack to force NFC tag connect call even if we are already connected
65
+ return super.connect(options);
66
+ }
67
+ /**
68
+ * Not used as we have rewrote "connect()" function
69
+ * @param options
70
+ * @returns
71
+ */
72
+ _connect(options) {
73
+ return defer(() => __awaiter(this, void 0, void 0, function* () {
74
+ debug('_connect', options);
75
+ try {
76
+ yield nfc.connect('android.nfc.tech.NfcV', this.options.connect.timeout);
77
+ }
78
+ catch (err) {
79
+ if (typeof err === 'string') {
80
+ if (err === 'Tag connection failed') {
81
+ throw NfcError.tagConnectionFailed();
82
+ }
83
+ else {
84
+ throw NfcError.unknownError(err);
85
+ }
86
+ }
87
+ throw err;
88
+ }
89
+ }));
90
+ }
91
+ _disconnect(options) {
92
+ return defer(() => __awaiter(this, void 0, void 0, function* () {
93
+ yield nfc.close();
94
+ this._sendQueue = new PromiseQueue();
95
+ }));
96
+ }
97
+ /**
98
+ * Not used
99
+ * @param options
100
+ * @returns
101
+ */
102
+ write(data) {
103
+ return __awaiter(this, void 0, void 0, function* () {
104
+ throw new Error('Method not implemented.');
105
+ });
106
+ }
107
+ /**
108
+ * Not used
109
+ * @param options
110
+ * @returns
111
+ */
112
+ read() {
113
+ return __awaiter(this, void 0, void 0, function* () {
114
+ throw new Error('Method not implemented.');
115
+ });
116
+ }
117
+ send(data, options) {
118
+ return defer(() => __awaiter(this, void 0, void 0, function* () {
119
+ return yield this._sendQueue.add(() => __awaiter(this, void 0, void 0, function* () {
120
+ try {
121
+ const response = yield nfc.transceiveTap(bufferToHexString(data));
122
+ if (typeof response != 'string') {
123
+ throw NfcError.internalError(`Internal error. Plugin should respond a hexadecimal string`);
124
+ }
125
+ debug('NFC plugin response: ', response);
126
+ return hexStringToBuffer(response);
127
+ }
128
+ catch (errString) {
129
+ if (typeof errString === 'string') {
130
+ const error = stringToError(errString);
131
+ if (error.code === NfcError.ErrorCode.NotConnectedError ||
132
+ error.code === NfcError.ErrorCode.TagLostError) {
133
+ this._onConnectionLost(error);
134
+ }
135
+ throw error;
136
+ }
137
+ else {
138
+ throw errString;
139
+ }
140
+ }
141
+ }));
142
+ }));
143
+ }
144
+ _onConnectionLost(error) {
145
+ if (this.connectionState !== ConnectionState.DISCONNECTED) {
146
+ this.setConnectionState(ConnectionState.DISCONNECTED);
147
+ }
148
+ }
149
+ }
150
+ /**
151
+ * Convert error string returned by the plugin into an error object
152
+ * It only checks a few Android error string for now
153
+ *
154
+ * TODO complete implementation with other error types
155
+ *
156
+ * @param errString
157
+ */
158
+ function stringToError(errString) {
159
+ const errStringLc = errString.toLowerCase();
160
+ if (errStringLc.indexOf('tag was lost') >= 0) {
161
+ return NfcError.tagLostError();
162
+ }
163
+ else if (errStringLc.indexOf('not connected') >= 0) {
164
+ return NfcError.notConnectedError();
165
+ }
166
+ else {
167
+ return NfcError.unknownError(errString);
168
+ }
169
+ }
170
170
  //# sourceMappingURL=nfc-com-protocol.js.map
@@ -1,2 +1,2 @@
1
- export {};
1
+ export {};
2
2
  //# sourceMappingURL=definitions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../../../../../src/www/tap-ndef/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface TapNfcTagPayload {\n type?: number;\n name?: string;\n aar?: string;\n uri?: string;\n macAddress?: string;\n ssid?: string;\n}\n\nexport interface NdefEvent {\n tag: NdefTag;\n}\nexport interface NdefRecord {\n id: any[];\n payload: number[];\n tnf: number;\n type: number[];\n}\nexport interface NdefTag {\n canMakeReadOnly: boolean;\n id: number[];\n isWritable: boolean;\n maxSize: number;\n ndefMessage: NdefRecord[];\n techTypes: string[];\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../../../../../src/www/tap-ndef/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface TapNfcTagPayload {\r\n type?: number;\r\n name?: string;\r\n aar?: string;\r\n uri?: string;\r\n macAddress?: string;\r\n ssid?: string;\r\n}\r\n\r\nexport interface NdefEvent {\r\n tag: NdefTag;\r\n}\r\nexport interface NdefRecord {\r\n id: any[];\r\n payload: number[];\r\n tnf: number;\r\n type: number[];\r\n}\r\nexport interface NdefTag {\r\n canMakeReadOnly: boolean;\r\n id: number[];\r\n isWritable: boolean;\r\n maxSize: number;\r\n ndefMessage: NdefRecord[];\r\n techTypes: string[];\r\n}\r\n"]}
@@ -1,3 +1,3 @@
1
- export * from './definitions';
2
- export * from './parse-ndef-message';
1
+ export * from './definitions';
2
+ export * from './parse-ndef-message';
3
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/www/tap-ndef/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC","sourcesContent":["export * from './definitions';\nexport * from './parse-ndef-message';"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/www/tap-ndef/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC","sourcesContent":["export * from './definitions';\r\nexport * from './parse-ndef-message';"]}
@@ -1,52 +1,52 @@
1
- import { toAsciiString } from '../utility';
2
- /**
3
- * We manage only on NDEF message with 3 records:
4
- * record 0 = URI; record 1 = AAR; record 2 = BLE MAC ADDRESS / BSSID; record 3: universal link
5
- */
6
- export function parseTapNdefMessage(messages) {
7
- let result = {};
8
- if (messages.length >= 1) {
9
- let asciiUri = messages[0].payload;
10
- result.uri = toAsciiString(asciiUri);
11
- }
12
- if (messages.length >= 2) {
13
- result.aar = toAsciiString(messages[1].payload);
14
- }
15
- if (messages.length >= 3) {
16
- let payload3 = messages[2].payload;
17
- let type = payload3[0];
18
- let content = payload3.slice(1);
19
- result.type = type;
20
- switch (type) {
21
- case TapNdefProtocolType.BLE:
22
- result.macAddress = convertBytesToBLEAddress(content);
23
- break;
24
- case TapNdefProtocolType.WiFi:
25
- result.ssid = toAsciiString(content);
26
- break;
27
- }
28
- }
29
- if (messages.length >= 4) {
30
- result.name = toAsciiString(messages[3].payload);
31
- }
32
- return result;
33
- }
34
- var TapNdefProtocolType;
35
- (function (TapNdefProtocolType) {
36
- TapNdefProtocolType[TapNdefProtocolType["WiFi"] = 32] = "WiFi";
37
- TapNdefProtocolType[TapNdefProtocolType["BLE"] = 64] = "BLE";
38
- })(TapNdefProtocolType || (TapNdefProtocolType = {}));
39
- function convertBytesToBLEAddress(bytes) {
40
- return bytes
41
- .map((byte) => {
42
- if (byte < 0) {
43
- byte += 256;
44
- }
45
- let byteString = '0' + byte.toString(16).toUpperCase();
46
- byteString = byteString.slice(-2);
47
- return byteString;
48
- })
49
- .reverse()
50
- .join(':');
51
- }
1
+ import { toAsciiString } from '../utility';
2
+ /**
3
+ * We manage only on NDEF message with 3 records:
4
+ * record 0 = URI; record 1 = AAR; record 2 = BLE MAC ADDRESS / BSSID; record 3: universal link
5
+ */
6
+ export function parseTapNdefMessage(messages) {
7
+ let result = {};
8
+ if (messages.length >= 1) {
9
+ let asciiUri = messages[0].payload;
10
+ result.uri = toAsciiString(asciiUri);
11
+ }
12
+ if (messages.length >= 2) {
13
+ result.aar = toAsciiString(messages[1].payload);
14
+ }
15
+ if (messages.length >= 3) {
16
+ let payload3 = messages[2].payload;
17
+ let type = payload3[0];
18
+ let content = payload3.slice(1);
19
+ result.type = type;
20
+ switch (type) {
21
+ case TapNdefProtocolType.BLE:
22
+ result.macAddress = convertBytesToBLEAddress(content);
23
+ break;
24
+ case TapNdefProtocolType.WiFi:
25
+ result.ssid = toAsciiString(content);
26
+ break;
27
+ }
28
+ }
29
+ if (messages.length >= 4) {
30
+ result.name = toAsciiString(messages[3].payload);
31
+ }
32
+ return result;
33
+ }
34
+ var TapNdefProtocolType;
35
+ (function (TapNdefProtocolType) {
36
+ TapNdefProtocolType[TapNdefProtocolType["WiFi"] = 32] = "WiFi";
37
+ TapNdefProtocolType[TapNdefProtocolType["BLE"] = 64] = "BLE";
38
+ })(TapNdefProtocolType || (TapNdefProtocolType = {}));
39
+ function convertBytesToBLEAddress(bytes) {
40
+ return bytes
41
+ .map((byte) => {
42
+ if (byte < 0) {
43
+ byte += 256;
44
+ }
45
+ let byteString = '0' + byte.toString(16).toUpperCase();
46
+ byteString = byteString.slice(-2);
47
+ return byteString;
48
+ })
49
+ .reverse()
50
+ .join(':');
51
+ }
52
52
  //# sourceMappingURL=parse-ndef-message.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-ndef-message.js","sourceRoot":"","sources":["../../../../../../src/www/tap-ndef/parse-ndef-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG3C;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAsB;IACxD,IAAI,MAAM,GAAqB,EAAE,CAAC;IAClC,IAAI,QAAQ,CAAC,MAAM,IAAI,CAAC,EAAE;QACxB,IAAI,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QACnC,MAAM,CAAC,GAAG,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;KACtC;IACD,IAAI,QAAQ,CAAC,MAAM,IAAI,CAAC,EAAE;QACxB,MAAM,CAAC,GAAG,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;KACjD;IACD,IAAI,QAAQ,CAAC,MAAM,IAAI,CAAC,EAAE;QACxB,IAAI,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QACnC,IAAI,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;QACvB,IAAI,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAChC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC;QAEnB,QAAQ,IAAI,EAAE;YACZ,KAAK,mBAAmB,CAAC,GAAG;gBAC1B,MAAM,CAAC,UAAU,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAC;gBACtD,MAAM;YACR,KAAK,mBAAmB,CAAC,IAAI;gBAC3B,MAAM,CAAC,IAAI,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;gBACrC,MAAM;SACT;KACF;IACD,IAAI,QAAQ,CAAC,MAAM,IAAI,CAAC,EAAE;QACxB,MAAM,CAAC,IAAI,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;KAClD;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,IAAK,mBAGJ;AAHD,WAAK,mBAAmB;IACtB,8DAAW,CAAA;IACX,4DAAU,CAAA;AACZ,CAAC,EAHI,mBAAmB,KAAnB,mBAAmB,QAGvB;AAED,SAAS,wBAAwB,CAAC,KAAe;IAC/C,OAAO,KAAK;SACT,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACZ,IAAI,IAAI,GAAG,CAAC,EAAE;YACZ,IAAI,IAAI,GAAG,CAAC;SACb;QACD,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;QAClC,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;SACD,OAAO,EAAE;SACT,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC","sourcesContent":["import { toAsciiString } from '../utility';\nimport { NdefRecord, TapNfcTagPayload } from './definitions';\n\n/**\n * We manage only on NDEF message with 3 records:\n * record 0 = URI; record 1 = AAR; record 2 = BLE MAC ADDRESS / BSSID; record 3: universal link\n */\nexport function parseTapNdefMessage(messages: NdefRecord[]): TapNfcTagPayload {\n let result: TapNfcTagPayload = {};\n if (messages.length >= 1) {\n let asciiUri = messages[0].payload;\n result.uri = toAsciiString(asciiUri);\n }\n if (messages.length >= 2) {\n result.aar = toAsciiString(messages[1].payload);\n }\n if (messages.length >= 3) {\n let payload3 = messages[2].payload;\n let type = payload3[0];\n let content = payload3.slice(1);\n result.type = type;\n\n switch (type) {\n case TapNdefProtocolType.BLE:\n result.macAddress = convertBytesToBLEAddress(content);\n break;\n case TapNdefProtocolType.WiFi:\n result.ssid = toAsciiString(content);\n break;\n }\n }\n if (messages.length >= 4) {\n result.name = toAsciiString(messages[3].payload);\n }\n return result;\n}\n\nenum TapNdefProtocolType {\n WiFi = 0x20,\n BLE = 0x40,\n}\n\nfunction convertBytesToBLEAddress(bytes: number[]): string {\n return bytes\n .map((byte) => {\n if (byte < 0) {\n byte += 256;\n }\n let byteString = '0' + byte.toString(16).toUpperCase();\n byteString = byteString.slice(-2);\n return byteString;\n })\n .reverse()\n .join(':');\n}\n"]}
1
+ {"version":3,"file":"parse-ndef-message.js","sourceRoot":"","sources":["../../../../../../src/www/tap-ndef/parse-ndef-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG3C;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAsB;IACxD,IAAI,MAAM,GAAqB,EAAE,CAAC;IAClC,IAAI,QAAQ,CAAC,MAAM,IAAI,CAAC,EAAE;QACxB,IAAI,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QACnC,MAAM,CAAC,GAAG,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;KACtC;IACD,IAAI,QAAQ,CAAC,MAAM,IAAI,CAAC,EAAE;QACxB,MAAM,CAAC,GAAG,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;KACjD;IACD,IAAI,QAAQ,CAAC,MAAM,IAAI,CAAC,EAAE;QACxB,IAAI,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QACnC,IAAI,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;QACvB,IAAI,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAChC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC;QAEnB,QAAQ,IAAI,EAAE;YACZ,KAAK,mBAAmB,CAAC,GAAG;gBAC1B,MAAM,CAAC,UAAU,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAC;gBACtD,MAAM;YACR,KAAK,mBAAmB,CAAC,IAAI;gBAC3B,MAAM,CAAC,IAAI,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;gBACrC,MAAM;SACT;KACF;IACD,IAAI,QAAQ,CAAC,MAAM,IAAI,CAAC,EAAE;QACxB,MAAM,CAAC,IAAI,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;KAClD;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,IAAK,mBAGJ;AAHD,WAAK,mBAAmB;IACtB,8DAAW,CAAA;IACX,4DAAU,CAAA;AACZ,CAAC,EAHI,mBAAmB,KAAnB,mBAAmB,QAGvB;AAED,SAAS,wBAAwB,CAAC,KAAe;IAC/C,OAAO,KAAK;SACT,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACZ,IAAI,IAAI,GAAG,CAAC,EAAE;YACZ,IAAI,IAAI,GAAG,CAAC;SACb;QACD,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;QAClC,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;SACD,OAAO,EAAE;SACT,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC","sourcesContent":["import { toAsciiString } from '../utility';\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 convertBytesToBLEAddress(bytes: number[]): string {\r\n return bytes\r\n .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"]}
@@ -1,11 +1,11 @@
1
- import { bufferToAsciiString } from '@iotize/common/byte-converter';
2
- export function toAsciiString(payload) {
3
- if (payload.length > 0 && payload[0] === 0) {
4
- payload = payload.slice(1);
5
- }
6
- return bufferToAsciiString(payload);
7
- }
8
- export function arrayEquals(a1, a2) {
9
- return (a1.length === a2.length && a1.every((a1Item, index) => a1Item === a2[index]));
10
- }
1
+ import { bufferToAsciiString } from '@iotize/common/byte-converter';
2
+ export function toAsciiString(payload) {
3
+ if (payload.length > 0 && payload[0] === 0) {
4
+ payload = payload.slice(1);
5
+ }
6
+ return bufferToAsciiString(payload);
7
+ }
8
+ export function arrayEquals(a1, a2) {
9
+ return (a1.length === a2.length && a1.every((a1Item, index) => a1Item === a2[index]));
10
+ }
11
11
  //# sourceMappingURL=utility.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utility.js","sourceRoot":"","sources":["../../../../../src/www/utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAEpE,MAAM,UAAU,aAAa,CAAC,OAAiB;IAC7C,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE;QAC1C,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KAC5B;IACD,OAAO,mBAAmB,CAAC,OAA4B,CAAC,CAAC;AAC3D,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,EAAY,EAAE,EAAY;IACpD,OAAO,CACL,EAAE,CAAC,MAAM,KAAK,EAAE,CAAC,MAAM,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,MAAM,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,CAC7E,CAAC;AACJ,CAAC","sourcesContent":["import { bufferToAsciiString } from '@iotize/common/byte-converter';\n\nexport function toAsciiString(payload: number[]): string {\n if (payload.length > 0 && payload[0] === 0) {\n payload = payload.slice(1);\n }\n return bufferToAsciiString(payload as any as Uint8Array);\n}\n\nexport function arrayEquals(a1: number[], a2: number[]) {\n return (\n a1.length === a2.length && a1.every((a1Item, index) => a1Item === a2[index])\n );\n}\n"]}
1
+ {"version":3,"file":"utility.js","sourceRoot":"","sources":["../../../../../src/www/utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAEpE,MAAM,UAAU,aAAa,CAAC,OAAiB;IAC7C,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE;QAC1C,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KAC5B;IACD,OAAO,mBAAmB,CAAC,OAA4B,CAAC,CAAC;AAC3D,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,EAAY,EAAE,EAAY;IACpD,OAAO,CACL,EAAE,CAAC,MAAM,KAAK,EAAE,CAAC,MAAM,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,MAAM,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,CAC7E,CAAC;AACJ,CAAC","sourcesContent":["import { bufferToAsciiString } from '@iotize/common/byte-converter';\r\n\r\nexport function 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\nexport function arrayEquals(a1: number[], a2: number[]) {\r\n return (\r\n a1.length === a2.length && a1.every((a1Item, index) => a1Item === a2[index])\r\n );\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"moduleName":null,"summaries":[{"symbol":{"__symbol":0,"members":[]},"metadata":{"__symbolic":"function"}},{"symbol":{"__symbol":1,"members":[]},"metadata":{"__symbolic":"function","parameters":["a1","a2"],"value":{"__symbolic":"binop","operator":"&&","left":{"__symbolic":"binop","operator":"===","left":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"a1"},"member":"length"},"right":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"a2"},"member":"length"}},"right":{"__symbolic":"call","expression":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"a1"},"member":"every"},"arguments":[{"__symbolic":"error","message":"Lambda not supported","fileName":"src/www/utility.ts"}]}}}}],"symbols":[{"__symbol":0,"name":"toAsciiString","filePath":"./utility"},{"__symbol":1,"name":"arrayEquals","filePath":"./utility"}]}
1
+ {"moduleName":null,"summaries":[{"symbol":{"__symbol":0,"members":[]},"metadata":{"__symbolic":"function"}},{"symbol":{"__symbol":1,"members":[]},"metadata":{"__symbolic":"function","parameters":["a1","a2"],"value":{"__symbolic":"binop","operator":"&&","left":{"__symbolic":"binop","operator":"===","left":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"a1"},"member":"length"},"right":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"a2"},"member":"length"}},"right":{"__symbolic":"call","expression":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"a1"},"member":"every"},"arguments":[{"__symbolic":"error","message":"Lambda not supported","fileName":"src\\www\\utility.ts"}]}}}}],"symbols":[{"__symbol":0,"name":"toAsciiString","filePath":"./utility"},{"__symbol":1,"name":"arrayEquals","filePath":"./utility"}]}