From e2158078bab5ac5446698d5b2f1873296e2383cc Mon Sep 17 00:00:00 2001 From: Michael DESIGAUD Date: Wed, 24 Feb 2016 18:50:47 +0100 Subject: [PATCH 1/5] Add phonegap nfc plugin typing --- phonegap-nfc/PhoneGapNfc-ndef-tests.ts | 27 ++ phonegap-nfc/PhoneGapNfc-nfc-tests.ts | 50 +++ phonegap-nfc/PhoneGapNfc.d.ts | 456 +++++++++++++++++++++++++ 3 files changed, 533 insertions(+) create mode 100644 phonegap-nfc/PhoneGapNfc-ndef-tests.ts create mode 100644 phonegap-nfc/PhoneGapNfc-nfc-tests.ts create mode 100644 phonegap-nfc/PhoneGapNfc.d.ts diff --git a/phonegap-nfc/PhoneGapNfc-ndef-tests.ts b/phonegap-nfc/PhoneGapNfc-ndef-tests.ts new file mode 100644 index 00000000000000..29b8c13269d00c --- /dev/null +++ b/phonegap-nfc/PhoneGapNfc-ndef-tests.ts @@ -0,0 +1,27 @@ +/// + +let record:NdefRecord = ndef.record(0x01,[0x0F],[0x0C],[0xFF]); + +record = ndef.textRecord('textRecord','fr',[24,78]); + +record = ndef.uriRecord('uriRecord',[24,78]); + +record = ndef.absoluteUriRecord('uriRecord',[88,142],[24,78]); + +record = ndef.mimeMediaRecord('text/json',[88,142],[24,78]); + +record = ndef.smartPoster([],[88,142]); + +record = ndef.emptyRecord(); + +record = ndef.androidApplicationRecord('fr.redfroggy.phonegap'); + +let bytes:Array = ndef.encodeMessage([]); + +let records:Array = ndef.decodeMessage(bytes); + +let obj:any = ndef.decodeTnf(bytes[0]); + +let tnfByte:number = ndef.encodeTnf(bytes[0],bytes[1],bytes[2],bytes[3],bytes[4],bytes[5]); + +let tnfString:string = ndef.tnfToString(tnfByte); diff --git a/phonegap-nfc/PhoneGapNfc-nfc-tests.ts b/phonegap-nfc/PhoneGapNfc-nfc-tests.ts new file mode 100644 index 00000000000000..e677ccdccc7471 --- /dev/null +++ b/phonegap-nfc/PhoneGapNfc-nfc-tests.ts @@ -0,0 +1,50 @@ +/// + +nfc.addTagDiscoveredListener(() => {}); +nfc.addTagDiscoveredListener(() => {},() => {}, () => {}); + +nfc.addMimeTypeListener('text/json',() => {}); +nfc.addMimeTypeListener('text/json',() => {},() => {}, () => {}); + +nfc.addNdefListener(() => {}); +nfc.addNdefListener(() => {}, () => {},() => {}); + +nfc.addNdefFormatableListener(() => {}); +nfc.addNdefFormatableListener(() => {}, () => {}, () => {}); + +nfc.write([],() => {}, () => {}); + +nfc.makeReadOnly(); +nfc.makeReadOnly(() => {}, () => {}); + +nfc.share([]); +nfc.share([],() => {}, () => {}); + +nfc.unshare(); +nfc.unshare(() => {}, () => {}); + +nfc.handover('uri',() => {}, () => {}); +nfc.handover(['uri'],() => {}, () => {}); +nfc.handover('uri'); +nfc.handover(['uri']); + +nfc.stopHandover(); +nfc.stopHandover(() => {}, () => {}); + +nfc.erase(); +nfc.erase(() => {}, () => {}); + +nfc.enabled(); +nfc.enabled(() => {}, () => {}); + +nfc.removeTagDiscoveredListener(() => {}); +nfc.removeTagDiscoveredListener(() => {},() => {},() => {}); + +nfc.removeMimeTypeListener('text/json',() => {}); +nfc.removeMimeTypeListener('text/json',() => {},() => {},() => {}); + +nfc.removeNdefListener(() => {}); +nfc.removeNdefListener(() => {},() => {},() => {}); + +nfc.showSettings(); +nfc.showSettings(() => {},() => {}); diff --git a/phonegap-nfc/PhoneGapNfc.d.ts b/phonegap-nfc/PhoneGapNfc.d.ts new file mode 100644 index 00000000000000..21c7b959cd6459 --- /dev/null +++ b/phonegap-nfc/PhoneGapNfc.d.ts @@ -0,0 +1,456 @@ +// Type definitions for Phonegap NFC Plugin +// Project: https://github.com/chariotsolutions/phonegap-nfc +// Definitions by: Michael Desigaud +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +interface Document { + addEventListener(type: 'deviceready', listener: (ev: Event) => any, useCapture?: boolean): void; +} + +/** + * Global object NFC. + */ +interface Window { + nfc: Nfc; + ndef: Ndef; + util:Util; + fireNfcTagEvent(event:TagEvent, tagAsJson:string):void; +} + +interface Tag { + id:Array; + techTypes:Array; + type:string; + date:string; +} + +interface NdefRecord { + /** + * 3-bit TNF (Type Name Format) - use one of the TNF_* constants + */ + tnf:number; + /** + * byte array, containing zero to 255 bytes, must not be null + */ + type:Array; + /** + * byte array, containing zero to 255 bytes, must not be null + */ + id:Array; + /** + * byte array, containing zero to (2 ** 32 - 1) bytes, must not be null + */ + payload:Array; +} + +interface NdefTag extends Tag { + canMakeReadOnly:boolean; + isWritable:boolean; + maxSize:number; + records:Array; +} + +interface TagEvent extends Event { + tag:Tag; +} + +interface NdefTagEvent extends TagEvent { + tag:NdefTag; +} + +interface UriHelper { + /** + * URI identifier codes from URI Record Type Definition NFCForum-TS-RTD_URI_1.0 2006-07-24 + * index in array matches code in the spec + */ + protocols:Array; + + /** + * Decode a URI payload bytes + * @param data + */ + decodePayload(data:any):string; + + /** + * shorten a URI with standard prefix + * @param uri + */ + encodePayload(uri:string):Array; +} + +interface TextHelper { + + /** + * Decode a URI payload bytes + * @param data + */ + decodePayload(data:any):string; + + /** + * Encode text payload + * @param text + * @param lang + * @param encoding + */ + encodePayload(text:string, lang:string, encoding:string):Array; +} + +/** + * The Ndef object. + */ +interface Ndef { + + TNF_EMPTY:number; + TNF_WELL_KNOWN: number; + TNF_MIME_MEDIA: number; + TNF_ABSOLUTE_URI: number; + TNF_EXTERNAL_TYPE: number; + TNF_UNKNOWN: number; + TNF_UNCHANGED: number; + TNF_RESERVED: number; + + RTD_TEXT: Array; // "T" + RTD_URI: Array; // "U" + RTD_SMART_POSTER: Array; // "Sp" + RTD_ALTERNATIVE_CARRIER: Array; // "ac" + RTD_HANDOVER_CARRIER: Array; // "Hc" + RTD_HANDOVER_REQUEST: Array; // "Hr" + RTD_HANDOVER_SELECT: Array; // "Hs" + + uriHelper:UriHelper; + textHelper:TextHelper; + /** + * Creates a JSON representation of a NdefRecord. + * + * @param tnf 3-bit TNF (Type Name Format) - use one of the TNF_* constants + * @param type array, containing zero to 255 bytes, must not be null + * @param id byte array, containing zero to 255 bytes, must not be null + * @param payload byte array, containing zero to (2 ** 32 - 1) bytes, must not be null + * + * @return NdefRecord + * + * @see Ndef.textRecord, Ndef.uriRecord and Ndef.mimeMediaRecord for examples + */ + record(tnf:number, type:Array, id:Array, payload:Array):NdefRecord; + + /** + * Helper that creates an NdefRecord containing plain text. + * + * @param text String of text to encode + * @paramlanguageCode ISO/IANA language code. Examples: “fi”, “en-US”, “fr- CA”, “jp”. (optional) + * @param id byte[] (optional) + * + * @return NdefRecord + */ + textRecord(text:string, languageCode:string, id:Array):NdefRecord; + + /** + * Helper that creates a NdefRecord containing a URI. + * + * @param uri String + * @param id byte[] (optional) + * + * @return NdefRecord + */ + uriRecord(uri:string, id:Array):NdefRecord; + + /** + * Helper that creates a NdefRecord containing an absolute URI. + * + * An Absolute URI record means the URI describes the payload of the record. + * + * For example a SOAP message could use "http://schemas.xmlsoap.org/soap/envelope/" + * as the type and XML content for the payload. + * + * Absolute URI can also be used to write LaunchApp records for Windows. + * + * See 2.4.2 Payload Type of the NDEF Specification + * http://www.nfc-forum.org/specs/spec_list#ndefts + * + * Note that by default, Android will open the URI defined in the type + * field of an Absolute URI record (TNF=3) and ignore the payload. + * BlackBerry and Windows do not open the browser for TNF=3. + * + * To write a URI as the payload use ndef.uriRecord(uri) + * + * @param uri String + * @param payload byte[] or String + * @param id byte[] (optional) + * + * @return NdefRecord + */ + absoluteUriRecord(uri:string, payload:Array, id:Array):NdefRecord; + + /** + * Helper that creates a NdefRecordcontaining an mimeMediaRecord. + * + * @param mimeType String + * @param payload byte[] + * @param id byte[] (optional) + */ + mimeMediaRecord(mimeType:string, payload:Array, id:Array):NdefRecord; + + /** + * Helper that creates an NDEF record containing an Smart Poster. + * + * @param ndefRecords array of NdefRecord + * @param id byte[] (optional) + * + * @return NdefRecord + */ + smartPoster(ndefRecords:Array, id:Array):NdefRecord; + + /** + * Helper that creates an empty NdefRecord. + * + */ + emptyRecord():NdefRecord; + + /** + * Helper that creates an Android Application Record (AAR). + * http://developer.android.com/guide/topics/connectivity/nfc/nfc.html#aar + * @param packageName android package name + * + */ + androidApplicationRecord(packageName:string):NdefRecord; + + /** + * Encodes an NDEF Message into bytes that can be written to a NFC tag. + * + * @param ndefRecords an Array of NdefRecord + * + * @return Array + * + * @see NFC Data Exchange Format (NDEF) http://www.nfc-forum.org/specs/spec_list/ + */ + encodeMessage(ndefRecords:Array):Array; + + /** + * Decodes an array bytes into an NDEF Message + * + * @param bytes Array read from a NFC tag + * + * @return array of NdefRecord + * + * @see NFC Data Exchange Format (NDEF) http://www.nfc-forum.org/specs/spec_list/ + */ + decodeMessage(bytes:Array):Array; + + /** + * Decode the bit flags from a TNF Byte. + * + * @return object with decoded data + * + * See NFC Data Exchange Format (NDEF) Specification Section 3.2 RecordLayout + */ + decodeTnf(tnf_byte:number):any; + + /** + * Encode NDEF bit flags into a TNF Byte. + * + * @return tnf byte + * + * See NFC Data Exchange Format (NDEF) Specification Section 3.2 RecordLayout + */ + encodeTnf(mb:number, me:number, cf:number, sr:number, il:number, tnf:number):number; + + /** + * Convert TNF to String for user friendly display + * + *@param tnf tnf byte + */ + tnfToString(tnf:number):string; +} + +interface Util { + /** + * Convert bytes to string + * @param bytes + */ + bytesToString(bytes:Array):string; + + /** + * Convert string to bytes + * @param string + */ + stringToBytes(string:string):Array; + + /** + * Convert bytes to hexadecimal string + * @param bytes + */ + bytesToHexString(bytes:Array):string; +} + +/** + * The Nfc object. + */ +interface Nfc extends Util { + /** + * Function nfc.addTagDiscoveredListener registers the callback for tag events. + * This event occurs when any tag is detected by the phone + * @param callback The callback that is called when a tag is detected. + * @param win The callback that is called when the listener is added. + * @param fail The callback that is called if there was an error. + */ + addTagDiscoveredListener(callback:(event:TagEvent) => void, win?:() => void, fail?:() => void):void; + + /** + * Function nfc.addMimeTypeListener registers the callback for ndef-mime events. + * A ndef-mime event occurs when a Ndef.TNF_MIME_MEDIA tag is read and matches the specified MIME type. + * This function can be called multiple times to register different MIME types. You should use the same handler for all MIME messages. + * @param mimeType The MIME type to filter for messages. + * @param callback The callback that is called when an NDEF tag matching the MIME type is read. + * @param win The callback that is called when the listener is added. + * @param fail The callback that is called if there was an error. + */ + addMimeTypeListener(mimeType:string, callback:() => void, win?:() => void, fail?:() => void):void; + + /** + * Function nfc.addNdefListener registers the callback for ndef events. + * A ndef event is fired when a NDEF tag is read. + * For BlackBerry 10, you must configure the type of tags your application will read with an invoke-target in config.xml. + * On Android registered mimeTypeListeners takes precedence over this more generic NDEF listener. + * @param callback The callback that is called when an NDEF tag is read. + * @param win The callback that is called when the listener is added. + * @param fail The callback that is called if there was an error. + */ + addNdefListener(callback:(event:NdefTagEvent) => void, win?:() => void, fail?:() => void):void; + + /** + * Function nfc.addNdefFormatableListener registers the callback for ndef-formatable events. + * A ndef-formatable event occurs when a tag is read that can be NDEF formatted. + * This is not fired for tags that are already formatted as NDEF. + * The ndef-formatable event will not contain an NdefMessage. + * @param callback The callback that is called when NDEF formatable tag is read. + * @param win The callback that is called when the listener is added. + * @param fail The callback that is called if there was an error. + */ + addNdefFormatableListener(callback:(event:NdefTagEvent) => void, win?:() => void, fail?:() => void):void; + + /** + * Function nfc.write writes an NdefMessage to a NFC tag. + * On Android this method must be called from within an NDEF TagEvent Handler. + * On Windows this method may be called from within the NDEF TagEvent Handler. + * On Windows Phone 8.1 this method should be called outside the NDEF TagEvent Handler, + * otherwise Windows tries to read the tag contents as you are writing to the tag. + * @param ndefMessage An array of NDEF Records. + * @param win The callback that is called when the tag is written. + * @param fail The callback that is called if there was an error. + */ + write(ndefMessage:Array, win?:() => void, fail?:() => void):void; + + /** + * Function nfc.makeReadOnly make a NFC tag read only. + * Warning this is permanent and can not be undone. + * On Android this method must be called from within an NDEF TagEvent Handler. + * @param win The callback that is called when the tag is locked. + * @param fail The callback that is called if there was an error. + */ + makeReadOnly(win?:() => void, fail?:() => void):void; + + /** + * Function nfc.share writes an NdefMessage via peer-to-peer. + * This should appear as an NFC tag to another device. + * @param ndefMessage An array of NDEF Records. + * @param win The callback that is called when the message is pushed. + * @param fail The callback that is called if there was an error. + */ + share(ndefMessage:Array, win?:() => void, fail?:() => void):void; + + /** + * Function nfc.unshare stops sharing data via peer-to-peer. + * @param win The callback that is called when sharing stops. + * @param fail The callback that is called if there was an error. + */ + unshare(win?:() => void, fail?:() => void):void; + + /** + * Function nfc.handover shares files to a NFC peer using handover. Files are sent by specifying a file:// or context:// URI or a list of URIs. + * The file transfer is initiated with NFC but the transfer is completed with over Bluetooth or WiFi which is handled by a NFC handover request. + * The Android code is responsible for building the handover NFC Message. + * This is Android only, but it should be possible to add implementations for other platforms. + * @param uris A URI as a String, or an array of URIs. + * @param win The callback that is called when the message is pushed. + * @param fail The callback that is called if there was an error. + */ + handover(uris:string|Array, win?:() => void, fail?:() => void):void; + + /** + * Function nfc.stopHandover stops sharing data via peer-to-peer. + * @param win The callback that is called when sharing stops. + * @param fail The callback that is called if there was an error. + */ + stopHandover(win?:() => void, fail?:() => void):void; + + /** + * Function nfc.erase erases a tag by writing an empty message. + * Will format unformatted tags before writing. + * This method must be called from within an NDEF TagEvent Handler. + * @param win The callback that is called when sharing stops. + * @param fail The callback that is called if there was an error. + */ + erase(win?:() => void, fail?:() => void):void; + + /** + * Function nfc.enabled explicitly checks to see if the phone has NFC and if NFC is enabled. + * If everything is OK, the success callback is called. + * If there is a problem, the failure callback will be called with a reason code. + * The reason will be NO_NFC if the device doesn't support NFC and NFC_DISABLED if the user has disabled NFC. + * Note: that on Android the NFC status is checked before every API call NO_NFC or NFC_DISABLED can be returned in any failure function. + * Windows will return NO_NFC_OR_NFC_DISABLED when NFC is not present or disabled. + * If the user disabled NFC after the application started, Windows may return NFC_DISABLED. + * Windows checks the NFC status before most API calls, but there are some cases when the NFC state can not be determined. + * @param win The callback that is called when NFC is enabled. + * @param fail The callback that is called when NFC is disabled or missing. + */ + enabled(win?:() => void, fail?:() => void):void; + + /** + * Removes the previously registered event listener added via nfc.addTagDiscoveredListener + * @param callback The previously registered callback. + * @param win The callback that is called when the listener is successfully removed. + * @param fail The callback that is called if there was an error during removal. + */ + removeTagDiscoveredListener(callback:(event:TagEvent) => void, win?:() => void, fail?:() => void):void; + + /** + * Removes the previously registered event listener added via nfc.addMimeTypeListener + * @param mimeType The MIME type to filter for messages. + * @param callback The previously registered callback. + * @param win The callback that is called when the listener is successfully removed. + * @param fail The callback that is called if there was an error during removal. + */ + removeMimeTypeListener(mimeType:string, callback:(event:TagEvent) => void, win?:() => void, fail?:() => void):void; + + /** + * Removes the previously registered event listener for NDEF tags added via nfc.addNdefListener. + * @param callback The previously registered callback. + * @param win The callback that is called when the listener is successfully removed. + * @param fail The callback that is called if there was an error during removal. + */ + removeNdefListener(callback:(event:TagEvent) => void, win?:() => void, fail?:() => void):void; + + /** + * Function showSettings opens the NFC settings for the operating system. + * @param win Success callback function + * @param fail Error callback function, invoked when error occurs. + */ + showSettings(win?:() => void, fail?:() => void):void; +} + +declare var ndef:Ndef; +declare var nfc:Nfc; +declare var util:Util; + + +declare module 'ndef' { + export = ndef; +} + +declare module 'nfc' { + export = nfc; +} + + + From 7d71ad4c0dc842ca0c0573483e60e972f2ec5ea4 Mon Sep 17 00:00:00 2001 From: Michael DESIGAUD Date: Wed, 24 Feb 2016 19:03:01 +0100 Subject: [PATCH 2/5] Fix typescript file name --- .../{PhoneGapNfc-ndef-tests.ts => phonegap-nfc-ndef-tests.ts} | 2 +- .../{PhoneGapNfc-nfc-tests.ts => phonegap-nfc-nfc-tests.ts} | 2 +- phonegap-nfc/{PhoneGapNfc.d.ts => phonegap-nfc.d.ts} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename phonegap-nfc/{PhoneGapNfc-ndef-tests.ts => phonegap-nfc-ndef-tests.ts} (94%) rename phonegap-nfc/{PhoneGapNfc-nfc-tests.ts => phonegap-nfc-nfc-tests.ts} (96%) rename phonegap-nfc/{PhoneGapNfc.d.ts => phonegap-nfc.d.ts} (100%) diff --git a/phonegap-nfc/PhoneGapNfc-ndef-tests.ts b/phonegap-nfc/phonegap-nfc-ndef-tests.ts similarity index 94% rename from phonegap-nfc/PhoneGapNfc-ndef-tests.ts rename to phonegap-nfc/phonegap-nfc-ndef-tests.ts index 29b8c13269d00c..9f836c6dd63238 100644 --- a/phonegap-nfc/PhoneGapNfc-ndef-tests.ts +++ b/phonegap-nfc/phonegap-nfc-ndef-tests.ts @@ -1,4 +1,4 @@ -/// +/// let record:NdefRecord = ndef.record(0x01,[0x0F],[0x0C],[0xFF]); diff --git a/phonegap-nfc/PhoneGapNfc-nfc-tests.ts b/phonegap-nfc/phonegap-nfc-nfc-tests.ts similarity index 96% rename from phonegap-nfc/PhoneGapNfc-nfc-tests.ts rename to phonegap-nfc/phonegap-nfc-nfc-tests.ts index e677ccdccc7471..c596a99d7fc4f3 100644 --- a/phonegap-nfc/PhoneGapNfc-nfc-tests.ts +++ b/phonegap-nfc/phonegap-nfc-nfc-tests.ts @@ -1,4 +1,4 @@ -/// +/// nfc.addTagDiscoveredListener(() => {}); nfc.addTagDiscoveredListener(() => {},() => {}, () => {}); diff --git a/phonegap-nfc/PhoneGapNfc.d.ts b/phonegap-nfc/phonegap-nfc.d.ts similarity index 100% rename from phonegap-nfc/PhoneGapNfc.d.ts rename to phonegap-nfc/phonegap-nfc.d.ts From bb6fa13eac14f20b1b837af83529d9cc293528ca Mon Sep 17 00:00:00 2001 From: Michael DESIGAUD Date: Fri, 26 Feb 2016 17:52:32 +0100 Subject: [PATCH 3/5] Rename test file --- phonegap-nfc/phonegap-nfc-ndef-tests.ts | 27 ------------------- ...nfc-nfc-tests.ts => phonegap-nfc.tests.ts} | 26 ++++++++++++++++++ 2 files changed, 26 insertions(+), 27 deletions(-) delete mode 100644 phonegap-nfc/phonegap-nfc-ndef-tests.ts rename phonegap-nfc/{phonegap-nfc-nfc-tests.ts => phonegap-nfc.tests.ts} (63%) diff --git a/phonegap-nfc/phonegap-nfc-ndef-tests.ts b/phonegap-nfc/phonegap-nfc-ndef-tests.ts deleted file mode 100644 index 9f836c6dd63238..00000000000000 --- a/phonegap-nfc/phonegap-nfc-ndef-tests.ts +++ /dev/null @@ -1,27 +0,0 @@ -/// - -let record:NdefRecord = ndef.record(0x01,[0x0F],[0x0C],[0xFF]); - -record = ndef.textRecord('textRecord','fr',[24,78]); - -record = ndef.uriRecord('uriRecord',[24,78]); - -record = ndef.absoluteUriRecord('uriRecord',[88,142],[24,78]); - -record = ndef.mimeMediaRecord('text/json',[88,142],[24,78]); - -record = ndef.smartPoster([],[88,142]); - -record = ndef.emptyRecord(); - -record = ndef.androidApplicationRecord('fr.redfroggy.phonegap'); - -let bytes:Array = ndef.encodeMessage([]); - -let records:Array = ndef.decodeMessage(bytes); - -let obj:any = ndef.decodeTnf(bytes[0]); - -let tnfByte:number = ndef.encodeTnf(bytes[0],bytes[1],bytes[2],bytes[3],bytes[4],bytes[5]); - -let tnfString:string = ndef.tnfToString(tnfByte); diff --git a/phonegap-nfc/phonegap-nfc-nfc-tests.ts b/phonegap-nfc/phonegap-nfc.tests.ts similarity index 63% rename from phonegap-nfc/phonegap-nfc-nfc-tests.ts rename to phonegap-nfc/phonegap-nfc.tests.ts index c596a99d7fc4f3..db9fce2b5523f4 100644 --- a/phonegap-nfc/phonegap-nfc-nfc-tests.ts +++ b/phonegap-nfc/phonegap-nfc.tests.ts @@ -48,3 +48,29 @@ nfc.removeNdefListener(() => {},() => {},() => {}); nfc.showSettings(); nfc.showSettings(() => {},() => {}); + +let record:NdefRecord = ndef.record(0x01,[0x0F],[0x0C],[0xFF]); + +record = ndef.textRecord('textRecord','fr',[24,78]); + +record = ndef.uriRecord('uriRecord',[24,78]); + +record = ndef.absoluteUriRecord('uriRecord',[88,142],[24,78]); + +record = ndef.mimeMediaRecord('text/json',[88,142],[24,78]); + +record = ndef.smartPoster([],[88,142]); + +record = ndef.emptyRecord(); + +record = ndef.androidApplicationRecord('fr.redfroggy.phonegap'); + +let bytes:Array = ndef.encodeMessage([]); + +let records:Array = ndef.decodeMessage(bytes); + +let obj:any = ndef.decodeTnf(bytes[0]); + +let tnfByte:number = ndef.encodeTnf(bytes[0],bytes[1],bytes[2],bytes[3],bytes[4],bytes[5]); + +let tnfString:string = ndef.tnfToString(tnfByte); From b4d480dde69dfdebe8c2c453d25ee924c0702dd6 Mon Sep 17 00:00:00 2001 From: Michael DESIGAUD Date: Fri, 26 Feb 2016 22:21:29 +0100 Subject: [PATCH 4/5] Fix modules --- phonegap-nfc/phonegap-nfc.d.ts | 876 +++++++++++++++-------------- phonegap-nfc/phonegap-nfc.tests.ts | 4 + 2 files changed, 444 insertions(+), 436 deletions(-) diff --git a/phonegap-nfc/phonegap-nfc.d.ts b/phonegap-nfc/phonegap-nfc.d.ts index 21c7b959cd6459..1a6c7bfd8edb82 100644 --- a/phonegap-nfc/phonegap-nfc.d.ts +++ b/phonegap-nfc/phonegap-nfc.d.ts @@ -7,450 +7,454 @@ interface Document { addEventListener(type: 'deviceready', listener: (ev: Event) => any, useCapture?: boolean): void; } -/** - * Global object NFC. - */ -interface Window { - nfc: Nfc; - ndef: Ndef; - util:Util; - fireNfcTagEvent(event:TagEvent, tagAsJson:string):void; +declare module PhoneGapNfc { + + /** + * Global object NFC. + */ + interface Window { + nfc: Nfc; + ndef: Ndef; + util:Util; + fireNfcTagEvent(event:TagEvent, tagAsJson:string):void; + } + + interface Tag { + id:Array; + techTypes:Array; + type:string; + date:string; + } + + interface NdefRecord { + /** + * 3-bit TNF (Type Name Format) - use one of the TNF_* constants + */ + tnf:number; + /** + * byte array, containing zero to 255 bytes, must not be null + */ + type:Array; + /** + * byte array, containing zero to 255 bytes, must not be null + */ + id:Array; + /** + * byte array, containing zero to (2 ** 32 - 1) bytes, must not be null + */ + payload:Array; + } + + interface NdefTag extends Tag { + canMakeReadOnly:boolean; + isWritable:boolean; + maxSize:number; + records:Array; + } + + interface TagEvent extends Event { + tag:Tag; + } + + interface NdefTagEvent extends TagEvent { + tag:NdefTag; + } + + interface UriHelper { + /** + * URI identifier codes from URI Record Type Definition NFCForum-TS-RTD_URI_1.0 2006-07-24 + * index in array matches code in the spec + */ + protocols:Array; + + /** + * Decode a URI payload bytes + * @param data + */ + decodePayload(data:any):string; + + /** + * shorten a URI with standard prefix + * @param uri + */ + encodePayload(uri:string):Array; + } + + interface TextHelper { + + /** + * Decode a URI payload bytes + * @param data + */ + decodePayload(data:any):string; + + /** + * Encode text payload + * @param text + * @param lang + * @param encoding + */ + encodePayload(text:string, lang:string, encoding:string):Array; + } + + /** + * The Ndef object. + */ + interface Ndef { + + TNF_EMPTY:number; + TNF_WELL_KNOWN: number; + TNF_MIME_MEDIA: number; + TNF_ABSOLUTE_URI: number; + TNF_EXTERNAL_TYPE: number; + TNF_UNKNOWN: number; + TNF_UNCHANGED: number; + TNF_RESERVED: number; + + RTD_TEXT: Array; // "T" + RTD_URI: Array; // "U" + RTD_SMART_POSTER: Array; // "Sp" + RTD_ALTERNATIVE_CARRIER: Array; // "ac" + RTD_HANDOVER_CARRIER: Array; // "Hc" + RTD_HANDOVER_REQUEST: Array; // "Hr" + RTD_HANDOVER_SELECT: Array; // "Hs" + + uriHelper:UriHelper; + textHelper:TextHelper; + /** + * Creates a JSON representation of a NdefRecord. + * + * @param tnf 3-bit TNF (Type Name Format) - use one of the TNF_* constants + * @param type array, containing zero to 255 bytes, must not be null + * @param id byte array, containing zero to 255 bytes, must not be null + * @param payload byte array, containing zero to (2 ** 32 - 1) bytes, must not be null + * + * @return NdefRecord + * + * @see Ndef.textRecord, Ndef.uriRecord and Ndef.mimeMediaRecord for examples + */ + record(tnf:number, type:Array, id:Array, payload:Array):NdefRecord; + + /** + * Helper that creates an NdefRecord containing plain text. + * + * @param text String of text to encode + * @paramlanguageCode ISO/IANA language code. Examples: “fi”, “en-US”, “fr- CA”, “jp”. (optional) + * @param id byte[] (optional) + * + * @return NdefRecord + */ + textRecord(text:string, languageCode:string, id:Array):NdefRecord; + + /** + * Helper that creates a NdefRecord containing a URI. + * + * @param uri String + * @param id byte[] (optional) + * + * @return NdefRecord + */ + uriRecord(uri:string, id:Array):NdefRecord; + + /** + * Helper that creates a NdefRecord containing an absolute URI. + * + * An Absolute URI record means the URI describes the payload of the record. + * + * For example a SOAP message could use "http://schemas.xmlsoap.org/soap/envelope/" + * as the type and XML content for the payload. + * + * Absolute URI can also be used to write LaunchApp records for Windows. + * + * See 2.4.2 Payload Type of the NDEF Specification + * http://www.nfc-forum.org/specs/spec_list#ndefts + * + * Note that by default, Android will open the URI defined in the type + * field of an Absolute URI record (TNF=3) and ignore the payload. + * BlackBerry and Windows do not open the browser for TNF=3. + * + * To write a URI as the payload use ndef.uriRecord(uri) + * + * @param uri String + * @param payload byte[] or String + * @param id byte[] (optional) + * + * @return NdefRecord + */ + absoluteUriRecord(uri:string, payload:Array, id:Array):NdefRecord; + + /** + * Helper that creates a NdefRecordcontaining an mimeMediaRecord. + * + * @param mimeType String + * @param payload byte[] + * @param id byte[] (optional) + */ + mimeMediaRecord(mimeType:string, payload:Array, id:Array):NdefRecord; + + /** + * Helper that creates an NDEF record containing an Smart Poster. + * + * @param ndefRecords array of NdefRecord + * @param id byte[] (optional) + * + * @return NdefRecord + */ + smartPoster(ndefRecords:Array, id:Array):NdefRecord; + + /** + * Helper that creates an empty NdefRecord. + * + */ + emptyRecord():NdefRecord; + + /** + * Helper that creates an Android Application Record (AAR). + * http://developer.android.com/guide/topics/connectivity/nfc/nfc.html#aar + * @param packageName android package name + * + */ + androidApplicationRecord(packageName:string):NdefRecord; + + /** + * Encodes an NDEF Message into bytes that can be written to a NFC tag. + * + * @param ndefRecords an Array of NdefRecord + * + * @return Array + * + * @see NFC Data Exchange Format (NDEF) http://www.nfc-forum.org/specs/spec_list/ + */ + encodeMessage(ndefRecords:Array):Array; + + /** + * Decodes an array bytes into an NDEF Message + * + * @param bytes Array read from a NFC tag + * + * @return array of NdefRecord + * + * @see NFC Data Exchange Format (NDEF) http://www.nfc-forum.org/specs/spec_list/ + */ + decodeMessage(bytes:Array):Array; + + /** + * Decode the bit flags from a TNF Byte. + * + * @return object with decoded data + * + * See NFC Data Exchange Format (NDEF) Specification Section 3.2 RecordLayout + */ + decodeTnf(tnf_byte:number):any; + + /** + * Encode NDEF bit flags into a TNF Byte. + * + * @return tnf byte + * + * See NFC Data Exchange Format (NDEF) Specification Section 3.2 RecordLayout + */ + encodeTnf(mb:number, me:number, cf:number, sr:number, il:number, tnf:number):number; + + /** + * Convert TNF to String for user friendly display + * + *@param tnf tnf byte + */ + tnfToString(tnf:number):string; + } + + interface Util { + /** + * Convert bytes to string + * @param bytes + */ + bytesToString(bytes:Array):string; + + /** + * Convert string to bytes + * @param string + */ + stringToBytes(string:string):Array; + + /** + * Convert bytes to hexadecimal string + * @param bytes + */ + bytesToHexString(bytes:Array):string; + } + + /** + * The Nfc object. + */ + interface Nfc extends Util { + /** + * Function nfc.addTagDiscoveredListener registers the callback for tag events. + * This event occurs when any tag is detected by the phone + * @param callback The callback that is called when a tag is detected. + * @param win The callback that is called when the listener is added. + * @param fail The callback that is called if there was an error. + */ + addTagDiscoveredListener(callback:(event:TagEvent) => void, win?:() => void, fail?:() => void):void; + + /** + * Function nfc.addMimeTypeListener registers the callback for ndef-mime events. + * A ndef-mime event occurs when a Ndef.TNF_MIME_MEDIA tag is read and matches the specified MIME type. + * This function can be called multiple times to register different MIME types. You should use the same handler for all MIME messages. + * @param mimeType The MIME type to filter for messages. + * @param callback The callback that is called when an NDEF tag matching the MIME type is read. + * @param win The callback that is called when the listener is added. + * @param fail The callback that is called if there was an error. + */ + addMimeTypeListener(mimeType:string, callback:() => void, win?:() => void, fail?:() => void):void; + + /** + * Function nfc.addNdefListener registers the callback for ndef events. + * A ndef event is fired when a NDEF tag is read. + * For BlackBerry 10, you must configure the type of tags your application will read with an invoke-target in config.xml. + * On Android registered mimeTypeListeners takes precedence over this more generic NDEF listener. + * @param callback The callback that is called when an NDEF tag is read. + * @param win The callback that is called when the listener is added. + * @param fail The callback that is called if there was an error. + */ + addNdefListener(callback:(event:NdefTagEvent) => void, win?:() => void, fail?:() => void):void; + + /** + * Function nfc.addNdefFormatableListener registers the callback for ndef-formatable events. + * A ndef-formatable event occurs when a tag is read that can be NDEF formatted. + * This is not fired for tags that are already formatted as NDEF. + * The ndef-formatable event will not contain an NdefMessage. + * @param callback The callback that is called when NDEF formatable tag is read. + * @param win The callback that is called when the listener is added. + * @param fail The callback that is called if there was an error. + */ + addNdefFormatableListener(callback:(event:NdefTagEvent) => void, win?:() => void, fail?:() => void):void; + + /** + * Function nfc.write writes an NdefMessage to a NFC tag. + * On Android this method must be called from within an NDEF TagEvent Handler. + * On Windows this method may be called from within the NDEF TagEvent Handler. + * On Windows Phone 8.1 this method should be called outside the NDEF TagEvent Handler, + * otherwise Windows tries to read the tag contents as you are writing to the tag. + * @param ndefMessage An array of NDEF Records. + * @param win The callback that is called when the tag is written. + * @param fail The callback that is called if there was an error. + */ + write(ndefMessage:Array, win?:() => void, fail?:() => void):void; + + /** + * Function nfc.makeReadOnly make a NFC tag read only. + * Warning this is permanent and can not be undone. + * On Android this method must be called from within an NDEF TagEvent Handler. + * @param win The callback that is called when the tag is locked. + * @param fail The callback that is called if there was an error. + */ + makeReadOnly(win?:() => void, fail?:() => void):void; + + /** + * Function nfc.share writes an NdefMessage via peer-to-peer. + * This should appear as an NFC tag to another device. + * @param ndefMessage An array of NDEF Records. + * @param win The callback that is called when the message is pushed. + * @param fail The callback that is called if there was an error. + */ + share(ndefMessage:Array, win?:() => void, fail?:() => void):void; + + /** + * Function nfc.unshare stops sharing data via peer-to-peer. + * @param win The callback that is called when sharing stops. + * @param fail The callback that is called if there was an error. + */ + unshare(win?:() => void, fail?:() => void):void; + + /** + * Function nfc.handover shares files to a NFC peer using handover. Files are sent by specifying a file:// or context:// URI or a list of URIs. + * The file transfer is initiated with NFC but the transfer is completed with over Bluetooth or WiFi which is handled by a NFC handover request. + * The Android code is responsible for building the handover NFC Message. + * This is Android only, but it should be possible to add implementations for other platforms. + * @param uris A URI as a String, or an array of URIs. + * @param win The callback that is called when the message is pushed. + * @param fail The callback that is called if there was an error. + */ + handover(uris:string|Array, win?:() => void, fail?:() => void):void; + + /** + * Function nfc.stopHandover stops sharing data via peer-to-peer. + * @param win The callback that is called when sharing stops. + * @param fail The callback that is called if there was an error. + */ + stopHandover(win?:() => void, fail?:() => void):void; + + /** + * Function nfc.erase erases a tag by writing an empty message. + * Will format unformatted tags before writing. + * This method must be called from within an NDEF TagEvent Handler. + * @param win The callback that is called when sharing stops. + * @param fail The callback that is called if there was an error. + */ + erase(win?:() => void, fail?:() => void):void; + + /** + * Function nfc.enabled explicitly checks to see if the phone has NFC and if NFC is enabled. + * If everything is OK, the success callback is called. + * If there is a problem, the failure callback will be called with a reason code. + * The reason will be NO_NFC if the device doesn't support NFC and NFC_DISABLED if the user has disabled NFC. + * Note: that on Android the NFC status is checked before every API call NO_NFC or NFC_DISABLED can be returned in any failure function. + * Windows will return NO_NFC_OR_NFC_DISABLED when NFC is not present or disabled. + * If the user disabled NFC after the application started, Windows may return NFC_DISABLED. + * Windows checks the NFC status before most API calls, but there are some cases when the NFC state can not be determined. + * @param win The callback that is called when NFC is enabled. + * @param fail The callback that is called when NFC is disabled or missing. + */ + enabled(win?:() => void, fail?:() => void):void; + + /** + * Removes the previously registered event listener added via nfc.addTagDiscoveredListener + * @param callback The previously registered callback. + * @param win The callback that is called when the listener is successfully removed. + * @param fail The callback that is called if there was an error during removal. + */ + removeTagDiscoveredListener(callback:(event:TagEvent) => void, win?:() => void, fail?:() => void):void; + + /** + * Removes the previously registered event listener added via nfc.addMimeTypeListener + * @param mimeType The MIME type to filter for messages. + * @param callback The previously registered callback. + * @param win The callback that is called when the listener is successfully removed. + * @param fail The callback that is called if there was an error during removal. + */ + removeMimeTypeListener(mimeType:string, callback:(event:TagEvent) => void, win?:() => void, fail?:() => void):void; + + /** + * Removes the previously registered event listener for NDEF tags added via nfc.addNdefListener. + * @param callback The previously registered callback. + * @param win The callback that is called when the listener is successfully removed. + * @param fail The callback that is called if there was an error during removal. + */ + removeNdefListener(callback:(event:TagEvent) => void, win?:() => void, fail?:() => void):void; + + /** + * Function showSettings opens the NFC settings for the operating system. + * @param win Success callback function + * @param fail Error callback function, invoked when error occurs. + */ + showSettings(win?:() => void, fail?:() => void):void; + } } -interface Tag { - id:Array; - techTypes:Array; - type:string; - date:string; -} - -interface NdefRecord { - /** - * 3-bit TNF (Type Name Format) - use one of the TNF_* constants - */ - tnf:number; - /** - * byte array, containing zero to 255 bytes, must not be null - */ - type:Array; - /** - * byte array, containing zero to 255 bytes, must not be null - */ - id:Array; - /** - * byte array, containing zero to (2 ** 32 - 1) bytes, must not be null - */ - payload:Array; -} - -interface NdefTag extends Tag { - canMakeReadOnly:boolean; - isWritable:boolean; - maxSize:number; - records:Array; -} - -interface TagEvent extends Event { - tag:Tag; -} - -interface NdefTagEvent extends TagEvent { - tag:NdefTag; -} - -interface UriHelper { - /** - * URI identifier codes from URI Record Type Definition NFCForum-TS-RTD_URI_1.0 2006-07-24 - * index in array matches code in the spec - */ - protocols:Array; - - /** - * Decode a URI payload bytes - * @param data - */ - decodePayload(data:any):string; - - /** - * shorten a URI with standard prefix - * @param uri - */ - encodePayload(uri:string):Array; -} - -interface TextHelper { - - /** - * Decode a URI payload bytes - * @param data - */ - decodePayload(data:any):string; - - /** - * Encode text payload - * @param text - * @param lang - * @param encoding - */ - encodePayload(text:string, lang:string, encoding:string):Array; -} - -/** - * The Ndef object. - */ -interface Ndef { - - TNF_EMPTY:number; - TNF_WELL_KNOWN: number; - TNF_MIME_MEDIA: number; - TNF_ABSOLUTE_URI: number; - TNF_EXTERNAL_TYPE: number; - TNF_UNKNOWN: number; - TNF_UNCHANGED: number; - TNF_RESERVED: number; - - RTD_TEXT: Array; // "T" - RTD_URI: Array; // "U" - RTD_SMART_POSTER: Array; // "Sp" - RTD_ALTERNATIVE_CARRIER: Array; // "ac" - RTD_HANDOVER_CARRIER: Array; // "Hc" - RTD_HANDOVER_REQUEST: Array; // "Hr" - RTD_HANDOVER_SELECT: Array; // "Hs" - - uriHelper:UriHelper; - textHelper:TextHelper; - /** - * Creates a JSON representation of a NdefRecord. - * - * @param tnf 3-bit TNF (Type Name Format) - use one of the TNF_* constants - * @param type array, containing zero to 255 bytes, must not be null - * @param id byte array, containing zero to 255 bytes, must not be null - * @param payload byte array, containing zero to (2 ** 32 - 1) bytes, must not be null - * - * @return NdefRecord - * - * @see Ndef.textRecord, Ndef.uriRecord and Ndef.mimeMediaRecord for examples - */ - record(tnf:number, type:Array, id:Array, payload:Array):NdefRecord; - - /** - * Helper that creates an NdefRecord containing plain text. - * - * @param text String of text to encode - * @paramlanguageCode ISO/IANA language code. Examples: “fi”, “en-US”, “fr- CA”, “jp”. (optional) - * @param id byte[] (optional) - * - * @return NdefRecord - */ - textRecord(text:string, languageCode:string, id:Array):NdefRecord; - - /** - * Helper that creates a NdefRecord containing a URI. - * - * @param uri String - * @param id byte[] (optional) - * - * @return NdefRecord - */ - uriRecord(uri:string, id:Array):NdefRecord; - - /** - * Helper that creates a NdefRecord containing an absolute URI. - * - * An Absolute URI record means the URI describes the payload of the record. - * - * For example a SOAP message could use "http://schemas.xmlsoap.org/soap/envelope/" - * as the type and XML content for the payload. - * - * Absolute URI can also be used to write LaunchApp records for Windows. - * - * See 2.4.2 Payload Type of the NDEF Specification - * http://www.nfc-forum.org/specs/spec_list#ndefts - * - * Note that by default, Android will open the URI defined in the type - * field of an Absolute URI record (TNF=3) and ignore the payload. - * BlackBerry and Windows do not open the browser for TNF=3. - * - * To write a URI as the payload use ndef.uriRecord(uri) - * - * @param uri String - * @param payload byte[] or String - * @param id byte[] (optional) - * - * @return NdefRecord - */ - absoluteUriRecord(uri:string, payload:Array, id:Array):NdefRecord; - - /** - * Helper that creates a NdefRecordcontaining an mimeMediaRecord. - * - * @param mimeType String - * @param payload byte[] - * @param id byte[] (optional) - */ - mimeMediaRecord(mimeType:string, payload:Array, id:Array):NdefRecord; - - /** - * Helper that creates an NDEF record containing an Smart Poster. - * - * @param ndefRecords array of NdefRecord - * @param id byte[] (optional) - * - * @return NdefRecord - */ - smartPoster(ndefRecords:Array, id:Array):NdefRecord; - - /** - * Helper that creates an empty NdefRecord. - * - */ - emptyRecord():NdefRecord; - - /** - * Helper that creates an Android Application Record (AAR). - * http://developer.android.com/guide/topics/connectivity/nfc/nfc.html#aar - * @param packageName android package name - * - */ - androidApplicationRecord(packageName:string):NdefRecord; - - /** - * Encodes an NDEF Message into bytes that can be written to a NFC tag. - * - * @param ndefRecords an Array of NdefRecord - * - * @return Array - * - * @see NFC Data Exchange Format (NDEF) http://www.nfc-forum.org/specs/spec_list/ - */ - encodeMessage(ndefRecords:Array):Array; - - /** - * Decodes an array bytes into an NDEF Message - * - * @param bytes Array read from a NFC tag - * - * @return array of NdefRecord - * - * @see NFC Data Exchange Format (NDEF) http://www.nfc-forum.org/specs/spec_list/ - */ - decodeMessage(bytes:Array):Array; - - /** - * Decode the bit flags from a TNF Byte. - * - * @return object with decoded data - * - * See NFC Data Exchange Format (NDEF) Specification Section 3.2 RecordLayout - */ - decodeTnf(tnf_byte:number):any; - - /** - * Encode NDEF bit flags into a TNF Byte. - * - * @return tnf byte - * - * See NFC Data Exchange Format (NDEF) Specification Section 3.2 RecordLayout - */ - encodeTnf(mb:number, me:number, cf:number, sr:number, il:number, tnf:number):number; - - /** - * Convert TNF to String for user friendly display - * - *@param tnf tnf byte - */ - tnfToString(tnf:number):string; -} - -interface Util { - /** - * Convert bytes to string - * @param bytes - */ - bytesToString(bytes:Array):string; - - /** - * Convert string to bytes - * @param string - */ - stringToBytes(string:string):Array; - - /** - * Convert bytes to hexadecimal string - * @param bytes - */ - bytesToHexString(bytes:Array):string; -} - -/** - * The Nfc object. - */ -interface Nfc extends Util { - /** - * Function nfc.addTagDiscoveredListener registers the callback for tag events. - * This event occurs when any tag is detected by the phone - * @param callback The callback that is called when a tag is detected. - * @param win The callback that is called when the listener is added. - * @param fail The callback that is called if there was an error. - */ - addTagDiscoveredListener(callback:(event:TagEvent) => void, win?:() => void, fail?:() => void):void; - - /** - * Function nfc.addMimeTypeListener registers the callback for ndef-mime events. - * A ndef-mime event occurs when a Ndef.TNF_MIME_MEDIA tag is read and matches the specified MIME type. - * This function can be called multiple times to register different MIME types. You should use the same handler for all MIME messages. - * @param mimeType The MIME type to filter for messages. - * @param callback The callback that is called when an NDEF tag matching the MIME type is read. - * @param win The callback that is called when the listener is added. - * @param fail The callback that is called if there was an error. - */ - addMimeTypeListener(mimeType:string, callback:() => void, win?:() => void, fail?:() => void):void; - - /** - * Function nfc.addNdefListener registers the callback for ndef events. - * A ndef event is fired when a NDEF tag is read. - * For BlackBerry 10, you must configure the type of tags your application will read with an invoke-target in config.xml. - * On Android registered mimeTypeListeners takes precedence over this more generic NDEF listener. - * @param callback The callback that is called when an NDEF tag is read. - * @param win The callback that is called when the listener is added. - * @param fail The callback that is called if there was an error. - */ - addNdefListener(callback:(event:NdefTagEvent) => void, win?:() => void, fail?:() => void):void; - - /** - * Function nfc.addNdefFormatableListener registers the callback for ndef-formatable events. - * A ndef-formatable event occurs when a tag is read that can be NDEF formatted. - * This is not fired for tags that are already formatted as NDEF. - * The ndef-formatable event will not contain an NdefMessage. - * @param callback The callback that is called when NDEF formatable tag is read. - * @param win The callback that is called when the listener is added. - * @param fail The callback that is called if there was an error. - */ - addNdefFormatableListener(callback:(event:NdefTagEvent) => void, win?:() => void, fail?:() => void):void; - - /** - * Function nfc.write writes an NdefMessage to a NFC tag. - * On Android this method must be called from within an NDEF TagEvent Handler. - * On Windows this method may be called from within the NDEF TagEvent Handler. - * On Windows Phone 8.1 this method should be called outside the NDEF TagEvent Handler, - * otherwise Windows tries to read the tag contents as you are writing to the tag. - * @param ndefMessage An array of NDEF Records. - * @param win The callback that is called when the tag is written. - * @param fail The callback that is called if there was an error. - */ - write(ndefMessage:Array, win?:() => void, fail?:() => void):void; - - /** - * Function nfc.makeReadOnly make a NFC tag read only. - * Warning this is permanent and can not be undone. - * On Android this method must be called from within an NDEF TagEvent Handler. - * @param win The callback that is called when the tag is locked. - * @param fail The callback that is called if there was an error. - */ - makeReadOnly(win?:() => void, fail?:() => void):void; - - /** - * Function nfc.share writes an NdefMessage via peer-to-peer. - * This should appear as an NFC tag to another device. - * @param ndefMessage An array of NDEF Records. - * @param win The callback that is called when the message is pushed. - * @param fail The callback that is called if there was an error. - */ - share(ndefMessage:Array, win?:() => void, fail?:() => void):void; - - /** - * Function nfc.unshare stops sharing data via peer-to-peer. - * @param win The callback that is called when sharing stops. - * @param fail The callback that is called if there was an error. - */ - unshare(win?:() => void, fail?:() => void):void; - - /** - * Function nfc.handover shares files to a NFC peer using handover. Files are sent by specifying a file:// or context:// URI or a list of URIs. - * The file transfer is initiated with NFC but the transfer is completed with over Bluetooth or WiFi which is handled by a NFC handover request. - * The Android code is responsible for building the handover NFC Message. - * This is Android only, but it should be possible to add implementations for other platforms. - * @param uris A URI as a String, or an array of URIs. - * @param win The callback that is called when the message is pushed. - * @param fail The callback that is called if there was an error. - */ - handover(uris:string|Array, win?:() => void, fail?:() => void):void; - - /** - * Function nfc.stopHandover stops sharing data via peer-to-peer. - * @param win The callback that is called when sharing stops. - * @param fail The callback that is called if there was an error. - */ - stopHandover(win?:() => void, fail?:() => void):void; - - /** - * Function nfc.erase erases a tag by writing an empty message. - * Will format unformatted tags before writing. - * This method must be called from within an NDEF TagEvent Handler. - * @param win The callback that is called when sharing stops. - * @param fail The callback that is called if there was an error. - */ - erase(win?:() => void, fail?:() => void):void; - - /** - * Function nfc.enabled explicitly checks to see if the phone has NFC and if NFC is enabled. - * If everything is OK, the success callback is called. - * If there is a problem, the failure callback will be called with a reason code. - * The reason will be NO_NFC if the device doesn't support NFC and NFC_DISABLED if the user has disabled NFC. - * Note: that on Android the NFC status is checked before every API call NO_NFC or NFC_DISABLED can be returned in any failure function. - * Windows will return NO_NFC_OR_NFC_DISABLED when NFC is not present or disabled. - * If the user disabled NFC after the application started, Windows may return NFC_DISABLED. - * Windows checks the NFC status before most API calls, but there are some cases when the NFC state can not be determined. - * @param win The callback that is called when NFC is enabled. - * @param fail The callback that is called when NFC is disabled or missing. - */ - enabled(win?:() => void, fail?:() => void):void; - - /** - * Removes the previously registered event listener added via nfc.addTagDiscoveredListener - * @param callback The previously registered callback. - * @param win The callback that is called when the listener is successfully removed. - * @param fail The callback that is called if there was an error during removal. - */ - removeTagDiscoveredListener(callback:(event:TagEvent) => void, win?:() => void, fail?:() => void):void; - - /** - * Removes the previously registered event listener added via nfc.addMimeTypeListener - * @param mimeType The MIME type to filter for messages. - * @param callback The previously registered callback. - * @param win The callback that is called when the listener is successfully removed. - * @param fail The callback that is called if there was an error during removal. - */ - removeMimeTypeListener(mimeType:string, callback:(event:TagEvent) => void, win?:() => void, fail?:() => void):void; - - /** - * Removes the previously registered event listener for NDEF tags added via nfc.addNdefListener. - * @param callback The previously registered callback. - * @param win The callback that is called when the listener is successfully removed. - * @param fail The callback that is called if there was an error during removal. - */ - removeNdefListener(callback:(event:TagEvent) => void, win?:() => void, fail?:() => void):void; - - /** - * Function showSettings opens the NFC settings for the operating system. - * @param win Success callback function - * @param fail Error callback function, invoked when error occurs. - */ - showSettings(win?:() => void, fail?:() => void):void; +declare module 'nfc' { + var nfc:PhoneGapNfc.Nfc; + export = nfc; } -declare var ndef:Ndef; -declare var nfc:Nfc; -declare var util:Util; - - declare module 'ndef' { + var ndef:PhoneGapNfc.Ndef; export = ndef; } -declare module 'nfc' { - export = nfc; +declare module 'util' { + var util:PhoneGapNfc.Util; + export = util; } - diff --git a/phonegap-nfc/phonegap-nfc.tests.ts b/phonegap-nfc/phonegap-nfc.tests.ts index db9fce2b5523f4..ddaabebce71570 100644 --- a/phonegap-nfc/phonegap-nfc.tests.ts +++ b/phonegap-nfc/phonegap-nfc.tests.ts @@ -1,5 +1,9 @@ /// +import nfc = require('nfc'); +import ndef = require('ndef'); +import NdefRecord = PhoneGapNfc.NdefRecord; + nfc.addTagDiscoveredListener(() => {}); nfc.addTagDiscoveredListener(() => {},() => {}, () => {}); From 254a293f4bcc71ef8b9f2af8ca2e7115065ecb9b Mon Sep 17 00:00:00 2001 From: Michael DESIGAUD Date: Tue, 15 Mar 2016 15:30:27 +0100 Subject: [PATCH 5/5] Rename phonegap nfc test file --- phonegap-nfc/{phonegap-nfc.tests.ts => phonegap-nfc-tests.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename phonegap-nfc/{phonegap-nfc.tests.ts => phonegap-nfc-tests.ts} (100%) diff --git a/phonegap-nfc/phonegap-nfc.tests.ts b/phonegap-nfc/phonegap-nfc-tests.ts similarity index 100% rename from phonegap-nfc/phonegap-nfc.tests.ts rename to phonegap-nfc/phonegap-nfc-tests.ts