@iotize/device-com-nfc.cordova 3.8.0 → 3.8.1
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/LICENSE +30 -30
- package/README.md +673 -673
- package/bundles/iotize-device-com-nfc.cordova.umd.js +967 -946
- 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.js +4 -4
- package/esm2015/public_api.js +1 -1
- package/esm2015/www/cordova-interface.js +1 -1
- package/esm2015/www/errors.js +30 -30
- package/esm2015/www/errors.js.map +1 -1
- package/esm2015/www/index.js +6 -6
- package/esm2015/www/index.js.map +1 -1
- package/esm2015/www/logger.js +2 -2
- package/esm2015/www/logger.js.map +1 -1
- package/esm2015/www/ndef/definitions.js +16 -16
- package/esm2015/www/ndef/definitions.js.map +1 -1
- package/esm2015/www/ndef/parse-ndef-message.js +164 -164
- package/esm2015/www/ndef/parse-ndef-message.js.map +1 -1
- package/esm2015/www/nfc-com-protocol.js +169 -169
- package/esm2015/www/tap-ndef/definitions.js +1 -1
- package/esm2015/www/tap-ndef/definitions.js.map +1 -1
- package/esm2015/www/tap-ndef/index.js +2 -2
- package/esm2015/www/tap-ndef/index.js.map +1 -1
- package/esm2015/www/tap-ndef/parse-ndef-message.js +51 -51
- package/esm2015/www/tap-ndef/parse-ndef-message.js.map +1 -1
- package/esm2015/www/utility.js +10 -10
- package/esm2015/www/utility.js.map +1 -1
- package/esm2015/www/utility.ngsummary.json +1 -1
- package/fesm2015/iotize-device-com-nfc.cordova.js +425 -425
- package/fesm2015/iotize-device-com-nfc.cordova.js.map +1 -1
- package/iotize-device-com-nfc.cordova.d.ts +4 -4
- package/package.json +1 -1
- package/plugin.xml +1 -1
- package/public_api.d.ts +1 -1
- package/src/android/build.gradle +38 -38
- package/src/android/gradle/wrapper/gradle-wrapper.properties +6 -6
- package/src/android/gradlew +172 -172
- package/src/android/gradlew.bat +84 -84
- package/src/android/local.properties +8 -8
- package/src/android/src/com/chariotsolutions/nfc/plugin/JSONBuilder.java +60 -60
- package/src/android/src/com/chariotsolutions/nfc/plugin/NfcPluginError.java +15 -15
- package/src/android/src/com/chariotsolutions/nfc/plugin/PluginResponse.java +85 -85
- package/src/android/src/com/chariotsolutions/nfc/plugin/Util.java +140 -140
- package/src/ios/NFCTagReader.swift +6 -0
- package/src/ios/NFCTapPlugin.swift +2 -2
- package/www/cordova-interface.d.ts +34 -34
- package/www/errors.d.ts +17 -17
- package/www/index.d.ts +6 -6
- package/www/logger.d.ts +2 -2
- package/www/ndef/definitions.d.ts +15 -15
- package/www/ndef/parse-ndef-message.d.ts +69 -69
- package/www/nfc-com-protocol.d.ts +36 -36
- package/www/tap-ndef/definitions.d.ts +25 -25
- package/www/tap-ndef/index.d.ts +2 -2
- package/www/tap-ndef/parse-ndef-message.d.ts +6 -6
- package/www/utility.d.ts +2 -2
- package/src/android/.gradle/4.10.1/fileChanges/last-build.bin +0 -0
- 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/.gradle/4.10.1/gc.properties +0 -0
- package/src/android/.gradle/vcs-1/gc.properties +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generated bundle index. Do not edit.
|
|
3
|
-
*/
|
|
4
|
-
export * from './public_api';
|
|
1
|
+
/**
|
|
2
|
+
* Generated bundle index. Do not edit.
|
|
3
|
+
*/
|
|
4
|
+
export * from './public_api';
|
|
5
5
|
//# sourceMappingURL=iotize-device-com-nfc.cordova.js.map
|
package/esm2015/public_api.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './www/index';
|
|
1
|
+
export * from './www/index';
|
|
2
2
|
//# sourceMappingURL=public_api.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=cordova-interface.js.map
|
package/esm2015/www/errors.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
export class NfcError extends Error {
|
|
2
|
-
constructor(code, message) {
|
|
3
|
-
super(message);
|
|
4
|
-
this.code = code;
|
|
5
|
-
}
|
|
6
|
-
static tagLostError() {
|
|
7
|
-
return new NfcError(NfcError.ErrorCode.TagLostError, 'NFC tag lost');
|
|
8
|
-
}
|
|
9
|
-
static notConnectedError() {
|
|
10
|
-
return new NfcError(NfcError.ErrorCode.NotConnectedError, 'NFC tag is not connected');
|
|
11
|
-
}
|
|
12
|
-
static unknownError(errString) {
|
|
13
|
-
throw new NfcError(NfcError.ErrorCode.Unknown, errString);
|
|
14
|
-
}
|
|
15
|
-
static tagConnectionFailed() {
|
|
16
|
-
throw new NfcError(NfcError.ErrorCode.NotConnectedError, `Tag connection failed`);
|
|
17
|
-
}
|
|
18
|
-
static internalError(message) {
|
|
19
|
-
throw new NfcError(NfcError.ErrorCode.InternalError, message);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
(function (NfcError) {
|
|
23
|
-
let ErrorCode;
|
|
24
|
-
(function (ErrorCode) {
|
|
25
|
-
ErrorCode["Unknown"] = "NfcUnknownError";
|
|
26
|
-
ErrorCode["InternalError"] = "NfcInternalError";
|
|
27
|
-
ErrorCode["TagLostError"] = "NfcTagLostError";
|
|
28
|
-
ErrorCode["NotConnectedError"] = "NfcNotConnectedError";
|
|
29
|
-
})(ErrorCode = NfcError.ErrorCode || (NfcError.ErrorCode = {}));
|
|
30
|
-
})(NfcError || (NfcError = {}));
|
|
1
|
+
export class NfcError extends Error {
|
|
2
|
+
constructor(code, message) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.code = code;
|
|
5
|
+
}
|
|
6
|
+
static tagLostError() {
|
|
7
|
+
return new NfcError(NfcError.ErrorCode.TagLostError, 'NFC tag lost');
|
|
8
|
+
}
|
|
9
|
+
static notConnectedError() {
|
|
10
|
+
return new NfcError(NfcError.ErrorCode.NotConnectedError, 'NFC tag is not connected');
|
|
11
|
+
}
|
|
12
|
+
static unknownError(errString) {
|
|
13
|
+
throw new NfcError(NfcError.ErrorCode.Unknown, errString);
|
|
14
|
+
}
|
|
15
|
+
static tagConnectionFailed() {
|
|
16
|
+
throw new NfcError(NfcError.ErrorCode.NotConnectedError, `Tag connection failed`);
|
|
17
|
+
}
|
|
18
|
+
static internalError(message) {
|
|
19
|
+
throw new NfcError(NfcError.ErrorCode.InternalError, message);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
(function (NfcError) {
|
|
23
|
+
let ErrorCode;
|
|
24
|
+
(function (ErrorCode) {
|
|
25
|
+
ErrorCode["Unknown"] = "NfcUnknownError";
|
|
26
|
+
ErrorCode["InternalError"] = "NfcInternalError";
|
|
27
|
+
ErrorCode["TagLostError"] = "NfcTagLostError";
|
|
28
|
+
ErrorCode["NotConnectedError"] = "NfcNotConnectedError";
|
|
29
|
+
})(ErrorCode = NfcError.ErrorCode || (NfcError.ErrorCode = {}));
|
|
30
|
+
})(NfcError || (NfcError = {}));
|
|
31
31
|
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../../src/www/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,QAAS,SAAQ,KAAK;IACjC,YAAmB,IAAwB,EAAE,OAAe;QAC1D,KAAK,CAAC,OAAO,CAAC,CAAC;QADE,SAAI,GAAJ,IAAI,CAAoB;IAE3C,CAAC;IAEM,MAAM,CAAC,YAAY;QACxB,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;IACvE,CAAC;IAEM,MAAM,CAAC,iBAAiB;QAC7B,OAAO,IAAI,QAAQ,CACjB,QAAQ,CAAC,SAAS,CAAC,iBAAiB,EACpC,0BAA0B,CAC3B,CAAC;IACJ,CAAC;IAEM,MAAM,CAAC,YAAY,CAAC,SAAiB;QAC1C,MAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAC5D,CAAC;IAEM,MAAM,CAAC,mBAAmB;QAC/B,MAAM,IAAI,QAAQ,CAChB,QAAQ,CAAC,SAAS,CAAC,iBAAiB,EACpC,uBAAuB,CACxB,CAAC;IACJ,CAAC;IAEM,MAAM,CAAC,aAAa,CAAC,OAAe;QACzC,MAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IAChE,CAAC;CACF;AAED,WAAiB,QAAQ;IACvB,IAAY,SAKX;IALD,WAAY,SAAS;QACnB,wCAA2B,CAAA;QAC3B,+CAAkC,CAAA;QAClC,6CAAgC,CAAA;QAChC,uDAA0C,CAAA;IAC5C,CAAC,EALW,SAAS,GAAT,kBAAS,KAAT,kBAAS,QAKpB;AACH,CAAC,EAPgB,QAAQ,KAAR,QAAQ,QAOxB","sourcesContent":["export class NfcError extends Error {\
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../../src/www/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,QAAS,SAAQ,KAAK;IACjC,YAAmB,IAAwB,EAAE,OAAe;QAC1D,KAAK,CAAC,OAAO,CAAC,CAAC;QADE,SAAI,GAAJ,IAAI,CAAoB;IAE3C,CAAC;IAEM,MAAM,CAAC,YAAY;QACxB,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;IACvE,CAAC;IAEM,MAAM,CAAC,iBAAiB;QAC7B,OAAO,IAAI,QAAQ,CACjB,QAAQ,CAAC,SAAS,CAAC,iBAAiB,EACpC,0BAA0B,CAC3B,CAAC;IACJ,CAAC;IAEM,MAAM,CAAC,YAAY,CAAC,SAAiB;QAC1C,MAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAC5D,CAAC;IAEM,MAAM,CAAC,mBAAmB;QAC/B,MAAM,IAAI,QAAQ,CAChB,QAAQ,CAAC,SAAS,CAAC,iBAAiB,EACpC,uBAAuB,CACxB,CAAC;IACJ,CAAC;IAEM,MAAM,CAAC,aAAa,CAAC,OAAe;QACzC,MAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IAChE,CAAC;CACF;AAED,WAAiB,QAAQ;IACvB,IAAY,SAKX;IALD,WAAY,SAAS;QACnB,wCAA2B,CAAA;QAC3B,+CAAkC,CAAA;QAClC,6CAAgC,CAAA;QAChC,uDAA0C,CAAA;IAC5C,CAAC,EALW,SAAS,GAAT,kBAAS,KAAT,kBAAS,QAKpB;AACH,CAAC,EAPgB,QAAQ,KAAR,QAAQ,QAOxB","sourcesContent":["export class NfcError extends Error {\n constructor(public code: NfcError.ErrorCode, message: string) {\n super(message);\n }\n\n public static tagLostError() {\n return new NfcError(NfcError.ErrorCode.TagLostError, 'NFC tag lost');\n }\n\n public static notConnectedError() {\n return new NfcError(\n NfcError.ErrorCode.NotConnectedError,\n 'NFC tag is not connected'\n );\n }\n\n public static unknownError(errString: string): NfcError {\n throw new NfcError(NfcError.ErrorCode.Unknown, errString);\n }\n\n public static tagConnectionFailed() {\n throw new NfcError(\n NfcError.ErrorCode.NotConnectedError,\n `Tag connection failed`\n );\n }\n\n public static internalError(message: string) {\n throw new NfcError(NfcError.ErrorCode.InternalError, message);\n }\n}\n\nexport namespace NfcError {\n export enum ErrorCode {\n Unknown = 'NfcUnknownError',\n InternalError = 'NfcInternalError',\n TagLostError = 'NfcTagLostError',\n NotConnectedError = 'NfcNotConnectedError',\n }\n}\n"]}
|
package/esm2015/www/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from './cordova-interface';
|
|
2
|
-
export * from './errors';
|
|
3
|
-
export { TNF, WellKnownType } from './ndef/definitions';
|
|
4
|
-
export { parseNdefMessage, parseNdefMessages } from './ndef/parse-ndef-message';
|
|
5
|
-
export * from './nfc-com-protocol';
|
|
6
|
-
export * from './tap-ndef';
|
|
1
|
+
export * from './cordova-interface';
|
|
2
|
+
export * from './errors';
|
|
3
|
+
export { TNF, WellKnownType } from './ndef/definitions';
|
|
4
|
+
export { parseNdefMessage, parseNdefMessages } from './ndef/parse-ndef-message';
|
|
5
|
+
export * from './nfc-com-protocol';
|
|
6
|
+
export * from './tap-ndef';
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
package/esm2015/www/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/www/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAChF,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC","sourcesContent":["export * from './cordova-interface';\
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/www/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAChF,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC","sourcesContent":["export * from './cordova-interface';\nexport * from './errors';\nexport { TNF, WellKnownType } from './ndef/definitions';\nexport { parseNdefMessage, parseNdefMessages } from './ndef/parse-ndef-message';\nexport * from './nfc-com-protocol';\nexport * from './tap-ndef';\n"]}
|
package/esm2015/www/logger.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { createDebugger } from '@iotize/common/debug';
|
|
2
|
-
export const debug = createDebugger(`@iotize/device-com-nfc.cordova`);
|
|
1
|
+
import { createDebugger } from '@iotize/common/debug';
|
|
2
|
+
export const debug = createDebugger(`@iotize/device-com-nfc.cordova`);
|
|
3
3
|
//# sourceMappingURL=logger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../../../src/www/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,MAAM,CAAC,MAAM,KAAK,GAAG,cAAc,CAAC,gCAAgC,CAAC,CAAC","sourcesContent":["import { createDebugger } from '@iotize/common/debug';\
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../../../src/www/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,MAAM,CAAC,MAAM,KAAK,GAAG,cAAc,CAAC,gCAAgC,CAAC,CAAC","sourcesContent":["import { createDebugger } from '@iotize/common/debug';\n\nexport const debug = createDebugger(`@iotize/device-com-nfc.cordova`);"]}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
export var TNF;
|
|
2
|
-
(function (TNF) {
|
|
3
|
-
TNF[TNF["EMPTY"] = 0] = "EMPTY";
|
|
4
|
-
TNF[TNF["WELL_KNOWN_TYPE"] = 1] = "WELL_KNOWN_TYPE";
|
|
5
|
-
TNF[TNF["MIME_TYPE"] = 2] = "MIME_TYPE";
|
|
6
|
-
TNF[TNF["ABSOLUTE_URI"] = 3] = "ABSOLUTE_URI";
|
|
7
|
-
TNF[TNF["EXTERNAL"] = 4] = "EXTERNAL";
|
|
8
|
-
TNF[TNF["UNKNOWN"] = 5] = "UNKNOWN";
|
|
9
|
-
TNF[TNF["UNCHANGED"] = 6] = "UNCHANGED";
|
|
10
|
-
TNF[TNF["RFU"] = 7] = "RFU";
|
|
11
|
-
})(TNF || (TNF = {}));
|
|
12
|
-
export const WellKnownType = {
|
|
13
|
-
URI: [0x55],
|
|
14
|
-
TEXT: [0x54],
|
|
15
|
-
SMPART_POSTER: [0x53, 0x70],
|
|
16
|
-
};
|
|
1
|
+
export var TNF;
|
|
2
|
+
(function (TNF) {
|
|
3
|
+
TNF[TNF["EMPTY"] = 0] = "EMPTY";
|
|
4
|
+
TNF[TNF["WELL_KNOWN_TYPE"] = 1] = "WELL_KNOWN_TYPE";
|
|
5
|
+
TNF[TNF["MIME_TYPE"] = 2] = "MIME_TYPE";
|
|
6
|
+
TNF[TNF["ABSOLUTE_URI"] = 3] = "ABSOLUTE_URI";
|
|
7
|
+
TNF[TNF["EXTERNAL"] = 4] = "EXTERNAL";
|
|
8
|
+
TNF[TNF["UNKNOWN"] = 5] = "UNKNOWN";
|
|
9
|
+
TNF[TNF["UNCHANGED"] = 6] = "UNCHANGED";
|
|
10
|
+
TNF[TNF["RFU"] = 7] = "RFU";
|
|
11
|
+
})(TNF || (TNF = {}));
|
|
12
|
+
export const WellKnownType = {
|
|
13
|
+
URI: [0x55],
|
|
14
|
+
TEXT: [0x54],
|
|
15
|
+
SMPART_POSTER: [0x53, 0x70],
|
|
16
|
+
};
|
|
17
17
|
//# sourceMappingURL=definitions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../../../../../src/www/ndef/definitions.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,GASX;AATD,WAAY,GAAG;IACb,+BAAY,CAAA;IACZ,mDAAsB,CAAA;IACtB,uCAAgB,CAAA;IAChB,6CAAmB,CAAA;IACnB,qCAAe,CAAA;IACf,mCAAc,CAAA;IACd,uCAAgB,CAAA;IAChB,2BAAU,CAAA;AACZ,CAAC,EATW,GAAG,KAAH,GAAG,QASd;AAED,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,GAAG,EAAE,CAAC,IAAI,CAAC;IACX,IAAI,EAAE,CAAC,IAAI,CAAC;IACZ,aAAa,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;CAC5B,CAAC","sourcesContent":["export enum TNF {\
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../../../../../src/www/ndef/definitions.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,GASX;AATD,WAAY,GAAG;IACb,+BAAY,CAAA;IACZ,mDAAsB,CAAA;IACtB,uCAAgB,CAAA;IAChB,6CAAmB,CAAA;IACnB,qCAAe,CAAA;IACf,mCAAc,CAAA;IACd,uCAAgB,CAAA;IAChB,2BAAU,CAAA;AACZ,CAAC,EATW,GAAG,KAAH,GAAG,QASd;AAED,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,GAAG,EAAE,CAAC,IAAI,CAAC;IACX,IAAI,EAAE,CAAC,IAAI,CAAC;IACZ,aAAa,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;CAC5B,CAAC","sourcesContent":["export enum TNF {\n EMPTY = 0x00, // Empty\n WELL_KNOWN_TYPE = 0x01, // NFC Forum well-known type [NFC RTD]\n MIME_TYPE = 0x02, // Media-type [RFC 2046]\n ABSOLUTE_URI = 0x03, // Absolute URI [RFC 3986]\n EXTERNAL = 0x04, // NFC Forum external type [NFC RTD]\n UNKNOWN = 0x05,\n UNCHANGED = 0x06, //\n RFU = 0x07, // Reserved for future use\n}\n\nexport const WellKnownType = {\n URI: [0x55],\n TEXT: [0x54],\n SMPART_POSTER: [0x53, 0x70],\n};\n"]}
|
|
@@ -1,165 +1,165 @@
|
|
|
1
|
-
import { Buffer } from 'buffer';
|
|
2
|
-
import { arrayEquals, toAsciiString } from '../utility';
|
|
3
|
-
import { TNF, WellKnownType } from './definitions';
|
|
4
|
-
export function parseNdefMessages(messages) {
|
|
5
|
-
return (messages || []).map(parseNdefMessage);
|
|
6
|
-
}
|
|
7
|
-
export function parseNdefMessage(message) {
|
|
8
|
-
switch (message.tnf) {
|
|
9
|
-
case TNF.ABSOLUTE_URI:
|
|
10
|
-
return {
|
|
11
|
-
tnf: 'uri',
|
|
12
|
-
value: toAsciiString(message.payload),
|
|
13
|
-
};
|
|
14
|
-
case TNF.WELL_KNOWN_TYPE:
|
|
15
|
-
return {
|
|
16
|
-
tnf: 'wkt',
|
|
17
|
-
value: parseWellKnownType(message),
|
|
18
|
-
};
|
|
19
|
-
case TNF.EMPTY:
|
|
20
|
-
return {
|
|
21
|
-
tnf: 'empty',
|
|
22
|
-
value: {
|
|
23
|
-
type: message.type,
|
|
24
|
-
payload: message.payload,
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
case TNF.EXTERNAL:
|
|
28
|
-
return {
|
|
29
|
-
tnf: 'external',
|
|
30
|
-
value: paseExternalType(message),
|
|
31
|
-
};
|
|
32
|
-
case TNF.MIME_TYPE:
|
|
33
|
-
return {
|
|
34
|
-
tnf: 'mimetype',
|
|
35
|
-
value: parseMimeType(message),
|
|
36
|
-
};
|
|
37
|
-
case TNF.RFU:
|
|
38
|
-
return {
|
|
39
|
-
tnf: 'rfu',
|
|
40
|
-
value: {
|
|
41
|
-
type: message.type,
|
|
42
|
-
payload: message.payload,
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
case TNF.UNCHANGED:
|
|
46
|
-
return {
|
|
47
|
-
tnf: 'unchanged',
|
|
48
|
-
value: {
|
|
49
|
-
type: message.type,
|
|
50
|
-
payload: message.payload,
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
case TNF.UNKNOWN:
|
|
54
|
-
return {
|
|
55
|
-
tnf: 'unknown',
|
|
56
|
-
value: {
|
|
57
|
-
type: message.type,
|
|
58
|
-
payload: message.payload,
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
default:
|
|
62
|
-
return {
|
|
63
|
-
tnf: message.tnf,
|
|
64
|
-
value: {
|
|
65
|
-
type: message.type,
|
|
66
|
-
payload: message.payload,
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
function parseWellKnownType(message) {
|
|
72
|
-
if (arrayEquals(message.type, WellKnownType.URI)) {
|
|
73
|
-
const prefixCode = message.payload[0];
|
|
74
|
-
let prefix = WELL_KNOWN_TYPE_URI_PREFIX[prefixCode] || '';
|
|
75
|
-
return {
|
|
76
|
-
type: 'uri',
|
|
77
|
-
value: prefix + toAsciiString(message.payload.slice(1)),
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
else if (arrayEquals(message.type, WellKnownType.TEXT)) {
|
|
81
|
-
const encodingNumber = message.payload[0];
|
|
82
|
-
let encoding = 'utf8';
|
|
83
|
-
let languageSizeInBytes = 0;
|
|
84
|
-
if (typeof encodingNumber === 'number') {
|
|
85
|
-
// b0: encodage utf8 s’il vaut 0 et utf16 s’il vaut 1.
|
|
86
|
-
// b1: RFU (set to 0)
|
|
87
|
-
// b2-b7: la taille en octets de la langue (n)
|
|
88
|
-
// B8-B8+n-1: language
|
|
89
|
-
// Bn: message
|
|
90
|
-
const b0 = encodingNumber & 0b10000000;
|
|
91
|
-
encoding = b0 ? 'utf16le' : 'utf8';
|
|
92
|
-
languageSizeInBytes = encodingNumber & 0b00111111;
|
|
93
|
-
}
|
|
94
|
-
const text = message.payload.slice(languageSizeInBytes + 1);
|
|
95
|
-
return {
|
|
96
|
-
type: 'text',
|
|
97
|
-
value: Buffer.from(text).toString(encoding),
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
// else if (arrayEquals(message.type, WellKnownType.SMPART_POSTER)) {
|
|
101
|
-
// return {
|
|
102
|
-
// type: 'sp',
|
|
103
|
-
// // TODO implement
|
|
104
|
-
// payload: message.payload,
|
|
105
|
-
// };
|
|
106
|
-
// }
|
|
107
|
-
else {
|
|
108
|
-
return {
|
|
109
|
-
type: 'unknown',
|
|
110
|
-
value: {
|
|
111
|
-
type: message.type,
|
|
112
|
-
payload: message.payload,
|
|
113
|
-
},
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
function paseExternalType(message) {
|
|
118
|
-
const value = Buffer.from(message.payload).toString('utf8');
|
|
119
|
-
const domain = Buffer.from(message.type).toString('utf8');
|
|
120
|
-
return {
|
|
121
|
-
domain,
|
|
122
|
-
value,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
const WELL_KNOWN_TYPE_URI_PREFIX = {
|
|
126
|
-
0x0: '',
|
|
127
|
-
0x1: 'http://www.',
|
|
128
|
-
0x2: 'http://www.',
|
|
129
|
-
0x3: 'http://',
|
|
130
|
-
0x4: 'https://',
|
|
131
|
-
0x5: 'tel:',
|
|
132
|
-
0x6: 'mailto:',
|
|
133
|
-
0x07: 'ftp://anonymous:anonymous@',
|
|
134
|
-
0x1d: 'file://',
|
|
135
|
-
0x08: 'ftp://ftp.',
|
|
136
|
-
0x09: 'ftps://',
|
|
137
|
-
0x0a: 'sftp://',
|
|
138
|
-
0x0b: 'smb://',
|
|
139
|
-
0x0c: 'nfs://',
|
|
140
|
-
0x0d: 'ftp://',
|
|
141
|
-
0x0e: 'dav://',
|
|
142
|
-
0x0f: 'news:',
|
|
143
|
-
0x10: 'telnet://',
|
|
144
|
-
0x11: 'imap:',
|
|
145
|
-
0x12: 'rtsp://',
|
|
146
|
-
0x13: 'urn:',
|
|
147
|
-
0x14: 'pop:',
|
|
148
|
-
0x15: 'sip:',
|
|
149
|
-
0x16: 'sips:',
|
|
150
|
-
0x17: 'tftp:',
|
|
151
|
-
0x18: 'btspp://',
|
|
152
|
-
0x19: 'btl2cap://',
|
|
153
|
-
0x1a: 'btgoep://',
|
|
154
|
-
0x1b: 'tcpobex://',
|
|
155
|
-
0x1c: 'irdaobex://',
|
|
156
|
-
0x1e: 'urn:epc:id:',
|
|
157
|
-
0x1f: 'urn:epc:tag:',
|
|
158
|
-
0x20: 'urn:epc:pat:',
|
|
159
|
-
0x21: 'urn:epc:raw:',
|
|
160
|
-
0x22: 'urn:epc:',
|
|
161
|
-
};
|
|
162
|
-
function parseMimeType(message) {
|
|
163
|
-
return Buffer.from(message.payload).toString('utf8');
|
|
164
|
-
}
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
import { arrayEquals, toAsciiString } from '../utility';
|
|
3
|
+
import { TNF, WellKnownType } from './definitions';
|
|
4
|
+
export function parseNdefMessages(messages) {
|
|
5
|
+
return (messages || []).map(parseNdefMessage);
|
|
6
|
+
}
|
|
7
|
+
export function parseNdefMessage(message) {
|
|
8
|
+
switch (message.tnf) {
|
|
9
|
+
case TNF.ABSOLUTE_URI:
|
|
10
|
+
return {
|
|
11
|
+
tnf: 'uri',
|
|
12
|
+
value: toAsciiString(message.payload),
|
|
13
|
+
};
|
|
14
|
+
case TNF.WELL_KNOWN_TYPE:
|
|
15
|
+
return {
|
|
16
|
+
tnf: 'wkt',
|
|
17
|
+
value: parseWellKnownType(message),
|
|
18
|
+
};
|
|
19
|
+
case TNF.EMPTY:
|
|
20
|
+
return {
|
|
21
|
+
tnf: 'empty',
|
|
22
|
+
value: {
|
|
23
|
+
type: message.type,
|
|
24
|
+
payload: message.payload,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
case TNF.EXTERNAL:
|
|
28
|
+
return {
|
|
29
|
+
tnf: 'external',
|
|
30
|
+
value: paseExternalType(message),
|
|
31
|
+
};
|
|
32
|
+
case TNF.MIME_TYPE:
|
|
33
|
+
return {
|
|
34
|
+
tnf: 'mimetype',
|
|
35
|
+
value: parseMimeType(message),
|
|
36
|
+
};
|
|
37
|
+
case TNF.RFU:
|
|
38
|
+
return {
|
|
39
|
+
tnf: 'rfu',
|
|
40
|
+
value: {
|
|
41
|
+
type: message.type,
|
|
42
|
+
payload: message.payload,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
case TNF.UNCHANGED:
|
|
46
|
+
return {
|
|
47
|
+
tnf: 'unchanged',
|
|
48
|
+
value: {
|
|
49
|
+
type: message.type,
|
|
50
|
+
payload: message.payload,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
case TNF.UNKNOWN:
|
|
54
|
+
return {
|
|
55
|
+
tnf: 'unknown',
|
|
56
|
+
value: {
|
|
57
|
+
type: message.type,
|
|
58
|
+
payload: message.payload,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
default:
|
|
62
|
+
return {
|
|
63
|
+
tnf: message.tnf,
|
|
64
|
+
value: {
|
|
65
|
+
type: message.type,
|
|
66
|
+
payload: message.payload,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function parseWellKnownType(message) {
|
|
72
|
+
if (arrayEquals(message.type, WellKnownType.URI)) {
|
|
73
|
+
const prefixCode = message.payload[0];
|
|
74
|
+
let prefix = WELL_KNOWN_TYPE_URI_PREFIX[prefixCode] || '';
|
|
75
|
+
return {
|
|
76
|
+
type: 'uri',
|
|
77
|
+
value: prefix + toAsciiString(message.payload.slice(1)),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
else if (arrayEquals(message.type, WellKnownType.TEXT)) {
|
|
81
|
+
const encodingNumber = message.payload[0];
|
|
82
|
+
let encoding = 'utf8';
|
|
83
|
+
let languageSizeInBytes = 0;
|
|
84
|
+
if (typeof encodingNumber === 'number') {
|
|
85
|
+
// b0: encodage utf8 s’il vaut 0 et utf16 s’il vaut 1.
|
|
86
|
+
// b1: RFU (set to 0)
|
|
87
|
+
// b2-b7: la taille en octets de la langue (n)
|
|
88
|
+
// B8-B8+n-1: language
|
|
89
|
+
// Bn: message
|
|
90
|
+
const b0 = encodingNumber & 0b10000000;
|
|
91
|
+
encoding = b0 ? 'utf16le' : 'utf8';
|
|
92
|
+
languageSizeInBytes = encodingNumber & 0b00111111;
|
|
93
|
+
}
|
|
94
|
+
const text = message.payload.slice(languageSizeInBytes + 1);
|
|
95
|
+
return {
|
|
96
|
+
type: 'text',
|
|
97
|
+
value: Buffer.from(text).toString(encoding),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
// else if (arrayEquals(message.type, WellKnownType.SMPART_POSTER)) {
|
|
101
|
+
// return {
|
|
102
|
+
// type: 'sp',
|
|
103
|
+
// // TODO implement
|
|
104
|
+
// payload: message.payload,
|
|
105
|
+
// };
|
|
106
|
+
// }
|
|
107
|
+
else {
|
|
108
|
+
return {
|
|
109
|
+
type: 'unknown',
|
|
110
|
+
value: {
|
|
111
|
+
type: message.type,
|
|
112
|
+
payload: message.payload,
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function paseExternalType(message) {
|
|
118
|
+
const value = Buffer.from(message.payload).toString('utf8');
|
|
119
|
+
const domain = Buffer.from(message.type).toString('utf8');
|
|
120
|
+
return {
|
|
121
|
+
domain,
|
|
122
|
+
value,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const WELL_KNOWN_TYPE_URI_PREFIX = {
|
|
126
|
+
0x0: '',
|
|
127
|
+
0x1: 'http://www.',
|
|
128
|
+
0x2: 'http://www.',
|
|
129
|
+
0x3: 'http://',
|
|
130
|
+
0x4: 'https://',
|
|
131
|
+
0x5: 'tel:',
|
|
132
|
+
0x6: 'mailto:',
|
|
133
|
+
0x07: 'ftp://anonymous:anonymous@',
|
|
134
|
+
0x1d: 'file://',
|
|
135
|
+
0x08: 'ftp://ftp.',
|
|
136
|
+
0x09: 'ftps://',
|
|
137
|
+
0x0a: 'sftp://',
|
|
138
|
+
0x0b: 'smb://',
|
|
139
|
+
0x0c: 'nfs://',
|
|
140
|
+
0x0d: 'ftp://',
|
|
141
|
+
0x0e: 'dav://',
|
|
142
|
+
0x0f: 'news:',
|
|
143
|
+
0x10: 'telnet://',
|
|
144
|
+
0x11: 'imap:',
|
|
145
|
+
0x12: 'rtsp://',
|
|
146
|
+
0x13: 'urn:',
|
|
147
|
+
0x14: 'pop:',
|
|
148
|
+
0x15: 'sip:',
|
|
149
|
+
0x16: 'sips:',
|
|
150
|
+
0x17: 'tftp:',
|
|
151
|
+
0x18: 'btspp://',
|
|
152
|
+
0x19: 'btl2cap://',
|
|
153
|
+
0x1a: 'btgoep://',
|
|
154
|
+
0x1b: 'tcpobex://',
|
|
155
|
+
0x1c: 'irdaobex://',
|
|
156
|
+
0x1e: 'urn:epc:id:',
|
|
157
|
+
0x1f: 'urn:epc:tag:',
|
|
158
|
+
0x20: 'urn:epc:pat:',
|
|
159
|
+
0x21: 'urn:epc:raw:',
|
|
160
|
+
0x22: 'urn:epc:',
|
|
161
|
+
};
|
|
162
|
+
function parseMimeType(message) {
|
|
163
|
+
return Buffer.from(message.payload).toString('utf8');
|
|
164
|
+
}
|
|
165
165
|
//# sourceMappingURL=parse-ndef-message.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-ndef-message.js","sourceRoot":"","sources":["../../../../../../src/www/ndef/parse-ndef-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,MAAM,UAAU,iBAAiB,CAAC,QAAyC;IACzE,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,OAAmB;IAClD,QAAQ,OAAO,CAAC,GAAG,EAAE;QACnB,KAAK,GAAG,CAAC,YAAY;YACnB,OAAO;gBACL,GAAG,EAAE,KAAK;gBACV,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC;aACtC,CAAC;QACJ,KAAK,GAAG,CAAC,eAAe;YACtB,OAAO;gBACL,GAAG,EAAE,KAAK;gBACV,K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EAAE,cAAc;IACpB,IAAI,EAAE,UAAU;CACjB,CAAC;AAEF,SAAS,aAAa,CAAC,OAAoC;IACzD,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACvD,CAAC","sourcesContent":["import { Buffer } from 'buffer';\
|
|
1
|
+
{"version":3,"file":"parse-ndef-message.js","sourceRoot":"","sources":["../../../../../../src/www/ndef/parse-ndef-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,MAAM,UAAU,iBAAiB,CAAC,QAAyC;IACzE,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,OAAmB;IAClD,QAAQ,OAAO,CAAC,GAAG,EAAE;QACnB,KAAK,GAAG,CAAC,YAAY;YACnB,OAAO;gBACL,GAAG,EAAE,KAAK;gBACV,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC;aACtC,CAAC;QACJ,KAAK,GAAG,CAAC,eAAe;YACtB,OAAO;gBACL,GAAG,EAAE,KAAK;gBACV,KAAK,EAAE,kBAAkB,CAAC,OAAO,CAAC;aACnC,CAAC;QACJ,KAAK,GAAG,CAAC,KAAK;YACZ,OAAO;gBACL,GAAG,EAAE,OAAO;gBACZ,KAAK,EAAE;oBACL,IAAI,EAAE,OAAO,CAAC,IAAI;oBAClB,OAAO,EAAE,OAAO,CAAC,OAAO;iBACzB;aACF,CAAC;QACJ,KAAK,GAAG,CAAC,QAAQ;YACf,OAAO;gBACL,GAAG,EAAE,UAAU;gBACf,KAAK,EAAE,gBAAgB,CAAC,OAA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Q,CAAC,MAAM,CAAC,CAAC;IAC1D,OAAO;QACL,MAAM;QACN,KAAK;KACN,CAAC;AACJ,CAAC;AAED,MAAM,0BAA0B,GAAG;IACjC,GAAG,EAAE,EAAE;IACP,GAAG,EAAE,aAAa;IAClB,GAAG,EAAE,aAAa;IAClB,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,UAAU;IACf,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,SAAS;IACd,IAAI,EAAE,4BAA4B;IAClC,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,YAAY;IAClB,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,YAAY;IAClB,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,YAAY;IAClB,IAAI,EAAE,aAAa;IACnB,IAAI,EAAE,aAAa;IACnB,IAAI,EAAE,cAAc;IACpB,IAAI,EAAE,cAAc;IACpB,IAAI,EAAE,cAAc;IACpB,IAAI,EAAE,UAAU;CACjB,CAAC;AAEF,SAAS,aAAa,CAAC,OAAoC;IACzD,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACvD,CAAC","sourcesContent":["import { Buffer } from 'buffer';\nimport { NdefRecord } from '../tap-ndef/definitions';\nimport { arrayEquals, toAsciiString } from '../utility';\nimport { TNF, WellKnownType } from './definitions';\n\nexport function parseNdefMessages(messages: NdefRecord[] | undefined | null) {\n return (messages || []).map(parseNdefMessage);\n}\n\nexport function parseNdefMessage(message: NdefRecord) {\n switch (message.tnf) {\n case TNF.ABSOLUTE_URI:\n return {\n tnf: 'uri',\n value: toAsciiString(message.payload),\n };\n case TNF.WELL_KNOWN_TYPE:\n return {\n tnf: 'wkt',\n value: parseWellKnownType(message),\n };\n case TNF.EMPTY:\n return {\n tnf: 'empty',\n value: {\n type: message.type,\n payload: message.payload,\n },\n };\n case TNF.EXTERNAL:\n return {\n tnf: 'external',\n value: paseExternalType(message),\n };\n case TNF.MIME_TYPE:\n return {\n tnf: 'mimetype',\n value: parseMimeType(message),\n };\n case TNF.RFU:\n return {\n tnf: 'rfu',\n value: {\n type: message.type,\n payload: message.payload,\n },\n };\n case TNF.UNCHANGED:\n return {\n tnf: 'unchanged',\n value: {\n type: message.type,\n payload: message.payload,\n },\n };\n case TNF.UNKNOWN:\n return {\n tnf: 'unknown',\n value: {\n type: message.type,\n payload: message.payload,\n },\n };\n default:\n return {\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, 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, 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 return {\n type: 'text',\n value: Buffer.from(text).toString(encoding),\n };\n }\n // else if (arrayEquals(message.type, 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,\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"]}
|