@iotize/device-com-nfc.cordova 3.9.4 → 3.10.0
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.
- package/bundles/iotize-device-com-nfc.cordova.umd.js +1150 -1103
- package/bundles/iotize-device-com-nfc.cordova.umd.js.map +1 -1
- package/bundles/iotize-device-com-nfc.cordova.umd.min.js +1 -1
- package/bundles/iotize-device-com-nfc.cordova.umd.min.js.map +1 -1
- package/esm2015/iotize-device-com-nfc.cordova.ngsummary.json +1 -1
- package/esm2015/public_api.ngsummary.json +1 -1
- package/esm2015/www/cordova-interface.js +15 -1
- package/esm2015/www/cordova-interface.js.map +1 -1
- package/esm2015/www/cordova-interface.metadata.json +1 -1
- package/esm2015/www/cordova-interface.ngsummary.json +1 -1
- package/esm2015/www/index.ngsummary.json +1 -1
- package/esm2015/www/ndef/parse-ndef-message.js +7 -6
- package/esm2015/www/ndef/parse-ndef-message.js.map +1 -1
- package/esm2015/www/nfc-com-protocol.js +25 -2
- package/esm2015/www/nfc-com-protocol.js.map +1 -1
- package/esm2015/www/nfc-com-protocol.metadata.json +1 -1
- package/fesm2015/iotize-device-com-nfc.cordova.js +48 -9
- package/fesm2015/iotize-device-com-nfc.cordova.js.map +1 -1
- package/iotize-device-com-nfc.cordova.metadata.json +1 -1
- package/package.json +1 -1
- package/plugin.xml +7 -4
- package/src/android/.gradle/4.10.1/fileHashes/fileHashes.bin +0 -0
- package/src/android/.gradle/4.10.1/fileHashes/fileHashes.lock +0 -0
- package/src/android/src/com/chariotsolutions/nfc/plugin/NFC4Protocol.java +78 -0
- package/src/android/src/com/chariotsolutions/nfc/plugin/NFC5Protocol.java +513 -0
- package/src/android/src/com/chariotsolutions/nfc/plugin/NFCIntentParser.java +186 -0
- package/src/android/src/com/chariotsolutions/nfc/plugin/NFCProtocol.java +104 -0
- package/src/android/src/com/chariotsolutions/nfc/plugin/NFCProtocolFactory.java +64 -0
- package/src/android/src/com/chariotsolutions/nfc/plugin/NfcPlugin.java +72 -19
- package/src/ios/NFCPlugin-Bridging-Header.h +1 -1
- package/www/cordova-interface.d.ts +15 -0
- package/www/phonegap-nfc.js +12 -0
|
@@ -1 +1 @@
|
|
|
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;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAIjC,MAAM,YAAY;IAAlB;QACE,UAAK,GAAG,OAAO,CAAC,OAAO,CAAM,IAAI,CAAC,CAAC;IAOrC,CAAC;IALC,GAAG,CAAI,SAA2B;QAChC,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACxC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACtE,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,OAAO,cAAe,SAAQ,gBAAgB;IAClD,YACE,UAA8B;QAC5B,OAAO,EAAE;YACP,OAAO,EAAE,IAAI;SACd;QACD,UAAU,EAAE;YACV,OAAO,EAAE,IAAI;SACd;QACD,IAAI,EAAE;YACJ,OAAO,EAAE,IAAI;SACd;KACF;QAED,KAAK,EAAE,CAAC;QAuBF,eAAU,GAAG,IAAI,YAAY,EAAE,CAAC;QAtBtC,IAAI,CAAC,OAAO,GAAG,OAAO,CA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AC,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 {\n bufferToHexString,\n hexStringToBuffer,\n} from '@iotize/common/byte-converter';\nimport {\n ComProtocolConnectOptions,\n ComProtocolDisconnectOptions,\n ComProtocolOptions,\n ComProtocolSendOptions,\n ConnectionState,\n} from '@iotize/tap/protocol/api';\nimport { QueueComProtocol } from '@iotize/tap/protocol/core';\nimport { defer, Observable } from 'rxjs';\n\nimport { CordovaInterface } from './cordova-interface';\nimport { NfcError } from './errors';\nimport { debug } from './logger';\n\ndeclare var nfc: CordovaInterface;\n\nclass PromiseQueue {\n queue = Promise.resolve<any>(true);\n\n add<T>(operation: () => Promise<T>): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n this.queue = this.queue.then(operation).then(resolve).catch(reject);\n });\n }\n}\n\nexport class NFCComProtocol extends QueueComProtocol {\n constructor(\n options: ComProtocolOptions = {\n connect: {\n timeout: 2000,\n },\n disconnect: {\n timeout: 1000,\n },\n send: {\n timeout: 1000,\n },\n }\n ) {\n super();\n this.options = options;\n if (typeof nfc == undefined) {\n console.warn(\n 'NFC plugin has not been setup properly. Global variable NFC does not exist'\n );\n }\n }\n\n public static iOSProtocol(): NFCComProtocol {\n return new NFCComProtocol({\n connect: {\n timeout: 10000, // bigger timer on connect as connect launches a reading session\n },\n disconnect: {\n timeout: 1000,\n },\n send: {\n timeout: 1000,\n },\n });\n }\n\n private _sendQueue = new PromiseQueue();\n\n /**\n * We force tag connection with nfc as we need to refresh tag\n * @param options\n * @returns\n */\n connect(options?: ComProtocolConnectOptions): Observable<void> {\n this.connectionState = ConnectionState.CONNECTING; // Hack to force NFC tag connect call even if we are already connected\n return super.connect(options);\n }\n\n /**\n * Not used as we have rewrote \"connect()\" function\n * @param options\n * @returns\n */\n _connect(options?: ComProtocolConnectOptions): Observable<any> {\n return defer(async () => {\n debug('_connect', options);\n try {\n await nfc.connect(\n 'android.nfc.tech.NfcV',\n this.options.connect.timeout\n );\n } catch (err) {\n if (typeof err === 'string') {\n if (err === 'Tag connection failed') {\n throw NfcError.tagConnectionFailed();\n } else {\n throw NfcError.unknownError(err);\n }\n }\n throw err;\n }\n });\n }\n\n _disconnect(options?: ComProtocolDisconnectOptions): Observable<any> {\n return defer(async () => {\n await nfc.close();\n this._sendQueue = new PromiseQueue();\n });\n }\n\n /**\n * Not used\n * @param options\n * @returns\n */\n async write(data: Uint8Array): Promise<any> {\n throw new Error('Method not implemented.');\n }\n\n /**\n * Not used\n * @param options\n * @returns\n */\n async read(): Promise<Uint8Array> {\n throw new Error('Method not implemented.');\n }\n\n send(\n data: Uint8Array,\n options?: ComProtocolSendOptions\n ): Observable<Uint8Array> {\n return defer(async () => {\n return await this._sendQueue.add(async () => {\n try {\n const response = await nfc.transceiveTap(bufferToHexString(data));\n if (typeof response != 'string') {\n throw NfcError.internalError(\n `Internal error. Plugin should respond a hexadecimal string`\n );\n }\n debug('NFC plugin response: ', response);\n return hexStringToBuffer(response);\n } catch (errString) {\n if (typeof errString === 'string') {\n const error = stringToError(errString);\n if (\n error.code === NfcError.ErrorCode.NotConnectedError ||\n error.code === NfcError.ErrorCode.TagLostError\n ) {\n this._onConnectionLost(error);\n }\n throw error;\n } else {\n throw errString;\n }\n }\n });\n });\n }\n\n _onConnectionLost(error: NfcError) {\n if (this.connectionState !== ConnectionState.DISCONNECTED) {\n this.setConnectionState(ConnectionState.DISCONNECTED);\n }\n }\n}\n\n/**\n * Convert error string returned by the plugin into an error object\n * It only checks a few Android error string for now\n *\n * TODO complete implementation with other error types\n *\n * @param errString\n */\nfunction stringToError(errString: string): NfcError {\n const errStringLc = errString.toLowerCase();\n if (errStringLc.indexOf('tag was lost') >= 0) {\n return NfcError.tagLostError();\n } else if (errStringLc.indexOf('not connected') >= 0) {\n return NfcError.notConnectedError();\n } else {\n return NfcError.unknownError(errString);\n }\n}\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,EAAc,KAAK,EAAc,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAEhF,OAAO,EACL,wBAAwB,GAEzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAIjC,MAAM,YAAY;IAAlB;QACE,UAAK,GAAG,OAAO,CAAC,OAAO,CAAM,IAAI,CAAC,CAAC;IAOrC,CAAC;IALC,GAAG,CAAI,SAA2B;QAChC,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACxC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAA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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 {\n bufferToHexString,\n hexStringToBuffer,\n} from '@iotize/common/byte-converter';\nimport {\n ComProtocolConnectOptions,\n ComProtocolDisconnectOptions,\n ComProtocolOptions,\n ComProtocolSendOptions,\n ConnectionState,\n} from '@iotize/tap/protocol/api';\nimport { QueueComProtocol } from '@iotize/tap/protocol/core';\nimport { catchError, defer, Observable, of, switchMap, throwError } from 'rxjs';\n\nimport {\n CheckTapConnectionResult,\n CordovaInterface,\n} from './cordova-interface';\nimport { NfcError } from './errors';\nimport { debug } from './logger';\n\ndeclare var nfc: CordovaInterface;\n\nclass PromiseQueue {\n queue = Promise.resolve<any>(true);\n\n add<T>(operation: () => Promise<T>): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n this.queue = this.queue.then(operation).then(resolve).catch(reject);\n });\n }\n}\n\nexport class NFCComProtocol extends QueueComProtocol {\n constructor(\n options: ComProtocolOptions = {\n connect: {\n timeout: 2000,\n },\n disconnect: {\n timeout: 1000,\n },\n send: {\n timeout: 1000,\n },\n }\n ) {\n super();\n this.options = options;\n if (typeof nfc == undefined) {\n console.warn(\n 'NFC plugin has not been setup properly. Global variable NFC does not exist'\n );\n }\n }\n\n public static iOSProtocol(): NFCComProtocol {\n return new NFCComProtocol({\n connect: {\n timeout: 10000, // bigger timer on connect as connect launches a reading session\n },\n disconnect: {\n timeout: 1000,\n },\n send: {\n timeout: 1000,\n },\n });\n }\n\n private _sendQueue = new PromiseQueue();\n\n /**\n * We force tag connection with nfc as we need to refresh tag\n * @param options\n * @returns\n */\n connect(options?: ComProtocolConnectOptions): Observable<void> {\n if (this.connectionState === ConnectionState.CONNECTED) {\n return defer(async () => {\n try {\n return await nfc.checkTapConnection(this.options.connect.timeout);\n } catch (err) {\n this.setConnectionState(ConnectionState.DISCONNECTED);\n throw err;\n }\n }).pipe(\n switchMap((connectionCheckState) => {\n switch (connectionCheckState) {\n case CheckTapConnectionResult.IN_RANGE_READY:\n return of(undefined);\n case CheckTapConnectionResult.IN_RANGE_BUT_LEFT_FIELD:\n this.setConnectionState(ConnectionState.CONNECTING);\n return super.connect(options);\n case CheckTapConnectionResult.NOT_IN_RANGE:\n default:\n this.setConnectionState(ConnectionState.DISCONNECTED);\n return throwError(() => NfcError.tagLostError());\n }\n })\n );\n }\n return super.connect(options);\n }\n\n /**\n * Not used as we have rewrote \"connect()\" function\n * @param options\n * @returns\n */\n _connect(options?: ComProtocolConnectOptions): Observable<any> {\n return defer(async () => {\n debug('_connect', options);\n try {\n await nfc.connect(\n 'android.nfc.tech.NfcV',\n this.options.connect.timeout\n );\n } catch (err) {\n if (typeof err === 'string') {\n if (err === 'Tag connection failed') {\n throw NfcError.tagConnectionFailed();\n } else {\n throw NfcError.unknownError(err);\n }\n }\n throw err;\n }\n });\n }\n\n _disconnect(options?: ComProtocolDisconnectOptions): Observable<any> {\n return defer(async () => {\n await nfc.close();\n this._sendQueue = new PromiseQueue();\n });\n }\n\n /**\n * Not used\n * @param options\n * @returns\n */\n async write(data: Uint8Array): Promise<any> {\n throw new Error('Method not implemented.');\n }\n\n /**\n * Not used\n * @param options\n * @returns\n */\n async read(): Promise<Uint8Array> {\n throw new Error('Method not implemented.');\n }\n\n send(\n data: Uint8Array,\n options?: ComProtocolSendOptions\n ): Observable<Uint8Array> {\n return defer(async () => {\n return await this._sendQueue.add(async () => {\n try {\n const response = await nfc.transceiveTap(bufferToHexString(data));\n if (typeof response != 'string') {\n throw NfcError.internalError(\n `Internal error. Plugin should respond a hexadecimal string`\n );\n }\n debug('NFC plugin response: ', response);\n return hexStringToBuffer(response);\n } catch (errString) {\n if (typeof errString === 'string') {\n const error = stringToError(errString);\n if (\n error.code === NfcError.ErrorCode.NotConnectedError ||\n error.code === NfcError.ErrorCode.TagLostError\n ) {\n this._onConnectionLost(error);\n }\n throw error;\n } else {\n throw errString;\n }\n }\n });\n });\n }\n\n _onConnectionLost(error: NfcError) {\n if (this.connectionState !== ConnectionState.DISCONNECTED) {\n this.setConnectionState(ConnectionState.DISCONNECTED);\n }\n }\n}\n\n/**\n * Convert error string returned by the plugin into an error object\n * It only checks a few Android error string for now\n *\n * TODO complete implementation with other error types\n *\n * @param errString\n */\nfunction stringToError(errString: string): NfcError {\n const errStringLc = errString.toLowerCase();\n if (errStringLc.indexOf('tag was lost') >= 0) {\n return NfcError.tagLostError();\n } else if (errStringLc.indexOf('not connected') >= 0) {\n return NfcError.notConnectedError();\n } else {\n return NfcError.unknownError(errString);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
[{"__symbolic":"module","version":4,"metadata":{"NFCComProtocol":{"__symbolic":"class","extends":{"__symbolic":"reference","module":"@iotize/tap/protocol/core","name":"QueueComProtocol","line":
|
|
1
|
+
[{"__symbolic":"module","version":4,"metadata":{"NFCComProtocol":{"__symbolic":"class","extends":{"__symbolic":"reference","module":"@iotize/tap/protocol/core","name":"QueueComProtocol","line":33,"character":36},"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@iotize/tap/protocol/api","name":"ComProtocolOptions","line":35,"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}}]}}}}}}]
|
|
@@ -2,9 +2,25 @@ import { Buffer } from 'buffer';
|
|
|
2
2
|
import { bufferToAsciiString, asciiStringToByteBuffer, bufferToHexString, hexStringToBuffer } from '@iotize/common/byte-converter';
|
|
3
3
|
import { ConnectionState } from '@iotize/tap/protocol/api';
|
|
4
4
|
import { QueueComProtocol } from '@iotize/tap/protocol/core';
|
|
5
|
-
import { defer } from 'rxjs';
|
|
5
|
+
import { defer, switchMap, throwError, of } from 'rxjs';
|
|
6
6
|
import { createDebugger } from '@iotize/common/debug';
|
|
7
7
|
|
|
8
|
+
var CheckTapConnectionResult;
|
|
9
|
+
(function (CheckTapConnectionResult) {
|
|
10
|
+
/**
|
|
11
|
+
* Tag is still in range, connection is not required
|
|
12
|
+
*/
|
|
13
|
+
CheckTapConnectionResult[CheckTapConnectionResult["IN_RANGE_READY"] = 0] = "IN_RANGE_READY";
|
|
14
|
+
/**
|
|
15
|
+
* Tag in range but it has left NFC field, we need to connect again
|
|
16
|
+
*/
|
|
17
|
+
CheckTapConnectionResult[CheckTapConnectionResult["IN_RANGE_BUT_LEFT_FIELD"] = 1] = "IN_RANGE_BUT_LEFT_FIELD";
|
|
18
|
+
/**
|
|
19
|
+
* Tag not in range anymore, a new connection is required
|
|
20
|
+
*/
|
|
21
|
+
CheckTapConnectionResult[CheckTapConnectionResult["NOT_IN_RANGE"] = 2] = "NOT_IN_RANGE";
|
|
22
|
+
})(CheckTapConnectionResult || (CheckTapConnectionResult = {}));
|
|
23
|
+
|
|
8
24
|
class NfcError extends Error {
|
|
9
25
|
constructor(code, message) {
|
|
10
26
|
super(message);
|
|
@@ -177,7 +193,7 @@ function parseWellKnownType(message) {
|
|
|
177
193
|
type: 'text',
|
|
178
194
|
value: Buffer.from(text).toString(encoding),
|
|
179
195
|
encoding,
|
|
180
|
-
language: Buffer.from(language).toString(encoding)
|
|
196
|
+
language: Buffer.from(language).toString(encoding),
|
|
181
197
|
};
|
|
182
198
|
}
|
|
183
199
|
// else if (arrayEquals(message.type.slice(), WellKnownType.SMPART_POSTER)) {
|
|
@@ -251,7 +267,8 @@ function encodeWellKnownType(message) {
|
|
|
251
267
|
const prefixesEntries = Object.entries(WELL_KNOWN_TYPE_URI_PREFIX);
|
|
252
268
|
let prefixByte = 0;
|
|
253
269
|
for (const [id, prefix] of prefixesEntries) {
|
|
254
|
-
if (id == '0x0')
|
|
270
|
+
if (id == '0x0')
|
|
271
|
+
// Skip first as it is always recognized. (what about 0x1 vs 0x2?)
|
|
255
272
|
continue;
|
|
256
273
|
if (message.value.value.startsWith(prefix)) {
|
|
257
274
|
prefixByte = parseInt(id, 16);
|
|
@@ -260,7 +277,7 @@ function encodeWellKnownType(message) {
|
|
|
260
277
|
}
|
|
261
278
|
const lengthToSlice = WELL_KNOWN_TYPE_URI_PREFIX[prefixByte].length;
|
|
262
279
|
const slicedString = message.value.value.slice(lengthToSlice);
|
|
263
|
-
return [prefixByte, ...
|
|
280
|
+
return [prefixByte, ...asciiStringToByteBuffer(slicedString)];
|
|
264
281
|
}
|
|
265
282
|
else if (message.value.type === 'text') {
|
|
266
283
|
// b1: RFU (set to 0)
|
|
@@ -268,7 +285,7 @@ function encodeWellKnownType(message) {
|
|
|
268
285
|
// B8-B8+n-1: language
|
|
269
286
|
// Bn: message
|
|
270
287
|
let firstByte = message.value.encoding == 'utf16le' ? 0b10000000 : 0;
|
|
271
|
-
firstByte &=
|
|
288
|
+
firstByte &= message.value.language & 0b00111111;
|
|
272
289
|
const languageBytes = Buffer.from(message.value.language, message.value.encoding);
|
|
273
290
|
const textBytes = Buffer.from(message.value.value, message.value.encoding);
|
|
274
291
|
return [firstByte, ...languageBytes, ...textBytes];
|
|
@@ -292,7 +309,7 @@ function encodeNDEFMessage(ndefRecord) {
|
|
|
292
309
|
id: ndefRecord.id,
|
|
293
310
|
type: ndefRecord.type,
|
|
294
311
|
tnf: TNF.ABSOLUTE_URI,
|
|
295
|
-
payload: Array.from(asciiStringToByteBuffer(ndefRecord.value))
|
|
312
|
+
payload: Array.from(asciiStringToByteBuffer(ndefRecord.value)),
|
|
296
313
|
};
|
|
297
314
|
case 'wkt':
|
|
298
315
|
return {
|
|
@@ -327,7 +344,7 @@ function encodeNDEFMessage(ndefRecord) {
|
|
|
327
344
|
id: ndefRecord.id,
|
|
328
345
|
type: ndefRecord.type,
|
|
329
346
|
tnf: TNF.RFU,
|
|
330
|
-
payload: ndefRecord.payload
|
|
347
|
+
payload: ndefRecord.payload,
|
|
331
348
|
};
|
|
332
349
|
case 'unchanged':
|
|
333
350
|
return {
|
|
@@ -412,7 +429,29 @@ class NFCComProtocol extends QueueComProtocol {
|
|
|
412
429
|
* @returns
|
|
413
430
|
*/
|
|
414
431
|
connect(options) {
|
|
415
|
-
this.connectionState
|
|
432
|
+
if (this.connectionState === ConnectionState.CONNECTED) {
|
|
433
|
+
return defer(() => __awaiter(this, void 0, void 0, function* () {
|
|
434
|
+
try {
|
|
435
|
+
return yield nfc.checkTapConnection(this.options.connect.timeout);
|
|
436
|
+
}
|
|
437
|
+
catch (err) {
|
|
438
|
+
this.setConnectionState(ConnectionState.DISCONNECTED);
|
|
439
|
+
throw err;
|
|
440
|
+
}
|
|
441
|
+
})).pipe(switchMap((connectionCheckState) => {
|
|
442
|
+
switch (connectionCheckState) {
|
|
443
|
+
case CheckTapConnectionResult.IN_RANGE_READY:
|
|
444
|
+
return of(undefined);
|
|
445
|
+
case CheckTapConnectionResult.IN_RANGE_BUT_LEFT_FIELD:
|
|
446
|
+
this.setConnectionState(ConnectionState.CONNECTING);
|
|
447
|
+
return super.connect(options);
|
|
448
|
+
case CheckTapConnectionResult.NOT_IN_RANGE:
|
|
449
|
+
default:
|
|
450
|
+
this.setConnectionState(ConnectionState.DISCONNECTED);
|
|
451
|
+
return throwError(() => NfcError.tagLostError());
|
|
452
|
+
}
|
|
453
|
+
}));
|
|
454
|
+
}
|
|
416
455
|
return super.connect(options);
|
|
417
456
|
}
|
|
418
457
|
/**
|
|
@@ -574,5 +613,5 @@ function convertBytesToBLEAddress(bytes) {
|
|
|
574
613
|
* Generated bundle index. Do not edit.
|
|
575
614
|
*/
|
|
576
615
|
|
|
577
|
-
export { NFCComProtocol, NfcError, TNF, WellKnownType, encodeNDEFMessage, encodeNDEFMessages, parseNdefMessage, parseNdefMessages, parseTapNdefMessage };
|
|
616
|
+
export { CheckTapConnectionResult, NFCComProtocol, NfcError, TNF, WellKnownType, encodeNDEFMessage, encodeNDEFMessages, parseNdefMessage, parseNdefMessages, parseTapNdefMessage };
|
|
578
617
|
//# sourceMappingURL=iotize-device-com-nfc.cordova.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iotize-device-com-nfc.cordova.js","sources":["../../../../src/www/errors.ts","../../../../src/www/ndef/definitions.ts","../../../../src/www/utility.ts","../../../../src/www/ndef/parse-ndef-message.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 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","export enum TNF {\r\n EMPTY = 0x00, // Empty\r\n WELL_KNOWN_TYPE = 0x01, // NFC Forum well-known type [NFC RTD]\r\n MIME_TYPE = 0x02, // Media-type [RFC 2046]\r\n ABSOLUTE_URI = 0x03, // Absolute URI [RFC 3986]\r\n EXTERNAL = 0x04, // NFC Forum external type [NFC RTD]\r\n UNKNOWN = 0x05,\r\n UNCHANGED = 0x06, //\r\n RFU = 0x07, // Reserved for future use\r\n}\r\n\r\nexport const WellKnownType = {\r\n URI: [0x55],\r\n TEXT: [0x54],\r\n SMPART_POSTER: [0x53, 0x70],\r\n};\r\n","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","import { Buffer } from 'buffer';\nimport { NdefRecord } from '../tap-ndef/definitions';\nimport { arrayEquals, toAsciiString } from '../utility';\nimport { TNF, WellKnownType } from './definitions';\nimport { asciiStringToByteBuffer } from '@iotize/common/byte-converter';\n\nexport type NdefParsedRecord = {\n tnf: string | number,\n value?: any,\n payload?: any\n id: any[],\n type: number[]\n};\n\nexport function parseNdefMessages(messages: NdefRecord[] | undefined | null) {\n return (messages || []).map(parseNdefMessage);\n}\n\nexport function parseNdefMessage(message: NdefRecord): NdefParsedRecord {\n switch (message.tnf) {\n case TNF.ABSOLUTE_URI:\n return {\n id: message.id,\n type: message.type,\n tnf: 'uri',\n value: toAsciiString(message.payload),\n };\n case TNF.WELL_KNOWN_TYPE:\n return {\n id: message.id,\n type: message.type,\n tnf: 'wkt',\n value: parseWellKnownType(message),\n };\n case TNF.EMPTY:\n return {\n id: message.id,\n type: message.type,\n tnf: 'empty',\n value: {\n type: message.type,\n payload: message.payload,\n },\n };\n case TNF.EXTERNAL:\n return {\n id: message.id,\n type: message.type,\n tnf: 'external',\n value: paseExternalType(message),\n };\n case TNF.MIME_TYPE:\n return {\n id: message.id,\n type: message.type,\n tnf: 'mimetype',\n value: parseMimeType(message),\n };\n case TNF.RFU:\n return {\n id: message.id,\n type: message.type,\n tnf: 'rfu',\n value: {\n type: message.type,\n payload: message.payload,\n },\n };\n case TNF.UNCHANGED:\n return {\n id: message.id,\n type: message.type,\n tnf: 'unchanged',\n value: {\n type: message.type,\n payload: message.payload,\n },\n };\n case TNF.UNKNOWN:\n return {\n id: message.id,\n type: message.type,\n tnf: 'unknown',\n value: {\n type: message.type,\n payload: message.payload,\n },\n };\n default:\n return {\n id: message.id,\n type: message.type,\n tnf: message.tnf,\n value: {\n type: message.type,\n payload: message.payload,\n },\n };\n }\n}\n\nfunction parseWellKnownType(message: Pick<NdefRecord, 'payload' | 'type'>) {\n if (arrayEquals(message.type.slice(), WellKnownType.URI)) {\n const prefixCode = message.payload[0];\n let prefix: string =\n WELL_KNOWN_TYPE_URI_PREFIX[\n prefixCode as keyof typeof WELL_KNOWN_TYPE_URI_PREFIX\n ] || '';\n return {\n type: 'uri',\n value: prefix + toAsciiString(message.payload.slice(1)),\n };\n } else if (arrayEquals(message.type.slice(), WellKnownType.TEXT)) {\n const encodingNumber = message.payload[0];\n let encoding: 'utf16le' | 'utf8' = 'utf8';\n let languageSizeInBytes = 0;\n if (typeof encodingNumber === 'number') {\n // b0: encodage utf8 s’il vaut 0 et utf16 s’il vaut 1.\n // b1: RFU (set to 0)\n // b2-b7: la taille en octets de la langue (n)\n // B8-B8+n-1: language\n // Bn: message\n const b0 = encodingNumber & 0b10000000;\n encoding = b0 ? 'utf16le' : 'utf8';\n languageSizeInBytes = encodingNumber & 0b00111111;\n }\n const text = message.payload.slice(languageSizeInBytes + 1);\n const language = message.payload.slice(8, languageSizeInBytes + 1);\n return {\n type: 'text',\n value: Buffer.from(text).toString(encoding),\n encoding,\n language: Buffer.from(language).toString(encoding)\n };\n }\n // else if (arrayEquals(message.type.slice(), WellKnownType.SMPART_POSTER)) {\n // return {\n // type: 'sp',\n // // TODO implement\n // payload: message.payload,\n // };\n // }\n else {\n return {\n type: 'unknown',\n value: {\n type: message.type.slice(),\n payload: message.payload,\n },\n };\n }\n}\n\nfunction paseExternalType(message: Pick<NdefRecord, 'payload' | 'type'>) {\n const value = Buffer.from(message.payload).toString('utf8');\n const domain = Buffer.from(message.type).toString('utf8');\n return {\n domain,\n value,\n };\n}\n\nconst WELL_KNOWN_TYPE_URI_PREFIX = {\n 0x0: '',\n 0x1: 'http://www.',\n 0x2: 'http://www.',\n 0x3: 'http://',\n 0x4: 'https://',\n 0x5: 'tel:',\n 0x6: 'mailto:',\n 0x07: 'ftp://anonymous:anonymous@',\n 0x1d: 'file://',\n 0x08: 'ftp://ftp.',\n 0x09: 'ftps://',\n 0x0a: 'sftp://',\n 0x0b: 'smb://',\n 0x0c: 'nfs://',\n 0x0d: 'ftp://',\n 0x0e: 'dav://',\n 0x0f: 'news:',\n 0x10: 'telnet://',\n 0x11: 'imap:',\n 0x12: 'rtsp://',\n 0x13: 'urn:',\n 0x14: 'pop:',\n 0x15: 'sip:',\n 0x16: 'sips:',\n 0x17: 'tftp:',\n 0x18: 'btspp://',\n 0x19: 'btl2cap://',\n 0x1a: 'btgoep://',\n 0x1b: 'tcpobex://',\n 0x1c: 'irdaobex://',\n 0x1e: 'urn:epc:id:',\n 0x1f: 'urn:epc:tag:',\n 0x20: 'urn:epc:pat:',\n 0x21: 'urn:epc:raw:',\n 0x22: 'urn:epc:',\n};\n\nfunction parseMimeType(message: Pick<NdefRecord, 'payload'>) {\n return Buffer.from(message.payload).toString('utf8');\n}\n\nfunction encodeWellKnownType(message: NdefParsedRecord) {\n\n if (message.value.type == 'uri') {\n //identify the prefix\n const prefixesEntries = Object.entries(WELL_KNOWN_TYPE_URI_PREFIX);\n let prefixByte = 0;\n for (const [id, prefix] of prefixesEntries) {\n if (id == '0x0') // Skip first as it is always recognized. (what about 0x1 vs 0x2?)\n continue;\n if (message.value.value.startsWith(prefix)) {\n prefixByte = parseInt(id, 16);\n break;\n }\n }\n const lengthToSlice = WELL_KNOWN_TYPE_URI_PREFIX[prefixByte as keyof typeof WELL_KNOWN_TYPE_URI_PREFIX].length;\n const slicedString = message.value.value.slice(lengthToSlice);\n return [prefixByte, ...(asciiStringToByteBuffer(slicedString))];\n\n } else if (message.value.type === 'text') {\n // b1: RFU (set to 0)\n // b2-b7: la taille en octets de la langue (n)\n // B8-B8+n-1: language\n // Bn: message\n let firstByte = message.value.encoding == 'utf16le' ? 0b10000000 : 0;\n firstByte &= (message.value.language & 0b00111111);\n const languageBytes = Buffer.from(message.value.language, message.value.encoding);\n const textBytes = Buffer.from(message.value.value, message.value.encoding);\n return [firstByte, ...languageBytes, ...textBytes];\n }\n else return [...message.value.type, ...message.value.payload];\n}\n\nfunction encodeExternalType(message: NdefParsedRecord) {\n return Array.from(Buffer.from(message.value.value, 'utf8'));\n}\n\nfunction encodeMimeType(message: NdefParsedRecord) {\n return Array.from(Buffer.from(message.value, 'utf8'));\n}\n\nexport function encodeNDEFMessages(ndefRecords: NdefParsedRecord[]) {\n return (ndefRecords || []).map(encodeNDEFMessage)\n}\n\nexport function encodeNDEFMessage(ndefRecord: NdefParsedRecord): NdefRecord {\n switch (ndefRecord.tnf) {\n case 'uri':\n return {\n id: ndefRecord.id,\n type: ndefRecord.type,\n tnf: TNF.ABSOLUTE_URI,\n payload: Array.from(asciiStringToByteBuffer(ndefRecord.value))\n };\n case 'wkt':\n return {\n id: ndefRecord.id,\n type: ndefRecord.type,\n tnf: TNF.WELL_KNOWN_TYPE,\n payload: encodeWellKnownType(ndefRecord),\n };\n case 'empty':\n return {\n id: ndefRecord.id,\n type: ndefRecord.type,\n tnf: TNF.EMPTY,\n payload: ndefRecord.payload,\n };\n case 'external':\n return {\n id: ndefRecord.id,\n type: ndefRecord.type,\n tnf: TNF.EXTERNAL,\n payload: encodeExternalType(ndefRecord),\n };\n case 'mimetype':\n return {\n id: ndefRecord.id,\n type: ndefRecord.type,\n tnf: TNF.MIME_TYPE,\n payload: encodeMimeType(ndefRecord),\n };\n case 'rfu':\n return {\n id: ndefRecord.id,\n type: ndefRecord.type,\n tnf: TNF.RFU,\n payload: ndefRecord.payload\n };\n case 'unchanged':\n return {\n id: ndefRecord.id,\n type: ndefRecord.type,\n tnf: TNF.UNCHANGED,\n payload: ndefRecord.payload,\n };\n case 'unknown':\n return {\n id: ndefRecord.id,\n type: ndefRecord.type,\n tnf: TNF.UNKNOWN,\n payload: ndefRecord.payload,\n };\n default:\n return {\n id: ndefRecord.id,\n type: ndefRecord.type,\n tnf: Number(ndefRecord.tnf),\n payload: ndefRecord.payload,\n };\n }\n}","import { createDebugger } from '@iotize/common/debug';\r\n\r\nexport const debug = createDebugger(`@iotize/device-com-nfc.cordova`);","import {\n bufferToHexString,\n hexStringToBuffer,\n} from '@iotize/common/byte-converter';\nimport {\n ComProtocolConnectOptions,\n ComProtocolDisconnectOptions,\n ComProtocolOptions,\n ComProtocolSendOptions,\n ConnectionState,\n} from '@iotize/tap/protocol/api';\nimport { QueueComProtocol } from '@iotize/tap/protocol/core';\nimport { defer, Observable } from 'rxjs';\n\nimport { CordovaInterface } from './cordova-interface';\nimport { NfcError } from './errors';\nimport { debug } from './logger';\n\ndeclare var nfc: CordovaInterface;\n\nclass PromiseQueue {\n queue = Promise.resolve<any>(true);\n\n add<T>(operation: () => Promise<T>): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n this.queue = this.queue.then(operation).then(resolve).catch(reject);\n });\n }\n}\n\nexport class NFCComProtocol extends QueueComProtocol {\n constructor(\n options: ComProtocolOptions = {\n connect: {\n timeout: 2000,\n },\n disconnect: {\n timeout: 1000,\n },\n send: {\n timeout: 1000,\n },\n }\n ) {\n super();\n this.options = options;\n if (typeof nfc == undefined) {\n console.warn(\n 'NFC plugin has not been setup properly. Global variable NFC does not exist'\n );\n }\n }\n\n public static iOSProtocol(): NFCComProtocol {\n return new NFCComProtocol({\n connect: {\n timeout: 10000, // bigger timer on connect as connect launches a reading session\n },\n disconnect: {\n timeout: 1000,\n },\n send: {\n timeout: 1000,\n },\n });\n }\n\n private _sendQueue = new PromiseQueue();\n\n /**\n * We force tag connection with nfc as we need to refresh tag\n * @param options\n * @returns\n */\n connect(options?: ComProtocolConnectOptions): Observable<void> {\n this.connectionState = ConnectionState.CONNECTING; // Hack to force NFC tag connect call even if we are already connected\n return super.connect(options);\n }\n\n /**\n * Not used as we have rewrote \"connect()\" function\n * @param options\n * @returns\n */\n _connect(options?: ComProtocolConnectOptions): Observable<any> {\n return defer(async () => {\n debug('_connect', options);\n try {\n await nfc.connect(\n 'android.nfc.tech.NfcV',\n this.options.connect.timeout\n );\n } catch (err) {\n if (typeof err === 'string') {\n if (err === 'Tag connection failed') {\n throw NfcError.tagConnectionFailed();\n } else {\n throw NfcError.unknownError(err);\n }\n }\n throw err;\n }\n });\n }\n\n _disconnect(options?: ComProtocolDisconnectOptions): Observable<any> {\n return defer(async () => {\n await nfc.close();\n this._sendQueue = new PromiseQueue();\n });\n }\n\n /**\n * Not used\n * @param options\n * @returns\n */\n async write(data: Uint8Array): Promise<any> {\n throw new Error('Method not implemented.');\n }\n\n /**\n * Not used\n * @param options\n * @returns\n */\n async read(): Promise<Uint8Array> {\n throw new Error('Method not implemented.');\n }\n\n send(\n data: Uint8Array,\n options?: ComProtocolSendOptions\n ): Observable<Uint8Array> {\n return defer(async () => {\n return await this._sendQueue.add(async () => {\n try {\n const response = await nfc.transceiveTap(bufferToHexString(data));\n if (typeof response != 'string') {\n throw NfcError.internalError(\n `Internal error. Plugin should respond a hexadecimal string`\n );\n }\n debug('NFC plugin response: ', response);\n return hexStringToBuffer(response);\n } catch (errString) {\n if (typeof errString === 'string') {\n const error = stringToError(errString);\n if (\n error.code === NfcError.ErrorCode.NotConnectedError ||\n error.code === NfcError.ErrorCode.TagLostError\n ) {\n this._onConnectionLost(error);\n }\n throw error;\n } else {\n throw errString;\n }\n }\n });\n });\n }\n\n _onConnectionLost(error: NfcError) {\n if (this.connectionState !== ConnectionState.DISCONNECTED) {\n this.setConnectionState(ConnectionState.DISCONNECTED);\n }\n }\n}\n\n/**\n * Convert error string returned by the plugin into an error object\n * It only checks a few Android error string for now\n *\n * TODO complete implementation with other error types\n *\n * @param errString\n */\nfunction stringToError(errString: string): NfcError {\n const errStringLc = errString.toLowerCase();\n if (errStringLc.indexOf('tag was lost') >= 0) {\n return NfcError.tagLostError();\n } else if (errStringLc.indexOf('not connected') >= 0) {\n return NfcError.notConnectedError();\n } else {\n return NfcError.unknownError(errString);\n }\n}\n","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","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;;;MAAa,QAAS,SAAQ,KAAK;IACjC,YAAmB,IAAwB,EAAE,OAAe;QAC1D,KAAK,CAAC,OAAO,CAAC,CAAC;QADE,SAAI,GAAJ,IAAI,CAAoB;KAE1C;IAEM,OAAO,YAAY;QACxB,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;KACtE;IAEM,OAAO,iBAAiB;QAC7B,OAAO,IAAI,QAAQ,CACjB,QAAQ,CAAC,SAAS,CAAC,iBAAiB,EACpC,0BAA0B,CAC3B,CAAC;KACH;IAEM,OAAO,YAAY,CAAC,SAAiB;QAC1C,MAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;KAC3D;IAEM,OAAO,mBAAmB;QAC/B,MAAM,IAAI,QAAQ,CAChB,QAAQ,CAAC,SAAS,CAAC,iBAAiB,EACpC,uBAAuB,CACxB,CAAC;KACH;IAEM,OAAO,aAAa,CAAC,OAAe;QACzC,MAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;KAC/D;CACF;AAED,WAAiB,QAAQ;IACvB,IAAY,SAKX;IALD,WAAY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C;QAClC,OAAO,UAAU,CAAC;KACnB,CAAC;SACD,OAAO,EAAE;SACT,IAAI,CAAC,GAAG,CAAC,CAAC;AACf;;ACtDA;;;;;;"}
|
|
1
|
+
{"version":3,"file":"iotize-device-com-nfc.cordova.js","sources":["../../../../src/www/cordova-interface.ts","../../../../src/www/errors.ts","../../../../src/www/ndef/definitions.ts","../../../../src/www/utility.ts","../../../../src/www/ndef/parse-ndef-message.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":["//\n// Copyright 2018 IoTize SAS Inc. Licensed under the MIT license.\n//\n// cordova-interface.ts\n// device-com-ble.cordova BLE Cordova Plugin\n//\n/**\n * Partial typings for phonegap nfc cordova interface class\n */\nexport interface CordovaInterface {\n /**\n * Close current nfc tag\n */\n close(): Promise<void>;\n\n /**\n * Connect to current Tap nfc tag\n */\n connect(tech: string, timeout?: number): Promise<void>;\n\n /**\n * Raw NFC connect\n */\n connectRaw(tech: string, timeout?: number): Promise<void>;\n\n /**\n * Transeive data using Tap NFC communication protocol\n * @param data ArrayBuffer or string of hex data for transcieve\n */\n transceiveTap(data: ArrayBuffer | string): Promise<string>;\n\n /**\n * Transeive raw data\n * @param data ArrayBuffer or string of hex data for transcieve\n */\n transceive(data: ArrayBuffer | string): Promise<string>;\n\n setTapDeviceDiscoveryEnabled(value: boolean): Promise<void>;\n\n /**\n * Begins a reading session for the given technology.\n * @param tech String representing the technology of the tap to discover.\n */\n beginSessionFromTech(tech: string, alertMessage?: string): Promise<void>;\n\n endSession(): Promise<void>;\n\n checkTapConnection(timeout: number): Promise<CheckTapConnectionResult>;\n}\n\nexport enum CheckTapConnectionResult {\n /**\n * Tag is still in range, connection is not required\n */\n IN_RANGE_READY = 0,\n /**\n * Tag in range but it has left NFC field, we need to connect again\n */\n IN_RANGE_BUT_LEFT_FIELD = 1,\n /**\n * Tag not in range anymore, a new connection is required\n */\n NOT_IN_RANGE = 2,\n}\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","export enum TNF {\r\n EMPTY = 0x00, // Empty\r\n WELL_KNOWN_TYPE = 0x01, // NFC Forum well-known type [NFC RTD]\r\n MIME_TYPE = 0x02, // Media-type [RFC 2046]\r\n ABSOLUTE_URI = 0x03, // Absolute URI [RFC 3986]\r\n EXTERNAL = 0x04, // NFC Forum external type [NFC RTD]\r\n UNKNOWN = 0x05,\r\n UNCHANGED = 0x06, //\r\n RFU = 0x07, // Reserved for future use\r\n}\r\n\r\nexport const WellKnownType = {\r\n URI: [0x55],\r\n TEXT: [0x54],\r\n SMPART_POSTER: [0x53, 0x70],\r\n};\r\n","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","import { Buffer } from 'buffer';\nimport { NdefRecord } from '../tap-ndef/definitions';\nimport { arrayEquals, toAsciiString } from '../utility';\nimport { TNF, WellKnownType } from './definitions';\nimport { asciiStringToByteBuffer } from '@iotize/common/byte-converter';\n\nexport type NdefParsedRecord = {\n tnf: string | number;\n value?: any;\n payload?: any;\n id: any[];\n type: number[];\n};\n\nexport function parseNdefMessages(messages: NdefRecord[] | undefined | null) {\n return (messages || []).map(parseNdefMessage);\n}\n\nexport function parseNdefMessage(message: NdefRecord): NdefParsedRecord {\n switch (message.tnf) {\n case TNF.ABSOLUTE_URI:\n return {\n id: message.id,\n type: message.type,\n tnf: 'uri',\n value: toAsciiString(message.payload),\n };\n case TNF.WELL_KNOWN_TYPE:\n return {\n id: message.id,\n type: message.type,\n tnf: 'wkt',\n value: parseWellKnownType(message),\n };\n case TNF.EMPTY:\n return {\n id: message.id,\n type: message.type,\n tnf: 'empty',\n value: {\n type: message.type,\n payload: message.payload,\n },\n };\n case TNF.EXTERNAL:\n return {\n id: message.id,\n type: message.type,\n tnf: 'external',\n value: paseExternalType(message),\n };\n case TNF.MIME_TYPE:\n return {\n id: message.id,\n type: message.type,\n tnf: 'mimetype',\n value: parseMimeType(message),\n };\n case TNF.RFU:\n return {\n id: message.id,\n type: message.type,\n tnf: 'rfu',\n value: {\n type: message.type,\n payload: message.payload,\n },\n };\n case TNF.UNCHANGED:\n return {\n id: message.id,\n type: message.type,\n tnf: 'unchanged',\n value: {\n type: message.type,\n payload: message.payload,\n },\n };\n case TNF.UNKNOWN:\n return {\n id: message.id,\n type: message.type,\n tnf: 'unknown',\n value: {\n type: message.type,\n payload: message.payload,\n },\n };\n default:\n return {\n id: message.id,\n type: message.type,\n tnf: message.tnf,\n value: {\n type: message.type,\n payload: message.payload,\n },\n };\n }\n}\n\nfunction parseWellKnownType(message: Pick<NdefRecord, 'payload' | 'type'>) {\n if (arrayEquals(message.type.slice(), WellKnownType.URI)) {\n const prefixCode = message.payload[0];\n let prefix: string =\n WELL_KNOWN_TYPE_URI_PREFIX[\n prefixCode as keyof typeof WELL_KNOWN_TYPE_URI_PREFIX\n ] || '';\n return {\n type: 'uri',\n value: prefix + toAsciiString(message.payload.slice(1)),\n };\n } else if (arrayEquals(message.type.slice(), WellKnownType.TEXT)) {\n const encodingNumber = message.payload[0];\n let encoding: 'utf16le' | 'utf8' = 'utf8';\n let languageSizeInBytes = 0;\n if (typeof encodingNumber === 'number') {\n // b0: encodage utf8 s’il vaut 0 et utf16 s’il vaut 1.\n // b1: RFU (set to 0)\n // b2-b7: la taille en octets de la langue (n)\n // B8-B8+n-1: language\n // Bn: message\n const b0 = encodingNumber & 0b10000000;\n encoding = b0 ? 'utf16le' : 'utf8';\n languageSizeInBytes = encodingNumber & 0b00111111;\n }\n const text = message.payload.slice(languageSizeInBytes + 1);\n const language = message.payload.slice(8, languageSizeInBytes + 1);\n return {\n type: 'text',\n value: Buffer.from(text).toString(encoding),\n encoding,\n language: Buffer.from(language).toString(encoding),\n };\n }\n // else if (arrayEquals(message.type.slice(), WellKnownType.SMPART_POSTER)) {\n // return {\n // type: 'sp',\n // // TODO implement\n // payload: message.payload,\n // };\n // }\n else {\n return {\n type: 'unknown',\n value: {\n type: message.type.slice(),\n payload: message.payload,\n },\n };\n }\n}\n\nfunction paseExternalType(message: Pick<NdefRecord, 'payload' | 'type'>) {\n const value = Buffer.from(message.payload).toString('utf8');\n const domain = Buffer.from(message.type).toString('utf8');\n return {\n domain,\n value,\n };\n}\n\nconst WELL_KNOWN_TYPE_URI_PREFIX = {\n 0x0: '',\n 0x1: 'http://www.',\n 0x2: 'http://www.',\n 0x3: 'http://',\n 0x4: 'https://',\n 0x5: 'tel:',\n 0x6: 'mailto:',\n 0x07: 'ftp://anonymous:anonymous@',\n 0x1d: 'file://',\n 0x08: 'ftp://ftp.',\n 0x09: 'ftps://',\n 0x0a: 'sftp://',\n 0x0b: 'smb://',\n 0x0c: 'nfs://',\n 0x0d: 'ftp://',\n 0x0e: 'dav://',\n 0x0f: 'news:',\n 0x10: 'telnet://',\n 0x11: 'imap:',\n 0x12: 'rtsp://',\n 0x13: 'urn:',\n 0x14: 'pop:',\n 0x15: 'sip:',\n 0x16: 'sips:',\n 0x17: 'tftp:',\n 0x18: 'btspp://',\n 0x19: 'btl2cap://',\n 0x1a: 'btgoep://',\n 0x1b: 'tcpobex://',\n 0x1c: 'irdaobex://',\n 0x1e: 'urn:epc:id:',\n 0x1f: 'urn:epc:tag:',\n 0x20: 'urn:epc:pat:',\n 0x21: 'urn:epc:raw:',\n 0x22: 'urn:epc:',\n};\n\nfunction parseMimeType(message: Pick<NdefRecord, 'payload'>) {\n return Buffer.from(message.payload).toString('utf8');\n}\n\nfunction encodeWellKnownType(message: NdefParsedRecord) {\n if (message.value.type == 'uri') {\n //identify the prefix\n const prefixesEntries = Object.entries(WELL_KNOWN_TYPE_URI_PREFIX);\n let prefixByte = 0;\n for (const [id, prefix] of prefixesEntries) {\n if (id == '0x0')\n // Skip first as it is always recognized. (what about 0x1 vs 0x2?)\n continue;\n if (message.value.value.startsWith(prefix)) {\n prefixByte = parseInt(id, 16);\n break;\n }\n }\n const lengthToSlice =\n WELL_KNOWN_TYPE_URI_PREFIX[\n prefixByte as keyof typeof WELL_KNOWN_TYPE_URI_PREFIX\n ].length;\n const slicedString = message.value.value.slice(lengthToSlice);\n return [prefixByte, ...asciiStringToByteBuffer(slicedString)];\n } else if (message.value.type === 'text') {\n // b1: RFU (set to 0)\n // b2-b7: la taille en octets de la langue (n)\n // B8-B8+n-1: language\n // Bn: message\n let firstByte = message.value.encoding == 'utf16le' ? 0b10000000 : 0;\n firstByte &= message.value.language & 0b00111111;\n const languageBytes = Buffer.from(\n message.value.language,\n message.value.encoding\n );\n const textBytes = Buffer.from(message.value.value, message.value.encoding);\n return [firstByte, ...languageBytes, ...textBytes];\n } else return [...message.value.type, ...message.value.payload];\n}\n\nfunction encodeExternalType(message: NdefParsedRecord) {\n return Array.from(Buffer.from(message.value.value, 'utf8'));\n}\n\nfunction encodeMimeType(message: NdefParsedRecord) {\n return Array.from(Buffer.from(message.value, 'utf8'));\n}\n\nexport function encodeNDEFMessages(ndefRecords: NdefParsedRecord[]) {\n return (ndefRecords || []).map(encodeNDEFMessage);\n}\n\nexport function encodeNDEFMessage(ndefRecord: NdefParsedRecord): NdefRecord {\n switch (ndefRecord.tnf) {\n case 'uri':\n return {\n id: ndefRecord.id,\n type: ndefRecord.type,\n tnf: TNF.ABSOLUTE_URI,\n payload: Array.from(asciiStringToByteBuffer(ndefRecord.value)),\n };\n case 'wkt':\n return {\n id: ndefRecord.id,\n type: ndefRecord.type,\n tnf: TNF.WELL_KNOWN_TYPE,\n payload: encodeWellKnownType(ndefRecord),\n };\n case 'empty':\n return {\n id: ndefRecord.id,\n type: ndefRecord.type,\n tnf: TNF.EMPTY,\n payload: ndefRecord.payload,\n };\n case 'external':\n return {\n id: ndefRecord.id,\n type: ndefRecord.type,\n tnf: TNF.EXTERNAL,\n payload: encodeExternalType(ndefRecord),\n };\n case 'mimetype':\n return {\n id: ndefRecord.id,\n type: ndefRecord.type,\n tnf: TNF.MIME_TYPE,\n payload: encodeMimeType(ndefRecord),\n };\n case 'rfu':\n return {\n id: ndefRecord.id,\n type: ndefRecord.type,\n tnf: TNF.RFU,\n payload: ndefRecord.payload,\n };\n case 'unchanged':\n return {\n id: ndefRecord.id,\n type: ndefRecord.type,\n tnf: TNF.UNCHANGED,\n payload: ndefRecord.payload,\n };\n case 'unknown':\n return {\n id: ndefRecord.id,\n type: ndefRecord.type,\n tnf: TNF.UNKNOWN,\n payload: ndefRecord.payload,\n };\n default:\n return {\n id: ndefRecord.id,\n type: ndefRecord.type,\n tnf: Number(ndefRecord.tnf),\n payload: ndefRecord.payload,\n };\n }\n}\n","import { createDebugger } from '@iotize/common/debug';\r\n\r\nexport const debug = createDebugger(`@iotize/device-com-nfc.cordova`);","import {\n bufferToHexString,\n hexStringToBuffer,\n} from '@iotize/common/byte-converter';\nimport {\n ComProtocolConnectOptions,\n ComProtocolDisconnectOptions,\n ComProtocolOptions,\n ComProtocolSendOptions,\n ConnectionState,\n} from '@iotize/tap/protocol/api';\nimport { QueueComProtocol } from '@iotize/tap/protocol/core';\nimport { catchError, defer, Observable, of, switchMap, throwError } from 'rxjs';\n\nimport {\n CheckTapConnectionResult,\n CordovaInterface,\n} from './cordova-interface';\nimport { NfcError } from './errors';\nimport { debug } from './logger';\n\ndeclare var nfc: CordovaInterface;\n\nclass PromiseQueue {\n queue = Promise.resolve<any>(true);\n\n add<T>(operation: () => Promise<T>): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n this.queue = this.queue.then(operation).then(resolve).catch(reject);\n });\n }\n}\n\nexport class NFCComProtocol extends QueueComProtocol {\n constructor(\n options: ComProtocolOptions = {\n connect: {\n timeout: 2000,\n },\n disconnect: {\n timeout: 1000,\n },\n send: {\n timeout: 1000,\n },\n }\n ) {\n super();\n this.options = options;\n if (typeof nfc == undefined) {\n console.warn(\n 'NFC plugin has not been setup properly. Global variable NFC does not exist'\n );\n }\n }\n\n public static iOSProtocol(): NFCComProtocol {\n return new NFCComProtocol({\n connect: {\n timeout: 10000, // bigger timer on connect as connect launches a reading session\n },\n disconnect: {\n timeout: 1000,\n },\n send: {\n timeout: 1000,\n },\n });\n }\n\n private _sendQueue = new PromiseQueue();\n\n /**\n * We force tag connection with nfc as we need to refresh tag\n * @param options\n * @returns\n */\n connect(options?: ComProtocolConnectOptions): Observable<void> {\n if (this.connectionState === ConnectionState.CONNECTED) {\n return defer(async () => {\n try {\n return await nfc.checkTapConnection(this.options.connect.timeout);\n } catch (err) {\n this.setConnectionState(ConnectionState.DISCONNECTED);\n throw err;\n }\n }).pipe(\n switchMap((connectionCheckState) => {\n switch (connectionCheckState) {\n case CheckTapConnectionResult.IN_RANGE_READY:\n return of(undefined);\n case CheckTapConnectionResult.IN_RANGE_BUT_LEFT_FIELD:\n this.setConnectionState(ConnectionState.CONNECTING);\n return super.connect(options);\n case CheckTapConnectionResult.NOT_IN_RANGE:\n default:\n this.setConnectionState(ConnectionState.DISCONNECTED);\n return throwError(() => NfcError.tagLostError());\n }\n })\n );\n }\n return super.connect(options);\n }\n\n /**\n * Not used as we have rewrote \"connect()\" function\n * @param options\n * @returns\n */\n _connect(options?: ComProtocolConnectOptions): Observable<any> {\n return defer(async () => {\n debug('_connect', options);\n try {\n await nfc.connect(\n 'android.nfc.tech.NfcV',\n this.options.connect.timeout\n );\n } catch (err) {\n if (typeof err === 'string') {\n if (err === 'Tag connection failed') {\n throw NfcError.tagConnectionFailed();\n } else {\n throw NfcError.unknownError(err);\n }\n }\n throw err;\n }\n });\n }\n\n _disconnect(options?: ComProtocolDisconnectOptions): Observable<any> {\n return defer(async () => {\n await nfc.close();\n this._sendQueue = new PromiseQueue();\n });\n }\n\n /**\n * Not used\n * @param options\n * @returns\n */\n async write(data: Uint8Array): Promise<any> {\n throw new Error('Method not implemented.');\n }\n\n /**\n * Not used\n * @param options\n * @returns\n */\n async read(): Promise<Uint8Array> {\n throw new Error('Method not implemented.');\n }\n\n send(\n data: Uint8Array,\n options?: ComProtocolSendOptions\n ): Observable<Uint8Array> {\n return defer(async () => {\n return await this._sendQueue.add(async () => {\n try {\n const response = await nfc.transceiveTap(bufferToHexString(data));\n if (typeof response != 'string') {\n throw NfcError.internalError(\n `Internal error. Plugin should respond a hexadecimal string`\n );\n }\n debug('NFC plugin response: ', response);\n return hexStringToBuffer(response);\n } catch (errString) {\n if (typeof errString === 'string') {\n const error = stringToError(errString);\n if (\n error.code === NfcError.ErrorCode.NotConnectedError ||\n error.code === NfcError.ErrorCode.TagLostError\n ) {\n this._onConnectionLost(error);\n }\n throw error;\n } else {\n throw errString;\n }\n }\n });\n });\n }\n\n _onConnectionLost(error: NfcError) {\n if (this.connectionState !== ConnectionState.DISCONNECTED) {\n this.setConnectionState(ConnectionState.DISCONNECTED);\n }\n }\n}\n\n/**\n * Convert error string returned by the plugin into an error object\n * It only checks a few Android error string for now\n *\n * TODO complete implementation with other error types\n *\n * @param errString\n */\nfunction stringToError(errString: string): NfcError {\n const errStringLc = errString.toLowerCase();\n if (errStringLc.indexOf('tag was lost') >= 0) {\n return NfcError.tagLostError();\n } else if (errStringLc.indexOf('not connected') >= 0) {\n return NfcError.notConnectedError();\n } else {\n return NfcError.unknownError(errString);\n }\n}\n","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","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from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AAA,CAAA;AAED,SAAS,wBAAwB,CAAC,KAAe,EAAA;AAC/C,IAAA,OAAO,KAAK;AACT,SAAA,GAAG,CAAC,CAAC,IAAI,KAAI;QACZ,IAAI,IAAI,GAAG,CAAC,EAAE;YACZ,IAAI,IAAI,GAAG,CAAC;AACb,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;AACpB,KAAC,CAAC;AACD,SAAA,OAAO,EAAE;SACT,IAAI,CAAC,GAAG,CAAC,CAAC;AACf;;ACtDA;;AAEG;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"__symbolic":"module","version":4,"exports":[{"from":"./www/definitions"},{"from":"./www/parse-ndef-message"}],"metadata":{"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"]}}}},"TNF":{"EMPTY":0,"WELL_KNOWN_TYPE":1,"MIME_TYPE":2,"ABSOLUTE_URI":3,"EXTERNAL":4,"UNKNOWN":5,"UNCHANGED":6,"RFU":7},"WellKnownType":{"URI":[85],"TEXT":[84],"SMPART_POSTER":[83,112]},"parseNdefMessage":{"__symbolic":"function"},"parseNdefMessages":{"__symbolic":"function","parameters":["messages"],"value":{"__symbolic":"call","expression":{"__symbolic":"select","expression":{"__symbolic":"binop","operator":"||","left":{"__symbolic":"reference","name":"messages"},"right":[]},"member":"map"},"arguments":[{"__symbolic":"reference","name":"parseNdefMessage"}]}},"encodeNDEFMessage":{"__symbolic":"function"},"encodeNDEFMessages":{"__symbolic":"function","parameters":["ndefRecords"],"value":{"__symbolic":"call","expression":{"__symbolic":"select","expression":{"__symbolic":"binop","operator":"||","left":{"__symbolic":"reference","name":"ndefRecords"},"right":[]},"member":"map"},"arguments":[{"__symbolic":"reference","name":"encodeNDEFMessage"}]}},"NdefParsedRecord":{"__symbolic":"interface"},"NFCComProtocol":{"__symbolic":"class","extends":{"__symbolic":"reference","module":"@iotize/tap/protocol/core","name":"QueueComProtocol","line":
|
|
1
|
+
{"__symbolic":"module","version":4,"exports":[{"from":"./www/definitions"},{"from":"./www/parse-ndef-message"}],"metadata":{"CordovaInterface":{"__symbolic":"interface"},"CheckTapConnectionResult":{"IN_RANGE_READY":0,"IN_RANGE_BUT_LEFT_FIELD":1,"NOT_IN_RANGE":2},"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"]}}}},"TNF":{"EMPTY":0,"WELL_KNOWN_TYPE":1,"MIME_TYPE":2,"ABSOLUTE_URI":3,"EXTERNAL":4,"UNKNOWN":5,"UNCHANGED":6,"RFU":7},"WellKnownType":{"URI":[85],"TEXT":[84],"SMPART_POSTER":[83,112]},"parseNdefMessage":{"__symbolic":"function"},"parseNdefMessages":{"__symbolic":"function","parameters":["messages"],"value":{"__symbolic":"call","expression":{"__symbolic":"select","expression":{"__symbolic":"binop","operator":"||","left":{"__symbolic":"reference","name":"messages"},"right":[]},"member":"map"},"arguments":[{"__symbolic":"reference","name":"parseNdefMessage"}]}},"encodeNDEFMessage":{"__symbolic":"function"},"encodeNDEFMessages":{"__symbolic":"function","parameters":["ndefRecords"],"value":{"__symbolic":"call","expression":{"__symbolic":"select","expression":{"__symbolic":"binop","operator":"||","left":{"__symbolic":"reference","name":"ndefRecords"},"right":[]},"member":"map"},"arguments":[{"__symbolic":"reference","name":"encodeNDEFMessage"}]}},"NdefParsedRecord":{"__symbolic":"interface"},"NFCComProtocol":{"__symbolic":"class","extends":{"__symbolic":"reference","module":"@iotize/tap/protocol/core","name":"QueueComProtocol","line":33,"character":36},"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@iotize/tap/protocol/api","name":"ComProtocolOptions","line":35,"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}}]}}}}},"origins":{"CordovaInterface":"./www/cordova-interface","CheckTapConnectionResult":"./www/cordova-interface","NfcError":"./www/errors","TNF":"./www/ndef/definitions","WellKnownType":"./www/ndef/definitions","parseNdefMessage":"./www/ndef/parse-ndef-message","parseNdefMessages":"./www/ndef/parse-ndef-message","encodeNDEFMessage":"./www/ndef/parse-ndef-message","encodeNDEFMessages":"./www/ndef/parse-ndef-message","NdefParsedRecord":"./www/ndef/parse-ndef-message","NFCComProtocol":"./www/nfc-com-protocol"},"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.
|
|
4
|
+
"version": "3.10.0",
|
|
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",
|
package/plugin.xml
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
-
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
|
|
2
|
+
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
|
|
3
3
|
xmlns:android="http://schemas.android.com/apk/res/android" id="@iotize/device-com-nfc.cordova" version="3.8.1">
|
|
4
4
|
|
|
5
5
|
<name>@iotize/device-com-nfc.cordova</name>
|
|
@@ -33,13 +33,18 @@
|
|
|
33
33
|
<source-file src="src/android/src/com/chariotsolutions/nfc/plugin/JSONBuilder.java" target-dir="src/com/chariotsolutions/nfc/plugin"/>
|
|
34
34
|
<source-file src="src/android/src/com/chariotsolutions/nfc/plugin/PluginResponse.java" target-dir="src/com/chariotsolutions/nfc/plugin"/>
|
|
35
35
|
<source-file src="src/android/src/com/chariotsolutions/nfc/plugin/NfcPluginError.java" target-dir="src/com/chariotsolutions/nfc/plugin"/>
|
|
36
|
+
<source-file src="src/android/src/com/chariotsolutions/nfc/plugin/NFCProtocol.java" target-dir="src/com/chariotsolutions/nfc/plugin"/>
|
|
37
|
+
<source-file src="src/android/src/com/chariotsolutions/nfc/plugin/NFCProtocolFactory.java" target-dir="src/com/chariotsolutions/nfc/plugin"/>
|
|
38
|
+
<source-file src="src/android/src/com/chariotsolutions/nfc/plugin/NFCIntentParser.java" target-dir="src/com/chariotsolutions/nfc/plugin"/>
|
|
39
|
+
<source-file src="src/android/src/com/chariotsolutions/nfc/plugin/NFC4Protocol.java" target-dir="src/com/chariotsolutions/nfc/plugin"/>
|
|
40
|
+
<source-file src="src/android/src/com/chariotsolutions/nfc/plugin/NFC5Protocol.java" target-dir="src/com/chariotsolutions/nfc/plugin"/>
|
|
36
41
|
|
|
37
42
|
<config-file target="AndroidManifest.xml" parent="/manifest">
|
|
38
43
|
<uses-permission android:name="android.permission.NFC"/>
|
|
39
44
|
<uses-feature android:name="android.hardware.nfc" android:required="false"/>
|
|
40
45
|
</config-file>
|
|
41
46
|
|
|
42
|
-
<config-file parent="/manifest/application/activity[@android:name='MainActivity']" target="AndroidManifest.xml"
|
|
47
|
+
<config-file parent="/manifest/application/activity[@android:name='MainActivity']" target="AndroidManifest.xml"
|
|
43
48
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
|
44
49
|
<intent-filter>
|
|
45
50
|
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
|
|
@@ -74,14 +79,12 @@
|
|
|
74
79
|
|
|
75
80
|
<config-file platform="ios" target="*-Debug.plist" parent="com.apple.developer.nfc.readersession.formats">
|
|
76
81
|
<array>
|
|
77
|
-
<string>NDEF</string>
|
|
78
82
|
<string>TAG</string>
|
|
79
83
|
</array>
|
|
80
84
|
</config-file>
|
|
81
85
|
|
|
82
86
|
<config-file platform="ios" target="*-Release.plist" parent="com.apple.developer.nfc.readersession.formats">
|
|
83
87
|
<array>
|
|
84
|
-
<string>NDEF</string>
|
|
85
88
|
<string>TAG</string>
|
|
86
89
|
</array>
|
|
87
90
|
</config-file>
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
package com.chariotsolutions.nfc.plugin;
|
|
2
|
+
|
|
3
|
+
import android.nfc.Tag;
|
|
4
|
+
import android.nfc.tech.IsoDep;
|
|
5
|
+
|
|
6
|
+
import com.iotize.android.core.util.SynchronizeHelper;
|
|
7
|
+
import com.iotize.android.communication.client.impl.protocol.HostProtocol;
|
|
8
|
+
|
|
9
|
+
import java.io.IOException;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
public class NFC4Protocol extends NFCProtocol {
|
|
15
|
+
|
|
16
|
+
private static final long DEFAULT_READ_TIMEOUT = 2000;
|
|
17
|
+
private final IsoDep nfcTag;
|
|
18
|
+
private byte[] lastMessage;
|
|
19
|
+
|
|
20
|
+
public NFC4Protocol(Tag tag) {
|
|
21
|
+
super(tag);
|
|
22
|
+
nfcTag = IsoDep.get(tag);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@Override
|
|
27
|
+
public void _connect() throws IOException {
|
|
28
|
+
if (nfcTag.isConnected()) {
|
|
29
|
+
nfcTag.connect();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@Override
|
|
34
|
+
public void _disconnect() throws Exception {
|
|
35
|
+
nfcTag.close();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Override
|
|
39
|
+
public void write(byte[] message) throws Exception {
|
|
40
|
+
byte[] payload = nfcTag.transceive(message);
|
|
41
|
+
lastMessage = payload;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Override
|
|
45
|
+
public byte[] read() throws Exception {
|
|
46
|
+
SynchronizeHelper.waitForNotNull(lastMessage, DEFAULT_READ_TIMEOUT);
|
|
47
|
+
return lastMessage;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@Override
|
|
51
|
+
public void sendAsync(byte[] responseMessage, IOnEvent<byte[]> event) {
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@Override
|
|
56
|
+
public HostProtocol getType() {
|
|
57
|
+
return HostProtocol.NFC;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@Override
|
|
61
|
+
public String toString() {
|
|
62
|
+
return "NFC4Protocol{" +
|
|
63
|
+
"nfcTag=" + nfcTag +
|
|
64
|
+
'}';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// @Override
|
|
68
|
+
// public boolean isSameTag(Tag tag) {
|
|
69
|
+
// if (tag == null){
|
|
70
|
+
// return false;
|
|
71
|
+
// }
|
|
72
|
+
// IsoDep isoDepTag = IsoDep.get(tag);
|
|
73
|
+
// if (isoDepTag == null){
|
|
74
|
+
// return false;
|
|
75
|
+
// }
|
|
76
|
+
// return this.nfcTag.equals(isoDepTag);
|
|
77
|
+
// }
|
|
78
|
+
}
|