WebAPI/WebNFC
< WebAPI
Preliminary scope
- explicitly NDEF-only for now (navigator.mozNfc.ndef), other technologies to be investigated
- read-only, no tag creation
- dispatch all discovered NDEF tags to the "tagdiscovered" event, privileged web app does filtering and dispatches e.g. via WebIntents.
Example
navigator.mozNfc.ndef.ontagdiscovered = function (event) { console.log("Discovered an NDEF message with " + event.message.records.length + " records."); event.message.records.forEach(function (record) { console.log("Found a " + record.tnf + " record" + " of type " + record.type + " with ID " + record.id + " and payload " + record.payloadText); // record.payloadArrayBuffer is an typed array representation of the payload }); };
Proposed API
#include "nsISupports.idl" interface nsIDOMNfc; [scriptable, uuid(c5814d20-4dcf-11e1-b86c-0800200c9a66)] interface nsIDOMNavigatorNfc : nsISupports { readonly attribute nsIDOMNfc mozNfc; };
nsIDOMNfc.idl
#include "nsISupports.idl" interface nsIDOMNdef; [scriptable, uuid(c2c01a50-4779-11e1-b86c-0800200c9a66)] interface nsIDOMNfc : nsISupports { readonly attribute nsIDOMNdef ndef; };
nsIDOMNdef.idl
#include "nsIDOMEventTarget.idl" interface nsIDOMEventListener; [scriptable, uuid(c2c01a50-4779-11e1-b86c-0800200c9a66)] interface nsIDOMNdef : nsIDOMEventTarget { attribute nsIDOMEventListener ontagdiscovered; };
nsIDOMNfcNdefEvent.idl
#include "nsIDOMEvent.idl" interface nsIDOMNdefMessage; [scriptable, uuid(41fcd640-4dd4-11e1-b86c-0800200c9a66)] interface nsIDOMNfcNdefEvent : nsIDOMEvent { readonly attribute nsIDOMNdefMessage message; };
nsIDOMNdefMessage.idl
#include "nsISupports.idl" interface nsIDOMNdefRecord; [scriptable, uuid(b4388250-477a-11e1-b86c-0800200c9a66)] interface nsIDOMNdefMessage : nsISupports { /** * Array of all nsINdefRecord elements of the message */ readonly attribute jsval ndefRecords; };
nsIDOMNdefRecord.idl
#include "nsISupports.idl" [scriptable, uuid(c77c7470-477a-11e1-b86c-0800200c9a66)] interface nsIDOMNdefRecord : nsISupports { // See http://developer.android.com/reference/android/nfc/NdefRecord.html for the following attributes readonly attribute DOMString tnf; readonly attribute DOMString type; readonly attribute DOMString id; readonly attribute DOMString payloadText; readonly attribute jsval payloadArrayBuffer; };
Implementation
- See bug 674741
- Engineers: Markus Neubrand, Arno Puder, Philipp von Weitershausen