Skip to content

Commit

Permalink
Add smart poster and external type records examples
Browse files Browse the repository at this point in the history
Signed-off-by: Zoltan Kis <zoltan.kis@intel.com>
  • Loading branch information
zolkis committed Sep 30, 2019
1 parent f59b655 commit b6156e3
Showing 1 changed file with 88 additions and 1 deletion.
89 changes: 88 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ <h4>
</p>
<p>
For external type records, local types are application specific.
Local types are exposed as a recordType, prefixed with "`-`".
Local types are exposed as a recordType, in this example prefixed with "`-`".
</p>
<p>
This example shows how to read an external record for social posts,
Expand Down Expand Up @@ -919,6 +919,93 @@ <h4>
reader.scan({ recordType: "example.com:sp"});
</pre>
</aside>
<aside title="Push a smart poster message" class="example">
<p>
Smart poster defined in NFC Forum Smart Poster Record Type Definition
specification. It is an NDEF record that contains an <a>NDEF message</a>
as payload, which in turn may contain several records: a URI record that
refers to a content, and additional optional records for that content's
title, icon, size, type and possible action (e.g. send SMS, make call,
launch browser, or save for later, or open for editing, etc).
</p>
<pre class="highlight">
const writer = new NFCWriter();
let sp = new NDEFMessage({
records: [
{
recordType: "url",
data: "https://my.org/content/19911"
},
{
recordType: "t", // type, a local type to Sp
data: "image/gif"
},
{
recordType: "text",
data: "Funny dance"
},
{
recordType: "s", // size, a local type to Sp
data: 4096 // byte size of the content at the URL above
},
{
recordType: "act", // action, a local type to Sp
data: 0 // do the action, in this case open in the browser
},
];
});
writer.push({ records: [
{
recordType: "smart-poster",
data: sp.records
}
]}).catch(_ => {
console.log("Push failed");
});
</pre>
</aside>
<aside title="Push an external record with an NDEF message as payload"
class="example">
<p>
External type records can be used to create application defined records
that may even contain an <a>NDEF message</a> as payload.
</p>
<p>
This example show how to do the previous Smart Poster use case with
external records. In this case, content sourcing and the action
mechanism are internal to the application.
</p>
<pre class="highlight">
const writer = new NFCWriter();
let ext = new NDEFMessage({
records: [
{
recordType: "url",
data: "https://my.org/game/19911"
},
{
recordType: "text",
data: "Game context given here"
},
{
recordType: "opaque",
mediaType: "image/png"
data: getImageBytes(fromURL);
}
];
});
writer.push({ records: [
{
recordType: "external",
data: ext.records // embedded message
}
]}).catch(_ => {
console.log("Push failed");
});
</pre>
</aside>


</section> <!-- Usage examples -->

<section class="informative"> <h3>Use Cases</h3>
Expand Down

0 comments on commit b6156e3

Please sign in to comment.