-
Notifications
You must be signed in to change notification settings - Fork 161
Add support for Web NFC API #806
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
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
import scala.scalajs.js.annotation.JSGlobal | ||
|
||
/** The [[NDEFMessage]] interface of the Web NFC API represents the content of an NDEF message that has been read from | ||
* or could be written to an NFC tag. An instance is acquired by calling the NDEFMessage() constructor or from the | ||
* NDEFReadingEvent.message property, which is passed to the reading event. | ||
* | ||
* @param records | ||
* The records property of NDEFMessage interface represents a list of NDEFRecords present in the NDEF message. | ||
*/ | ||
@js.native | ||
@JSGlobal | ||
class NDEFMessage(recordsAgr: js.Array[NDEFRecordInit]) extends js.Object { | ||
|
||
/** Returns the list of NDEF records contained in the message. */ | ||
var records: FrozenArray[NDEFRecord] = js.native | ||
} |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
import scala.scalajs.js.annotation.JSGlobal | ||
|
||
/** The [[NDEFReader]] interface of the Web NFC API (https://developer.mozilla.org/en-US/docs/Web/API/Web_NFC_API) is | ||
* used to read from and write data to compatible NFC devices, e.g. NFC tags supporting NDEF, when these devices are | ||
* within the reader's magnetic induction field. | ||
*/ | ||
@JSGlobal("NDEFReader") | ||
@js.native | ||
class NDEFReader() extends EventTarget { | ||
FabioPinheiro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** Activates a reading device and returns a Promise that either resolves when an NFC tag read operation is scheduled | ||
* or rejects if a hardware or permission error is encountered. This method triggers a permission prompt if the "nfc" | ||
* permission has not been previously granted. | ||
* | ||
* @return | ||
* a Promise that resolves immediately after scheduling read operations for the NFC adapter. | ||
*/ | ||
def scan(options: NDEFScanOptions = js.native): js.Promise[Unit] = js.native | ||
|
||
/** Attempts to write an NDEF message to a tag and returns a Promise that either resolves when a message has been | ||
* written to the tag or rejects if a hardware or permission error is encountered. This method triggers a permission | ||
* prompt if the "nfc" permission has not been previously granted. | ||
* | ||
* @param message | ||
* The message to be written, either a string object or literal, an ArrayBuffer, a TypedArray, a DataView, or an | ||
* array of records. A record has the following members: | ||
* @param options | ||
* An object with the following properties: | ||
* | ||
* @return | ||
* a Promise that either resolves when a message has been written to the tag or rejects if a hardware or permission | ||
* error is encountered. | ||
*/ | ||
def write(message: String, options: NDEFWriteOptions): js.Promise[Unit] = js.native | ||
def write(message: js.typedarray.ArrayBuffer, options: NDEFWriteOptions): js.Promise[Unit] = js.native | ||
|
||
def write(message: js.typedarray.TypedArray[_, _], | ||
options: NDEFWriteOptions = js.native): js.Promise[Unit] = js.native | ||
def write(message: js.typedarray.DataView, options: NDEFWriteOptions): js.Promise[Unit] = js.native | ||
def write(message: js.Array[NDEFRecord], options: NDEFWriteOptions): js.Promise[Unit] = js.native | ||
|
||
def write(message: String): js.Promise[Unit] = js.native | ||
def write(message: js.typedarray.ArrayBuffer): js.Promise[Unit] = js.native | ||
// def write(message:js.typedarray.TypedArray[NDEFRecord, ???]): js.Promise[Unit] = js.native | ||
def write(message: js.typedarray.DataView): js.Promise[Unit] = js.native | ||
def write(message: js.Array[NDEFRecord]): js.Promise[Unit] = js.native | ||
|
||
/** The reading event of the NDEFReader interface is fired whenever a new reading is available from compatible NFC | ||
* devices (e.g. NFC tags supporting NDEF) when these devices are within the reader's magnetic induction field. | ||
*/ | ||
var onreading: js.Function1[NDEFReadingEvent, Any] = js.native | ||
|
||
/** The readingerror event of the NDEFReader interface is fired whenever an error occurs during reading of NFC tags, | ||
* e.g. when tags leave the reader's magnetic induction field. | ||
*/ | ||
var onreadingerror: js.Function1[Event, Any] = js.native | ||
} |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
|
||
/** The NDEFReadingEvent interface of the Web NFC API represents events dispatched on new NFC readings obtained by | ||
* NDEFReader. | ||
* | ||
* @see | ||
* https://developer.mozilla.org/en-US/docs/Web/API/NDEFReadingEvent | ||
*/ | ||
@js.native | ||
trait NDEFReadingEvent extends Event { | ||
zetashift marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** Returns an NDEFMessage object containing the received message. */ | ||
var message: NDEFMessage = js.native | ||
FabioPinheiro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** Returns the serial number of the device, which is used for anti-collision and identification, or an empty string | ||
* if no serial number is available. | ||
*/ | ||
var serialNumber: String = js.native | ||
FabioPinheiro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
} |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
import scala.scalajs.js.annotation.JSGlobal | ||
|
||
/** The [[NDEFRecord]] interface of the Web NFC API provides data that can be read from, or written to, compatible NFC | ||
* devices, e.g. NFC tags supporting NDEF. | ||
*/ | ||
@js.native | ||
@JSGlobal | ||
class NDEFRecord(options: NDEFRecordInit) extends js.Object { | ||
|
||
/** Returns the record type of the record. Records must have either a standardized well-known type name such as | ||
* "empty", "text", "url", "smart-poster", "absolute-url", "mime", or "unknown" or else an external type name, which | ||
* consists of a domain name and custom type name separated by a colon (":"). | ||
*/ | ||
var recordType: String = js.native | ||
FabioPinheiro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** Returns the MIME type of the record. This value will be null if recordType is not equal to "mime". */ | ||
var mediaType: js.UndefOr[String] = js.native | ||
zetashift marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** Returns the record identifier, which is an absolute or relative URL used to identify the record. | ||
* | ||
* Note: The uniqueness of the identifier is enforced only by the generator of the record. | ||
*/ | ||
var id: js.UndefOr[String] = js.native | ||
FabioPinheiro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** Returns a DataView containing the raw bytes of the record's payload. */ | ||
var data: js.typedarray.DataView = js.native | ||
FabioPinheiro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** Returns the encoding of a textual payload, or null otherwise. */ | ||
var encoding: js.UndefOr[String] = js.native | ||
FabioPinheiro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** Returns the language of a textual payload, or null if one was not supplied. */ | ||
var lang: js.UndefOr[String] = js.native | ||
FabioPinheiro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** Converts [[NDEFRecord.data]] to a sequence of records. This allows parsing the payloads of record types which may | ||
* contain nested records, such as smart poster and external type records. | ||
*/ | ||
def toRecords(): js.Array[NDEFRecord] = js.native | ||
} |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
import scala.scalajs.js.| | ||
|
||
/** @see | ||
* https://developer.mozilla.org/en-US/docs/Web/API/NDEFMessage/NDEFMessage | ||
* @see | ||
* https://developer.mozilla.org/en-US/docs/Web/API/NDEFRecord/NDEFRecord | ||
*/ | ||
trait NDEFRecordInit extends js.Object { | ||
|
||
/** Contains the data to be transmitted. It can be a string object or literal, an ArrayBuffer, a TypedArray, a | ||
* DataView, or an array of nested records. | ||
*/ | ||
var data: js.UndefOr[ | ||
String | | ||
js.typedarray.DataView | | ||
js.typedarray.ArrayBuffer | | ||
js.typedarray.TypedArray[_, _] | | ||
js.typedarray.DataView | | ||
js.Array[NDEFRecord] | ||
] = js.undefined | ||
|
||
/** A string specifying the record's encoding. */ | ||
var encoding: js.UndefOr[String] = js.undefined | ||
|
||
/** A developer-defined identifier for the record. */ | ||
var id: js.UndefOr[String] = js.undefined | ||
|
||
/** A valid language tag according to [RFC 5646: Tags for Identifying Languages (also known as BCP | ||
* 47)](https://datatracker.ietf.org/doc/html/rfc5646). | ||
*/ | ||
var lang: js.UndefOr[String] = js.undefined | ||
|
||
/** A valid MIME type. */ | ||
var mediaType: js.UndefOr[String] = js.undefined | ||
|
||
/** A string indicating the type of data stored in data. | ||
* | ||
* It must be one of the following values: | ||
* - "absolute-url" - An absolute URL to the data. | ||
* - "empty" - An empty NDEFRecord. | ||
* - "mime" - A valid MIME type. | ||
* - "smart-poster" - A smart poster as defined by the NDEF-SMARTPOSTER specification. | ||
* - "text" - Text as defined by the NDEF-TEXT specification. | ||
* - "unknown" - The record type is not known. | ||
* - "URL" - A URL as defined by the NDEF-URI specification. | ||
*/ | ||
var recordType: js.UndefOr[String] = js.undefined | ||
} |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
|
||
trait NDEFScanOptions extends js.Object { | ||
|
||
/** An AbortSignal that allows the current write operation to be canceled. */ | ||
var `signal`: js.UndefOr[AbortSignal] = js.undefined | ||
} |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
|
||
/** @see https://developer.mozilla.org/en-US/docs/Web/API/NDEFReader/write */ | ||
trait NDEFWriteOptions extends js.Object { | ||
|
||
/** A boolean value specifying whether or not existing records should be overwritten, if such exists. */ | ||
var `overwrite`: js.UndefOr[Boolean] = js.undefined | ||
|
||
/** An AbortSignal that allows the current write operation to be canceled. */ | ||
var `signal`: js.UndefOr[AbortSignal] = js.undefined | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.