|
| 1 | +package org.scalajs.dom |
| 2 | + |
| 3 | +import scala.scalajs.js |
| 4 | +import scala.scalajs.js.annotation.JSGlobal |
| 5 | + |
| 6 | +/** The [[NDEFReader]] interface of the Web NFC API (https://developer.mozilla.org/en-US/docs/Web/API/Web_NFC_API) is |
| 7 | + * used to read from and write data to compatible NFC devices, e.g. NFC tags supporting NDEF, when these devices are |
| 8 | + * within the reader's magnetic induction field. |
| 9 | + */ |
| 10 | +@JSGlobal("NDEFReader") |
| 11 | +@js.native |
| 12 | +class NDEFReader() extends EventTarget { |
| 13 | + |
| 14 | + /** Activates a reading device and returns a [[Promise]] that either resolves when an NFC tag read operation is |
| 15 | + * scheduled or rejects if a hardware or permission error is encountered. This method triggers a permission prompt if |
| 16 | + * the "nfc" permission has not been previously granted. |
| 17 | + * |
| 18 | + * @return |
| 19 | + * a Promise that resolves immediately after scheduling read operations for the NFC adapter. |
| 20 | + */ |
| 21 | + def scan(options: NDEFScanOptions = js.native): js.Promise[Any] = js.native |
| 22 | + |
| 23 | + /** Attempts to write an NDEF message to a tag and returns a [[Promise]] that either resolves when a message has been |
| 24 | + * written to the tag or rejects if a hardware or permission error is encountered. This method triggers a permission |
| 25 | + * prompt if the "nfc" permission has not been previously granted. |
| 26 | + * |
| 27 | + * @param message |
| 28 | + * The message to be written, either a string object or literal, an ArrayBuffer, a TypedArray, a DataView, or an |
| 29 | + * array of records. A record has the following members: |
| 30 | + * @param options |
| 31 | + * An object with the following properties: |
| 32 | + * |
| 33 | + * @return |
| 34 | + * a Promise that either resolves when a message has been written to the tag or rejects if a hardware or permission |
| 35 | + * error is encountered. |
| 36 | + */ |
| 37 | + def write(message: NDEFRecord.Data, options: NDEFWriteOptions = js.native): js.Promise[String] = js.native |
| 38 | + |
| 39 | + /** The reading event of the NDEFReader interface is fired whenever a new reading is available from compatible NFC |
| 40 | + * devices (e.g. NFC tags supporting NDEF) when these devices are within the reader's magnetic induction field. |
| 41 | + */ |
| 42 | + var onreading: js.Function1[NDEFReadingEvent, Any] = js.native |
| 43 | + |
| 44 | + /** The readingerror event of the NDEFReader interface is fired whenever an error occurs during reading of NFC tags, |
| 45 | + * e.g. when tags leave the reader's magnetic induction field. |
| 46 | + */ |
| 47 | + var onreadingerror: js.Function1[Event, Any] = js.native |
| 48 | +} |
| 49 | + |
| 50 | +@js.native |
| 51 | +trait NDEFScanOptions extends js.Object { |
| 52 | + |
| 53 | + /** An AbortSignal that allows the current write operation to be canceled. */ |
| 54 | + def `signal`: js.UndefOr[AbortSignal] = js.native |
| 55 | +} |
| 56 | + |
| 57 | +@js.native |
| 58 | +trait NDEFWriteOptions extends js.Object { |
| 59 | + |
| 60 | + /** A boolean value specifying whether or not existing records should be overwritten, if such exists. */ |
| 61 | + def `overwrite`: Boolean = js.native |
| 62 | + |
| 63 | + /** An AbortSignal that allows the current write operation to be canceled. */ |
| 64 | + def `signal`: js.UndefOr[AbortSignal] = js.native |
| 65 | +} |
0 commit comments