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

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 (74) hide show
  1. package/LICENSE +0 -1
  2. package/bundles/iotize-device-com-nfc.cordova.umd.js +267 -28
  3. package/bundles/iotize-device-com-nfc.cordova.umd.js.map +1 -1
  4. package/bundles/iotize-device-com-nfc.cordova.umd.min.js +15 -1
  5. package/bundles/iotize-device-com-nfc.cordova.umd.min.js.map +1 -1
  6. package/esm2015/iotize-device-com-nfc.cordova.js +1 -1
  7. package/esm2015/iotize-device-com-nfc.cordova.js.map +1 -0
  8. package/esm2015/iotize-device-com-nfc.cordova.metadata.json +1 -0
  9. package/esm2015/public_api.js +1 -1
  10. package/esm2015/public_api.js.map +1 -0
  11. package/esm2015/public_api.metadata.json +1 -0
  12. package/esm2015/www/cordova-interface.js +2 -1
  13. package/esm2015/www/cordova-interface.js.map +1 -0
  14. package/esm2015/www/cordova-interface.metadata.json +1 -0
  15. package/esm2015/www/errors.js +1 -1
  16. package/esm2015/www/errors.js.map +1 -0
  17. package/esm2015/www/errors.metadata.json +1 -0
  18. package/esm2015/www/index.js +2 -1
  19. package/esm2015/www/index.js.map +1 -0
  20. package/esm2015/www/index.metadata.json +1 -0
  21. package/esm2015/www/logger.js +1 -1
  22. package/esm2015/www/logger.js.map +1 -0
  23. package/esm2015/www/logger.metadata.json +1 -0
  24. package/esm2015/www/logger.ngsummary.json +1 -1
  25. package/esm2015/www/nfc-com-protocol.js +1 -1
  26. package/esm2015/www/nfc-com-protocol.js.map +1 -0
  27. package/esm2015/www/nfc-com-protocol.metadata.json +1 -0
  28. package/esm2015/www/nfc-com-protocol.ngsummary.json +1 -1
  29. package/esm2015/www/tap-ndef/definitions.js +2 -1
  30. package/esm2015/www/tap-ndef/definitions.js.map +1 -0
  31. package/esm2015/www/tap-ndef/definitions.metadata.json +1 -0
  32. package/esm2015/www/tap-ndef/index.js +2 -1
  33. package/esm2015/www/tap-ndef/index.js.map +1 -0
  34. package/esm2015/www/tap-ndef/index.metadata.json +1 -0
  35. package/esm2015/www/tap-ndef/parse-ndef-message.js +1 -1
  36. package/esm2015/www/tap-ndef/parse-ndef-message.js.map +1 -0
  37. package/esm2015/www/tap-ndef/parse-ndef-message.metadata.json +1 -0
  38. package/fesm2015/iotize-device-com-nfc.cordova.js.map +1 -1
  39. package/package.json +52 -53
  40. package/plugin.xml +2 -2
  41. package/src/android/.gradle/4.10.1/fileHashes/fileHashes.bin +0 -0
  42. package/src/android/.gradle/4.10.1/fileHashes/fileHashes.lock +0 -0
  43. package/src/android/build.gradle +5 -5
  44. package/src/android/src/com/chariotsolutions/nfc/plugin/NfcPlugin.java +7 -14
  45. package/src/ios/ISO15Reader.swift +1 -0
  46. package/www/logger.d.ts +2 -2
  47. package/CHANGELOG.md +0 -29
  48. package/esm5/iotize-device-com-nfc.cordova.js +0 -5
  49. package/esm5/public_api.js +0 -2
  50. package/esm5/www/cordova-interface.js +0 -1
  51. package/esm5/www/errors.js +0 -45
  52. package/esm5/www/index.js +0 -4
  53. package/esm5/www/logger.js +0 -3
  54. package/esm5/www/nfc-com-protocol.js +0 -128
  55. package/esm5/www/tap-ndef/definitions.js +0 -1
  56. package/esm5/www/tap-ndef/index.js +0 -2
  57. package/esm5/www/tap-ndef/parse-ndef-message.js +0 -57
  58. package/fesm5/iotize-device-com-nfc.cordova.js +0 -229
  59. package/fesm5/iotize-device-com-nfc.cordova.js.map +0 -1
  60. package/src/android/.gradle/4.10.2/fileChanges/last-build.bin +0 -0
  61. package/src/android/.gradle/4.10.2/fileHashes/fileHashes.bin +0 -0
  62. package/src/android/.gradle/4.10.2/fileHashes/fileHashes.lock +0 -0
  63. package/src/android/.gradle/4.10.2/gc.properties +0 -0
  64. package/src/android/.project +0 -17
  65. package/src/public_api.ts +0 -1
  66. package/src/www/cordova-interface.ts +0 -27
  67. package/src/www/errors.ts +0 -43
  68. package/src/www/index.ts +0 -4
  69. package/src/www/logger.ts +0 -3
  70. package/src/www/nfc-com-protocol.ts +0 -129
  71. package/src/www/tap-ndef/definitions.ts +0 -26
  72. package/src/www/tap-ndef/index.ts +0 -2
  73. package/src/www/tap-ndef/parse-ndef-message.spec.ts +0 -23
  74. package/src/www/tap-ndef/parse-ndef-message.ts +0 -62
@@ -1,129 +0,0 @@
1
- //
2
- // Copyright 2018 IoTize SAS Inc. Licensed under the MIT license.
3
- //
4
- // ble-com-protocol.ts
5
- // device-com-ble.cordova BLE Cordova Plugin
6
- //
7
- import { bufferToHexString, hexStringToBuffer } from '@iotize/common/byte-converter';
8
- import {
9
- ComProtocolConnectOptions,
10
- ComProtocolDisconnectOptions,
11
- ComProtocolOptions,
12
- ComProtocolSendOptions,
13
- ConnectionState,
14
- } from '@iotize/tap/protocol/api';
15
- import { QueueComProtocol } from '@iotize/tap/protocol/core';
16
- import { from, Observable } from 'rxjs';
17
-
18
- import { CordovaInterface } from './cordova-interface';
19
- import { NfcError } from './errors';
20
- import { debug } from './logger';
21
-
22
-
23
- declare var nfc: CordovaInterface;
24
-
25
- export class NFCComProtocol extends QueueComProtocol {
26
-
27
- constructor(options: ComProtocolOptions = {
28
- connect: {
29
- timeout: 2000
30
- },
31
- disconnect: {
32
- timeout: 1000
33
- },
34
- send: {
35
- timeout: 1000
36
- }
37
- }) {
38
- super();
39
- this.options = options;
40
- if (typeof nfc == undefined) {
41
- console.warn("NFC plugin has not been setup properly. Global variable NFC does not exist");
42
- }
43
- }
44
-
45
- public static iOSProtocol(): NFCComProtocol {
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
- _connect(options?: ComProtocolConnectOptions): Observable<any> {
60
- debug('_connect', options);
61
- const connectPromise = nfc.connect("android.nfc.tech.NfcV", this.options.connect.timeout)
62
- return from(connectPromise);
63
- }
64
-
65
- _disconnect(options?: ComProtocolDisconnectOptions): Observable<any> {
66
- return from(nfc.close());
67
- }
68
-
69
- write(data: Uint8Array): Promise<any> {
70
- throw new Error("Method not implemented.");
71
- }
72
-
73
- read(): Promise<Uint8Array> {
74
- throw new Error("Method not implemented.");
75
- }
76
-
77
- send(data: Uint8Array, options?: ComProtocolSendOptions): Observable<Uint8Array> {
78
- const promise = nfc
79
- .transceive(bufferToHexString(data))
80
- .then((response: string) => {
81
- if (typeof response != "string") {
82
- throw NfcError.internalError(`Internal error. Plugin should respond a hexadecimal string`);
83
- }
84
- debug('NFC plugin response: ', response)
85
- return hexStringToBuffer(response)
86
- })
87
- .catch((errString) => {
88
- if (typeof errString === "string") {
89
- const error = stringToError(errString);
90
- if (error.code === NfcError.ErrorCode.NotConnectedError || error.code === NfcError.ErrorCode.TagLostError) {
91
- this._onConnectionLost(error);
92
- }
93
- throw error;
94
- }
95
- else {
96
- throw errString;
97
- }
98
- });
99
- return from(promise);
100
- }
101
-
102
- _onConnectionLost(error: NfcError) {
103
- if (this.connectionState !== ConnectionState.DISCONNECTED) {
104
- this.setConnectionState(ConnectionState.DISCONNECTED);
105
- }
106
- }
107
-
108
- };
109
-
110
- /**
111
- * Convert error string returned by the plugin into an error object
112
- * It only checks a few Android error string for now
113
- *
114
- * TODO complete implementation with other error types
115
- *
116
- * @param errString
117
- */
118
- function stringToError(errString: string): NfcError {
119
- const errStringLc = errString.toLowerCase();
120
- if (errStringLc.indexOf('tag was lost') >= 0) {
121
- return NfcError.tagLostError();
122
- }
123
- else if (errStringLc.indexOf('not connected') >= 0) {
124
- return NfcError.notConnectedError();
125
- }
126
- else {
127
- return NfcError.unknownError(errString);
128
- }
129
- }
@@ -1,26 +0,0 @@
1
- export interface TapNfcTagPayload {
2
- type?: number;
3
- name?: string;
4
- aar?: string;
5
- uri?: string;
6
- macAddress?: string;
7
- ssid?: string
8
- }
9
-
10
- export interface NdefEvent {
11
- tag: NdefTag;
12
- }
13
- export interface NdefRecord {
14
- id: any[];
15
- payload: number[];
16
- tnf: number;
17
- type: number[];
18
- }
19
- export interface NdefTag {
20
- canMakeReadOnly: boolean;
21
- id: number[];
22
- isWritable: boolean;
23
- maxSize: number;
24
- ndefMessage: NdefRecord[];
25
- techTypes: string[];
26
- }
@@ -1,2 +0,0 @@
1
- export * from './definitions';
2
- export * from './parse-ndef-message';
@@ -1,23 +0,0 @@
1
- import { expect } from "chai";
2
- import { NdefRecord } from "./definitions";
3
- import { parseTapNdefMessage } from "./parse-ndef-message";
4
-
5
- describe(__filename, function () {
6
-
7
- const VALID_SAMPLE: NdefRecord[] = JSON.parse('[{"tnf":1,"type":[85],"id":[],"payload":[0,104,116,116,112,115,58,47,47,119,119,119,46,109,121,100,111,109,97,105,110,46,99,111,109]},{"tnf":4,"type":[97,110,100,114,111,105,100,46,99,111,109,58,112,107,103],"id":[],"payload":[99,111,109,46,105,111,116,105,122,101,46,100,101,109,111,46,115,101,110,115,111,114,100,101,109,111]},{"tnf":5,"type":[],"id":[],"payload":[64,88,-34,-65,-23,50,-63]},{"tnf":1,"type":[84],"id":[],"payload":[0,83,101,110,115,111,114,32,100,101,109,111,95,48,48,48,48,68]}]');
8
-
9
-
10
- describe('with valid NdefRecords', function () {
11
-
12
- it("parsing valid NDefRecords should extract informations", function () {
13
- let data = parseTapNdefMessage(VALID_SAMPLE);
14
- expect(data.ssid).to.be.undefined;
15
- expect(data.aar).to.be.eq("com.iotize.demo.sensordemo");
16
- expect(data.uri).to.be.eq("https://www.mydomain.com");
17
- expect(data.name).to.be.eq("Sensor demo_0000D");
18
- expect(data.macAddress).to.be.eq('C1:32:E9:BF:DE:58');
19
- })
20
- });
21
-
22
-
23
- })
@@ -1,62 +0,0 @@
1
- import { bufferToAsciiString } from '@iotize/common/byte-converter';
2
-
3
- import { NdefRecord, TapNfcTagPayload } from './definitions';
4
-
5
- /**
6
- * We manage only on NDEF message with 3 records:
7
- * record 0 = URI; record 1 = AAR; record 2 = BLE MAC ADDRESS / BSSID; record 3: universal link
8
- */
9
- export function parseTapNdefMessage(messages: NdefRecord[]): TapNfcTagPayload {
10
- let result: TapNfcTagPayload = {};
11
- if (messages.length >= 1) {
12
- let asciiUri = messages[0].payload;
13
- result.uri = toAsciiString(asciiUri);
14
- }
15
- if (messages.length >= 2) {
16
- result.aar = toAsciiString(messages[1].payload);
17
- }
18
- if (messages.length >= 3) {
19
- let payload3 = messages[2].payload;
20
- let type = payload3[0];
21
- let content = payload3.slice(1);
22
- result.type = type;
23
-
24
- switch (type) {
25
- case TapNdefProtocolType.BLE:
26
- result.macAddress = convertBytesToBLEAddress(content);
27
- break;
28
- case TapNdefProtocolType.WiFi:
29
- result.ssid = toAsciiString(content);
30
- break;
31
- }
32
- }
33
- if (messages.length >= 4) {
34
- result.name = toAsciiString(messages[3].payload);
35
- }
36
- return result;
37
- }
38
-
39
- enum TapNdefProtocolType {
40
- WiFi = 0x20,
41
- BLE = 0x40
42
- }
43
-
44
- function toAsciiString(payload: number[]): string {
45
- if (payload.length > 0 && payload[0] === 0) {
46
- payload = payload.slice(1);
47
- }
48
- return bufferToAsciiString(payload as any as Uint8Array);
49
- }
50
-
51
- function convertBytesToBLEAddress(bytes: number[]): string {
52
- return bytes.map(byte => {
53
- if (byte < 0) {
54
- byte += 256;
55
- }
56
- let byteString = '0' + byte.toString(16).toUpperCase();
57
- byteString = byteString.slice(-2);
58
- return byteString;
59
- })
60
- .reverse()
61
- .join(':')
62
- }