Created
April 8, 2019 10:51
-
-
Save richardszalay/dd39a3486b6477a126103c6ea354247b to your computer and use it in GitHub Desktop.
Types for WebNFC as implemented by Chrome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Types for the version of Web NFC available in Chrome for Android | |
* | |
* The spec is similar to, but does not exactly match https://w3c.github.io/web-nfc/releases/20151112/ | |
*/ | |
declare global { | |
interface Navigator { | |
nfc: WebNFC | |
} | |
interface WebNFC { | |
watch(messageScanned: MessageCallback, options?: NFCWatchOptions): Promise<number> | |
cancelWatch(id?: number): Promise<void>; | |
push(message: NFCPushMessage): Promise<void>; | |
cancelPush(target?: NFCPushTarget): Promise<void>; | |
} | |
interface NFCMessage { | |
records: NFCRecord[], | |
url: string | |
} | |
interface NFCRecord { | |
data: NFCRecordData, | |
mediaType: string, | |
recordType: NFCRecordType | |
} | |
type NFCRecordData = string | number | ArrayBuffer | object; | |
interface MessageCallback { | |
(message: NFCMessage): void | |
} | |
interface NFCWatchOptions { | |
url?: string, | |
kind?: NFCRecordType, | |
mediaType?: string, | |
mode?: NFCWatchMode | |
} | |
type NFCWatchMode = | |
"web-nfc-only" | | |
"any"; | |
type NFCRecordType = | |
"empty" | | |
"text" | | |
"url" | | |
"json" | | |
"opaque"; | |
type NFCPushMessage = | |
string | | |
ArrayBuffer | | |
NFCMessage; | |
interface NFCPushOptions { | |
target?: NFCPushTarget, | |
timeout?: number, | |
ignoreRead?: boolean, | |
} | |
type NFCPushTarget = | |
"tag" | | |
"peer" | | |
"any"; | |
} | |
export {} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@MustafaUzumcu That detection code looks fine. Are you accessing the site via HTTPS? That's a restriction, if I recall correctly.
Btw if you get passed the detection, it should be
message.records
notmessage.data