-
Notifications
You must be signed in to change notification settings - Fork 67
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
Provide option for suspending NFC watchers when "push a message" algorithm is not completed #77
Comments
So do you expect the spec to list normative policy for handling concurrent watch/push scenario? |
@zolkis However, issue is about slightly different problem. Something like adapter.pushMessage(... { target: "tag", ignoreRead: true }) With current API you have to do somethig like: var watchers = new Array();
function addWatchers() {
navigator.nfc.requestAdapter().then((adapter) => { adapter.watch({}, (message)=>{addItemToCart(message);} ).then((id) => {watchers.push(id)} ) } );
}
function removeWatchers() {
navigator.nfc.requestAdapter().then((adapter) => { watchers.forEach((id) => {adapter.unwatch(id)}) } );
}
function writeTag() {
navigator.nfc.requestAdapter().then((adapter) => { removeWatchers(); adapter.pushMessage(....).then(() => {addWatchers();})} );
}
addWatchers();
=== user clicks write tag button === Another option is to have global flag: var pushPending = false;
navigator.nfc.requestAdapter().then((adapter) => { adapter.watch({}, (message)=>{ if(pushPending) return; addItemToCart(message);} )} );
navigator.nfc.requestAdapter().then((adapter) => { pushPending = true; adapter.pushMessage(....).then(pushPending = false;)} ); |
I like the flag idea, but not on push. IMO the watches should control this (their own) behavior. |
We could also include a flag on push, like |
I like the ignoreRead on push (that was my suggestion to Alex yesterday). In an element world (like in Polymer) it is common to have separate elements dealing with read and write, so the current behavior makes it hard to do so, as you kind of need a global watch. That is of course solved if you can ignore the read. Alex pointed out that the read can be useful if you want to cancel a write given the read values. I think that at least deserves an example in the spec, and maybe some discussion about the usefulness of that and the ease of use - if it is useful, could we make it easier? |
…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.
Fixed by #88. |
Precondition:
There are active NFC watches (https://w3c.github.io/web-nfc/#the-watch-method) and "push a message" algorithm is not completed. UA is waiting for NFC device to be within proximity.
When NFC device (Tag) is within proximity, NFC watcher callback would be called and "push a message" algorithm would be completed, thus data will be written to a tag.
Problem:
If webpage has a list that is updated when device touches NFC tag and same page is trying to write data to a tag, it would be beneficial to suspend read operations during write.
Possible solution:
Provide option for pushMessage() that will suspend active NFC watches until "push a message" algorithm is completed.
Also, NFC watchers should not be called if same device is within proximity after "push a message" algorithm is completed.
The text was updated successfully, but these errors were encountered: