WebAPI/WebNFC: Difference between revisions
< WebAPI
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 11: | Line 11: | ||
** Discovered NDEF tags are automatically parsed and dispatched to content in the "tagdiscovered" event on navigator.mozNfc.ndef. | ** Discovered NDEF tags are automatically parsed and dispatched to content in the "tagdiscovered" event on navigator.mozNfc.ndef. | ||
** navigator.mozNfc only available to a specific privileged content page (cf. WebTelephony, WebSMS). | ** navigator.mozNfc only available to a specific privileged content page (cf. WebTelephony, WebSMS). | ||
** For now, content is expected to do filtering and dispatching to handlers e.g. via WebIntents | ** For now, content is expected to do filtering and dispatching to handlers e.g. via WebIntents/WebActions. | ||
== Proposed API == | == Proposed API == | ||
| Line 63: | Line 50: | ||
readonly attribute DOMString payloadText; | readonly attribute DOMString payloadText; | ||
readonly attribute ArrayBuffer payloadArrayBuffer; | readonly attribute ArrayBuffer payloadArrayBuffer; | ||
}; | |||
== 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 | |||
// Could dispatch event.message here to other web apps based on MIME type, URI, etc. | |||
}); | |||
}; | }; | ||
Revision as of 00:25, 4 February 2012
Preliminary scope
- Technologies:
- Focus on NDEF standard only for now.
- Others (e.g. proprietary MIFARE) to be investigated later.
- Capabilities:
- read-only for now.
- Tag creation/simulation and two-way communication to be investigated later.
- Implementation:
- NDEF-only API available on navigator.mozNfc.ndef object.
- Discovered NDEF tags are automatically parsed and dispatched to content in the "tagdiscovered" event on navigator.mozNfc.ndef.
- navigator.mozNfc only available to a specific privileged content page (cf. WebTelephony, WebSMS).
- For now, content is expected to do filtering and dispatching to handlers e.g. via WebIntents/WebActions.
Proposed API
navigator.mozNfc returns an object that, for now, only exposed NDEF capabilities:
interface Nfc
{
readonly attribute Ndef ndef;
};
The NDEF capabilities are, for now, restricted to tag discovery. The "tagdiscovered" NfcNdefEvent will be fired when a new NDEF tag is discovered. The event will contain a reference to the NdefMessage object.
interface NfcNdef : EventTarget
{
attribute EventListener ontagdiscovered;
};
interface NfcNdefEvent : nsIDOMEvent
{
readonly attribute NdefMessage message;
};
An NDEF message is merely a container for NDEF records:
interface NdefMessage
{
readonly attribute NDefRecords[] ndefRecords;
};
NDEF records contain a bunch of metadata and a payload that is exposed as both a string and a Typed Array buffer (akin to the response on XMLHttpRequest).
interface NdefRecord
{
readonly attribute DOMString tnf;
readonly attribute DOMString type;
readonly attribute DOMString id;
readonly attribute DOMString payloadText;
readonly attribute ArrayBuffer payloadArrayBuffer;
};
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
// Could dispatch event.message here to other web apps based on MIME type, URI, etc.
});
};
Implementation
- See bug 674741
- Engineers: Markus Neubrand, Arno Puder, Philipp von Weitershausen