@alexgyver/ble 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +2 -0
- package/LICENSE +21 -0
- package/README.md +40 -0
- package/ble.js +171 -0
- package/ble.min.js +1 -0
- package/package.json +27 -0
- package/test/index.html +18 -0
- package/test/script.js +31 -0
- package/test_arduino/test_arduino.ino +29 -0
- package/test_dev/index.html +18 -0
- package/test_dev/script.js +31 -0
- package/webpack.config.js +14 -0
- package/webpack.dev.config.js +39 -0
package/.gitattributes
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 AlexGyver
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# BLE.js
|
|
2
|
+
Обёртка на Web Bluetooth API
|
|
3
|
+
- Автоматическое переподключение
|
|
4
|
+
- Буферизация отправки
|
|
5
|
+
- Буферизация приёма, разделение текста по разделителю
|
|
6
|
+
|
|
7
|
+
> npm i @alexgyver/ble
|
|
8
|
+
|
|
9
|
+
## Дока
|
|
10
|
+
```js
|
|
11
|
+
constructor(params = {});
|
|
12
|
+
config(params = {});
|
|
13
|
+
// eol: /\r?\n/
|
|
14
|
+
// serviceUUID: '0000ffe0-0000-1000-8000-00805f9b34fb'
|
|
15
|
+
// charxUUID: '0000ffe1-0000-1000-8000-00805f9b34fb'
|
|
16
|
+
// auto_open: false
|
|
17
|
+
// max_tx: 20
|
|
18
|
+
// reconnect: 1000
|
|
19
|
+
|
|
20
|
+
onbin(b);
|
|
21
|
+
ontext(t);
|
|
22
|
+
|
|
23
|
+
onopen():
|
|
24
|
+
onclose():
|
|
25
|
+
onchange(s):
|
|
26
|
+
onselect(name);
|
|
27
|
+
onerror(e);
|
|
28
|
+
|
|
29
|
+
static supported();
|
|
30
|
+
opened();
|
|
31
|
+
selected();
|
|
32
|
+
getName();
|
|
33
|
+
|
|
34
|
+
select();
|
|
35
|
+
open();
|
|
36
|
+
close();
|
|
37
|
+
|
|
38
|
+
sendBin(data);
|
|
39
|
+
sendText(text);
|
|
40
|
+
```
|
package/ble.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { sleep, ShiftBuffer, StreamSplitter } from "@alexgyver/utils";
|
|
2
|
+
|
|
3
|
+
export default class BLEJS {
|
|
4
|
+
static State = {
|
|
5
|
+
Closed: 'closed',
|
|
6
|
+
Opening: 'opening',
|
|
7
|
+
Open: 'open',
|
|
8
|
+
Closing: 'closing',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
//#region handlers
|
|
12
|
+
onbin = null;
|
|
13
|
+
ontext = null;
|
|
14
|
+
|
|
15
|
+
onopen() { }
|
|
16
|
+
onclose() { }
|
|
17
|
+
onchange(s) { }
|
|
18
|
+
onselect(name) { }
|
|
19
|
+
onerror(e) { }
|
|
20
|
+
|
|
21
|
+
//#region constructor
|
|
22
|
+
constructor(params = {}) {
|
|
23
|
+
const def = {
|
|
24
|
+
eol: /\r?\n/,
|
|
25
|
+
serviceUUID: '0000ffe0-0000-1000-8000-00805f9b34fb',
|
|
26
|
+
charxUUID: '0000ffe1-0000-1000-8000-00805f9b34fb',
|
|
27
|
+
auto_open: false,
|
|
28
|
+
max_tx: 20,
|
|
29
|
+
reconnect: 1000,
|
|
30
|
+
};
|
|
31
|
+
this.cfg = { ...def, ...params };
|
|
32
|
+
|
|
33
|
+
this.splitter = new StreamSplitter(this.cfg.eol);
|
|
34
|
+
this.splitter.ontext = (t) => this.ontext(t);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#region methods
|
|
38
|
+
config(params = {}) {
|
|
39
|
+
this.cfg = { ...this.cfg, ...params };
|
|
40
|
+
this.splitter.eol = this.cfg.eol;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static supported() {
|
|
44
|
+
return 'bluetooth' in navigator;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
opened() {
|
|
48
|
+
return this._state === BLEJS.State.Open;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
selected() {
|
|
52
|
+
return !!this._device;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
getName() {
|
|
56
|
+
return this._device ? this._device.name : null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async select() {
|
|
60
|
+
try {
|
|
61
|
+
await this.close();
|
|
62
|
+
if (this._device) this._device.removeEventListener('gattserverdisconnected', this._disconnect_h);
|
|
63
|
+
this._device = await navigator.bluetooth.requestDevice({
|
|
64
|
+
filters: [{ services: [this.cfg.serviceUUID] }],
|
|
65
|
+
optionalServices: [this.cfg.serviceUUID]
|
|
66
|
+
});
|
|
67
|
+
this._device.addEventListener("gattserverdisconnected", this._disconnect_h);
|
|
68
|
+
} catch (e) {
|
|
69
|
+
this._error(e);
|
|
70
|
+
this._device = null;
|
|
71
|
+
}
|
|
72
|
+
this.onselect(this.getName());
|
|
73
|
+
if (this.cfg.auto_open) this.open();
|
|
74
|
+
return this.selected();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async open() {
|
|
78
|
+
if (!this._device) return;
|
|
79
|
+
if (this.opened()) return;
|
|
80
|
+
|
|
81
|
+
if (this.cfg.reconnect) this.retry = true;
|
|
82
|
+
await this._open();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async _open() {
|
|
86
|
+
if (this._state != BLEJS.State.Closed) return;
|
|
87
|
+
|
|
88
|
+
this._change(BLEJS.State.Opening);
|
|
89
|
+
try {
|
|
90
|
+
const server = await this._device.gatt.connect();
|
|
91
|
+
const service = await server.getPrimaryService(this.cfg.serviceUUID);
|
|
92
|
+
this._charx = await service.getCharacteristic(this.cfg.charxUUID);
|
|
93
|
+
await this._charx.startNotifications();
|
|
94
|
+
this._charx.addEventListener("characteristicvaluechanged", this._data_h);
|
|
95
|
+
this._buffer.clear();
|
|
96
|
+
this._change(BLEJS.State.Open);
|
|
97
|
+
} catch (e) {
|
|
98
|
+
this._error(e);
|
|
99
|
+
this._change(BLEJS.State.Closed);
|
|
100
|
+
if (this.retry) sleep(this.cfg.reconnect).then(() => this._open());
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async close() {
|
|
105
|
+
this.retry = false;
|
|
106
|
+
if (this.opened()) await this._close();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async _close() {
|
|
110
|
+
this._change(BLEJS.State.Closing);
|
|
111
|
+
try { this._device.gatt.disconnect(); }
|
|
112
|
+
catch (e) { this._error(e); }
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async sendText(text) {
|
|
116
|
+
await this.sendBin((new TextEncoder()).encode(text));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async sendBin(data) {
|
|
120
|
+
this._buffer.push(data);
|
|
121
|
+
this._send();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
//#region private
|
|
125
|
+
_device = null;
|
|
126
|
+
_charx = null;
|
|
127
|
+
_state = BLEJS.State.Closed;
|
|
128
|
+
_buffer = new ShiftBuffer();
|
|
129
|
+
_decoder = new TextDecoder();
|
|
130
|
+
|
|
131
|
+
async _disconnect(e) {
|
|
132
|
+
this._change(BLEJS.State.Closed);
|
|
133
|
+
if (this._charx) this._charx.removeEventListener('characteristicvaluechanged', this._data_h);
|
|
134
|
+
this._charx = null;
|
|
135
|
+
if (this.retry) sleep(this.cfg.reconnect).then(() => this._open());
|
|
136
|
+
await sleep(50);
|
|
137
|
+
}
|
|
138
|
+
_disconnect_h = this._disconnect.bind(this);
|
|
139
|
+
|
|
140
|
+
_data(e) {
|
|
141
|
+
const dv = e.target.value;
|
|
142
|
+
const value = new Uint8Array(dv.buffer, dv.byteOffset, dv.byteLength);
|
|
143
|
+
if (this.onbin) this.onbin(value);
|
|
144
|
+
if (this.ontext) this.splitter.write(this._decoder.decode(value, { stream: true }));
|
|
145
|
+
}
|
|
146
|
+
_data_h = this._data.bind(this);
|
|
147
|
+
|
|
148
|
+
async _send() {
|
|
149
|
+
if (this._busy) return;
|
|
150
|
+
this._busy = true;
|
|
151
|
+
while (this._buffer.length && this._charx) {
|
|
152
|
+
let d = this._buffer.shift(this.cfg.max_tx);
|
|
153
|
+
try {
|
|
154
|
+
if (d.length) await this._charx.writeValueWithoutResponse(d);
|
|
155
|
+
} catch (e) { }
|
|
156
|
+
}
|
|
157
|
+
this._busy = false;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
_error(e) {
|
|
161
|
+
this.onerror('[BLE] ' + e);
|
|
162
|
+
}
|
|
163
|
+
_change(s) {
|
|
164
|
+
this._state = s;
|
|
165
|
+
this.onchange(s);
|
|
166
|
+
switch (s) {
|
|
167
|
+
case BLEJS.State.Open: this.onopen(); break;
|
|
168
|
+
case BLEJS.State.Closed: this.onclose(); break;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
package/ble.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const t=t=>new Promise(e=>setTimeout(e,t));class e{ontext=null;constructor(t=/\r?\n/,e=!1){this.eol=t,this.skip=e}reset(){this._buf=""}write(t){if(!this.ontext)return;if(!this.eol)return void this.ontext(t);this._buf+=t;let e=this._buf.split(this.eol);1!=e.length&&(e[e.length-1].length?this._buf=e.pop():(this._buf="",e.pop()),this.skip&&(e.shift(),this.skip=!1),e.forEach(t=>this.ontext(t)))}_buf=""}class s{constructor(){this.chunks=[],this.length=0}clear(){this.chunks=[],this.length=0}push(t){return!(!t||0===t.length||(this.chunks.push(t),this.length+=t.length,0))}shift(t){if(!this.length||!t)return new Uint8Array(0);t>this.length&&(t=this.length);const e=new Uint8Array(t);let s=0;for(;s<t&&this.chunks.length>0;){const i=this.chunks[0];if(!i||0===i.length){this.chunks.shift();continue}const h=Math.min(i.length,t-s);e.set(i.subarray(0,h),s),s+=h,h===i.length?this.chunks.shift():this.chunks[0]=i.subarray(h),this.length-=h}return e}shiftAll(){return this.shift(this.length)}}class i{static State={Closed:"closed",Opening:"opening",Open:"open",Closing:"closing"};onbin=null;ontext=null;onopen(){}onclose(){}onchange(t){}onselect(t){}onerror(t){}constructor(t={}){this.cfg={eol:/\r?\n/,serviceUUID:"0000ffe0-0000-1000-8000-00805f9b34fb",charxUUID:"0000ffe1-0000-1000-8000-00805f9b34fb",auto_open:!1,max_tx:20,reconnect:1e3,...t},this.splitter=new e(this.cfg.eol),this.splitter.ontext=t=>this.ontext(t)}config(t={}){this.cfg={...this.cfg,...t},this.splitter.eol=this.cfg.eol}static supported(){return"bluetooth"in navigator}opened(){return this._state===i.State.Open}selected(){return!!this._device}getName(){return this._device?this._device.name:null}async select(){try{await this.close(),this._device&&this._device.removeEventListener("gattserverdisconnected",this._disconnect_h),this._device=await navigator.bluetooth.requestDevice({filters:[{services:[this.cfg.serviceUUID]}],optionalServices:[this.cfg.serviceUUID]}),this._device.addEventListener("gattserverdisconnected",this._disconnect_h)}catch(t){this._error(t),this._device=null}return this.onselect(this.getName()),this.cfg.auto_open&&this.open(),this.selected()}async open(){this._device&&(this.opened()||(this.cfg.reconnect&&(this.retry=!0),await this._open()))}async _open(){if(this._state==i.State.Closed){this._change(i.State.Opening);try{const t=await this._device.gatt.connect(),e=await t.getPrimaryService(this.cfg.serviceUUID);this._charx=await e.getCharacteristic(this.cfg.charxUUID),await this._charx.startNotifications(),this._charx.addEventListener("characteristicvaluechanged",this._data_h),this._buffer.clear(),this._change(i.State.Open)}catch(e){this._error(e),this._change(i.State.Closed),this.retry&&t(this.cfg.reconnect).then(()=>this._open())}}}async close(){this.retry=!1,this.opened()&&await this._close()}async _close(){this._change(i.State.Closing);try{this._device.gatt.disconnect()}catch(t){this._error(t)}}async sendText(t){await this.sendBin((new TextEncoder).encode(t))}async sendBin(t){this._buffer.push(t),this._send()}_device=null;_charx=null;_state=i.State.Closed;_buffer=new s;_decoder=new TextDecoder;async _disconnect(e){this._change(i.State.Closed),this._charx&&this._charx.removeEventListener("characteristicvaluechanged",this._data_h),this._charx=null,this.retry&&t(this.cfg.reconnect).then(()=>this._open()),await t(50)}_disconnect_h=this._disconnect.bind(this);_data(t){const e=t.target.value,s=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);this.onbin&&this.onbin(s),this.ontext&&this.splitter.write(this._decoder.decode(s,{stream:!0}))}_data_h=this._data.bind(this);async _send(){if(!this._busy){for(this._busy=!0;this._buffer.length&&this._charx;){let t=this._buffer.shift(this.cfg.max_tx);try{t.length&&await this._charx.writeValueWithoutResponse(t)}catch(t){}}this._busy=!1}}_error(t){this.onerror("[BLE] "+t)}_change(t){switch(this._state=t,this.onchange(t),t){case i.State.Open:this.onopen();break;case i.State.Closed:this.onclose()}}}export{i as default};
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@alexgyver/ble",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Web BLE Serial",
|
|
5
|
+
"main": "./ble.js",
|
|
6
|
+
"module": "./ble.js",
|
|
7
|
+
"types": "./ble.js",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "webpack --config ./webpack.config.js",
|
|
10
|
+
"dev": "webpack serve --config ./webpack.dev.config.js & webpack --config ./webpack.dev.config.js"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/GyverLibs/ble.js.git"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"webpack": "^5.103.0",
|
|
18
|
+
"webpack-cli": "^6.0.1",
|
|
19
|
+
"webpack-dev-server": "^5.2.2",
|
|
20
|
+
"html-webpack-plugin": "^5.6.5"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@alexgyver/utils": "^1.2.4"
|
|
24
|
+
},
|
|
25
|
+
"author": "AlexGyver <alex@alexgyver.ru>",
|
|
26
|
+
"license": "MIT"
|
|
27
|
+
}
|
package/test/index.html
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
|
|
7
|
+
<script src="script.js" type="module" defer="defer"></script>
|
|
8
|
+
<title>BLE test</title>
|
|
9
|
+
</head>
|
|
10
|
+
|
|
11
|
+
<body>
|
|
12
|
+
<button id="select_b">select</button>
|
|
13
|
+
<button id="open_b">open</button>
|
|
14
|
+
<button id="close_b">close</button>
|
|
15
|
+
<button id="send_b">send</button>
|
|
16
|
+
</body>
|
|
17
|
+
|
|
18
|
+
</html>
|
package/test/script.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import BLEJS from "https://gyverlibs.github.io/BLE.js/ble.min.js";
|
|
2
|
+
|
|
3
|
+
let i = 0;
|
|
4
|
+
let ble = new BLEJS({ auto_open: true, eol: '' });
|
|
5
|
+
|
|
6
|
+
// control
|
|
7
|
+
select_b.onclick = () => ble.select();
|
|
8
|
+
open_b.onclick = () => ble.open();
|
|
9
|
+
close_b.onclick = () => ble.close();
|
|
10
|
+
send_b.onclick = () => ble.sendText('Hello ' + i++);
|
|
11
|
+
|
|
12
|
+
// read
|
|
13
|
+
// ble.onbin = b => console.log(b);
|
|
14
|
+
ble.ontext = t => console.log(t);
|
|
15
|
+
|
|
16
|
+
// state
|
|
17
|
+
// ble.onopen = () => {
|
|
18
|
+
// console.log('Opened', ble.getName());
|
|
19
|
+
// }
|
|
20
|
+
// ble.onclose = () => {
|
|
21
|
+
// console.log('Closed');
|
|
22
|
+
// }
|
|
23
|
+
ble.onchange = s => {
|
|
24
|
+
console.log(s);
|
|
25
|
+
}
|
|
26
|
+
ble.onerror = e => {
|
|
27
|
+
console.log(e);
|
|
28
|
+
}
|
|
29
|
+
ble.onselect = (d) => {
|
|
30
|
+
console.log('select', d);
|
|
31
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#include <Arduino.h>
|
|
2
|
+
#include <BLESerial.h>
|
|
3
|
+
// https://github.com/GyverLibs/BLESerial_ESP32
|
|
4
|
+
|
|
5
|
+
void setup() {
|
|
6
|
+
Serial.begin(115200);
|
|
7
|
+
Serial.println("Start");
|
|
8
|
+
|
|
9
|
+
BLESerial.begin("ESP32C3");
|
|
10
|
+
|
|
11
|
+
BLESerial.onData([](uint8_t* data, size_t len) {
|
|
12
|
+
Serial.print("got data:");
|
|
13
|
+
Serial.write(data, len);
|
|
14
|
+
Serial.println();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
BLESerial.onState([](bool conn) {
|
|
18
|
+
Serial.println(conn ? "connect" : "disconnect");
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
void loop() {
|
|
23
|
+
static uint32_t t;
|
|
24
|
+
if (millis() - t >= 3000) {
|
|
25
|
+
t = millis();
|
|
26
|
+
static int i;
|
|
27
|
+
BLESerial.send(String("Hello ") + (++i));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
|
|
7
|
+
<script src="script.js" type="module" defer="defer"></script>
|
|
8
|
+
<title>BLE test</title>
|
|
9
|
+
</head>
|
|
10
|
+
|
|
11
|
+
<body>
|
|
12
|
+
<button id="select_b">select</button>
|
|
13
|
+
<button id="open_b">open</button>
|
|
14
|
+
<button id="close_b">close</button>
|
|
15
|
+
<button id="send_b">send</button>
|
|
16
|
+
</body>
|
|
17
|
+
|
|
18
|
+
</html>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import BLEJS from "../ble";
|
|
2
|
+
|
|
3
|
+
let i = 0;
|
|
4
|
+
let ble = new BLEJS({ auto_open: true, eol: '' });
|
|
5
|
+
|
|
6
|
+
// control
|
|
7
|
+
select_b.onclick = () => ble.select();
|
|
8
|
+
open_b.onclick = () => ble.open();
|
|
9
|
+
close_b.onclick = () => ble.close();
|
|
10
|
+
send_b.onclick = () => ble.sendText('Hello ' + i++);
|
|
11
|
+
|
|
12
|
+
// read
|
|
13
|
+
// ble.onbin = b => console.log(b);
|
|
14
|
+
ble.ontext = t => console.log(t);
|
|
15
|
+
|
|
16
|
+
// state
|
|
17
|
+
// ble.onopen = () => {
|
|
18
|
+
// console.log('Opened', ble.getName());
|
|
19
|
+
// }
|
|
20
|
+
// ble.onclose = () => {
|
|
21
|
+
// console.log('Closed');
|
|
22
|
+
// }
|
|
23
|
+
ble.onchange = s => {
|
|
24
|
+
console.log(s);
|
|
25
|
+
}
|
|
26
|
+
ble.onerror = e => {
|
|
27
|
+
console.log(e);
|
|
28
|
+
}
|
|
29
|
+
ble.onselect = (d) => {
|
|
30
|
+
console.log('select', d);
|
|
31
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const PACKAGE = require('./package.json');
|
|
3
|
+
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
entry: {
|
|
7
|
+
index: './test_dev/script.js',
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
output: {
|
|
11
|
+
filename: 'script.js',
|
|
12
|
+
path: path.resolve(__dirname, 'dev'),
|
|
13
|
+
clean: true,
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
plugins: [
|
|
17
|
+
new HtmlWebpackPlugin({
|
|
18
|
+
template: `./test_dev/index.html`,
|
|
19
|
+
filename: `index.html`,
|
|
20
|
+
inject: true,
|
|
21
|
+
minify: false,
|
|
22
|
+
version: PACKAGE.version,
|
|
23
|
+
title: PACKAGE.title,
|
|
24
|
+
}),
|
|
25
|
+
],
|
|
26
|
+
|
|
27
|
+
devServer: {
|
|
28
|
+
watchFiles: ['test_dev/*.html'],
|
|
29
|
+
static: path.resolve(__dirname, './dev'),
|
|
30
|
+
hot: true,
|
|
31
|
+
open: true,
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
watchOptions: {
|
|
35
|
+
poll: 1000,
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
mode: 'development',
|
|
39
|
+
};
|