Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More flexible parameter to push() #84

Closed
zolkis opened this issue Nov 2, 2015 · 3 comments
Closed

More flexible parameter to push() #84

zolkis opened this issue Nov 2, 2015 · 3 comments

Comments

@zolkis
Copy link
Contributor

zolkis commented Nov 2, 2015

Following up on a comment in the F2F review of Web NFC API, the push() method could use a simpler way to pass NFC content as argument.

The current way is to provide a sequence of NFCRecord objects.

nfc.push([{ kind: "text", data: "data" }], options);

We do need to keep the sequence, and the NFCRecords, for controlling the mapping to NDEF.
To make the spec more coherent with the reads, we could modify it to provide an NFCMessage object, i.e. the sequence above + a URL path, and then deal with the same NFCMessage definition for push and reads.

nfc.push([{ data: { kind: "text", data: "data" }, url: "/mypath"} ], options);

But now this looks ugly. Still, some may say why to specify a dictionary with kind, type and data properties. Even though when kind and type are not specified, the content is deduced from data type, if possible, and if not, it is treated as "application/octet-stream".

We could use defaults, and it would be fine to say:

nfc.push([{ data: { data: "data" }} ]), options);

But isn't that unintuitive, and still ugly?

So another possibility would be to define a union for push() parameter, which would simplify the most usual writes. Also, make sensible defaults to options so that it is possible to write:

nfc.push("mytext");

or

nfc.push('{ prop1: 1, prop2: "hello" }');

The question is, what should be the sensible defaults.
IMO, we could say

typedef (DOMString or ArrayBuffer or NFCMessage) NFCPushMessage;
Promise<void> push(NFCPushMessage message, optional NFCPushOptions options);

Then we will have means to pass a simple data (e.g. serialized JSON as DOMString), and when needed, still have greater control on how the NDEF should look like. When DOMString or ArrayBuffer are passed, the resulting NDEF message will have 2 records (one for payload and one special record). If you need to pass more records, or specify more exact format, then use NFCMessage.

Thoughts?

@alexshalamov
Copy link

+1 for simplification.
I've updated my idl to

typedef (NFCMessage or DOMString or ArrayBuffer) NFCPushMessage;
Promise<void> push (NFCPushMessage message, optional NFCPushOptions options);

@kenchris
Copy link
Contributor

kenchris commented Nov 3, 2015

Could you add some examples on how to write text, json, binary etc... then we should add such ones to the spec

zolkis added a commit to zolkis/web-nfc that referenced this issue Nov 4, 2015
…3c#84. Handle push related TAG review comments: simplified and aligned push message, optional push options with sensible defaults, improved push and cancelPush steps, option for suspending watches during push(), editorials.
@zolkis
Copy link
Contributor Author

zolkis commented Nov 6, 2015

Fixed by #88.

@zolkis zolkis closed this as completed Nov 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants