Skip to content

Commit 7f4149e

Browse files
committed
v1.4.0 added sanitization to constructors
1 parent 5a6837d commit 7f4149e

6 files changed

Lines changed: 23 additions & 9 deletions

File tree

classes/BluetoothManager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export class BluetoothManager extends WebIOT {
1616
this.bluetooth.onadvertisementreceived = callback
1717
} else {
1818
alert("Doh! bluetooth is not supported");
19+
throw new Error("Doh! bluetooth is not supported")
1920
}
2021
}).catch((e) => {console.log(e)});
2122

classes/NFCManager.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@ export class NFCManager extends WebIOT {
44
constructor (debug = false) {
55
super(debug)
66
if ('NDEFReader' in window) { /* Scan and write NFC tags */
7-
this.nfc = new NDEFReader()
7+
this.startNFC()
88
} else {
99
alert('NFC is not supported in your browser')
1010
}
11-
1211
}
1312

1413
startNFC () {
15-
1614
this.nfc = new NDEFReader()
1715
}
16+
1817
async readNFCData (readCb = (event) => {console.log(event)}, errorCb = (event) => console.log(event)) {
19-
this.nfc.onreading = readCb
18+
try {
2019
await this.nfc.scan()
20+
this.nfc.onreading = readCb
21+
} catch(e) {
22+
errorCb(e)
23+
}
2124
}
2225
async writeNFCData (records, errorCb = (event) => console.log(event)) {
2326
try {

classes/SerialManager.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ export class SerialManager extends WebIOT {
33
#ports = {}
44
#selectedPort = {}
55
constructor (debug = false) {
6+
if ('serial' in navigator) { /* Scan and write NFC tags */
67
super(debug)
8+
} else {
9+
alert('NFC is not supported in your browser')
10+
}
711
}
812

913
async getPorts () {

classes/USBManager.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ export class USBManager extends WebIOT{
33
#devices = {}
44
#selectedDevice = {}
55
constructor (debug = false) {
6+
if('usb' in navigator) {
7+
8+
} else {
9+
alert('USB not available on this device')
10+
}
611
super(debug)
712
}
813

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@mastashake08/web-iot",
3-
"version": "1.3.3",
4-
"description": "Connect to your IoT devices via usb, serial, NFC or Serial",
3+
"version": "1.4.0",
4+
"description": "Connect to your IoT devices via usb, serial, NFC or Serial. Allows for callback integration and streaming *coming soon*",
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1"
@@ -15,7 +15,8 @@
1515
"webserial",
1616
"Serial",
1717
"webusb",
18-
"nfc"
18+
"nfc",
19+
"filesystem"
1920
],
2021
"author": "Mastashake",
2122
"license": "MIT",

0 commit comments

Comments
 (0)