nsd-ble 0.3.3 → 0.4.1
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/README.md +887 -0
- package/dist/Objects-Zntmn07s.cjs +1 -0
- package/dist/Objects-ulh5Kfet.js +1043 -0
- package/dist/main.cjs +1 -1
- package/dist/main.js +641 -287
- package/dist/objects.cjs +1 -1
- package/dist/objects.js +1 -1
- package/dist/types/Types.d.ts +99 -0
- package/dist/types/ble/BluetoothProvider.d.ts +9 -0
- package/dist/types/ble/Mesh.d.ts +14 -9
- package/dist/types/ble/MeshWriter.d.ts +8 -0
- package/dist/types/ble/MockBluetooth.d.ts +25 -0
- package/dist/types/ble/Settings.d.ts +4 -0
- package/dist/types/composable/Debug.d.ts +26 -0
- package/dist/types/main.d.ts +3 -1
- package/dist/types/standee/Loader.d.ts +5 -0
- package/package.json +1 -1
- package/dist/Objects-C2BH61j-.js +0 -941
- package/dist/Objects-WdcC281c.cjs +0 -1
- package/readme.md +0 -30
|
@@ -0,0 +1,1043 @@
|
|
|
1
|
+
import { Data as g, DataType as Ve, Button as x, FloodTypes as $ } from "./enums.js";
|
|
2
|
+
var O = {}, B = {}, ve;
|
|
3
|
+
function K() {
|
|
4
|
+
if (ve) return B;
|
|
5
|
+
ve = 1, Object.defineProperty(B, "__esModule", { value: !0 }), B.BaseEvent = void 0;
|
|
6
|
+
var e = (
|
|
7
|
+
/** @class */
|
|
8
|
+
(function() {
|
|
9
|
+
function r() {
|
|
10
|
+
}
|
|
11
|
+
return r.prototype.attach = function(t, l) {
|
|
12
|
+
return this._attach(t, l, !1);
|
|
13
|
+
}, r.prototype.once = function(t, l) {
|
|
14
|
+
return this._attach(t, l, !0);
|
|
15
|
+
}, r.prototype._attach = function(t, l, h) {
|
|
16
|
+
var v = this, u, a, i, c;
|
|
17
|
+
if (typeof t == "function")
|
|
18
|
+
a = t, c = function() {
|
|
19
|
+
return v.detach(a);
|
|
20
|
+
};
|
|
21
|
+
else if (!l && typeof t.post == "function")
|
|
22
|
+
i = t, c = function() {
|
|
23
|
+
return v.detach(i);
|
|
24
|
+
};
|
|
25
|
+
else {
|
|
26
|
+
if (typeof t != "object" || t === void 0)
|
|
27
|
+
throw new Error("Expect a function or object as first argument");
|
|
28
|
+
if (typeof l != "function")
|
|
29
|
+
throw new Error("Expect a function as second argument");
|
|
30
|
+
u = t, a = l, c = function() {
|
|
31
|
+
return v.detach(u, a);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return this._listeners ? this._listeners = this._listeners.slice() : this._listeners = [], this._listeners.push({
|
|
35
|
+
deleted: !1,
|
|
36
|
+
boundTo: u,
|
|
37
|
+
handler: a,
|
|
38
|
+
event: i,
|
|
39
|
+
once: h
|
|
40
|
+
}), c;
|
|
41
|
+
}, r.prototype.detach = function() {
|
|
42
|
+
for (var t = [], l = 0; l < arguments.length; l++)
|
|
43
|
+
t[l] = arguments[l];
|
|
44
|
+
this._detach.apply(this, t);
|
|
45
|
+
}, r.prototype._detach = function() {
|
|
46
|
+
for (var t = [], l = 0; l < arguments.length; l++)
|
|
47
|
+
t[l] = arguments[l];
|
|
48
|
+
if (!(!this._listeners || this._listeners.length === 0)) {
|
|
49
|
+
var h, v, u;
|
|
50
|
+
t.length >= 1 && (typeof t[0] == "function" ? v = t[0] : t.length === 1 && typeof t[0].post == "function" ? u = t[0] : h = t[0]), t.length >= 2 && (v = t[1]), this._listeners = this._listeners.filter(function(a) {
|
|
51
|
+
return (typeof v > "u" || a.handler === v) && (typeof u > "u" || a.event === u) && (typeof h > "u" || a.boundTo === h) ? (a.deleted = !0, !1) : !0;
|
|
52
|
+
}), this._listeners.length === 0 && delete this._listeners;
|
|
53
|
+
}
|
|
54
|
+
}, r.prototype.post = function(t) {
|
|
55
|
+
throw new Error("abstract");
|
|
56
|
+
}, r.prototype.listenerCount = function() {
|
|
57
|
+
return this._listeners ? this._listeners.length : 0;
|
|
58
|
+
}, r.prototype._call = function(t, l) {
|
|
59
|
+
this._listeners && (t.deleted || (t.once && (t.deleted = !0, this._listeners = this._listeners.filter(function(h) {
|
|
60
|
+
return h !== t;
|
|
61
|
+
}), this._listeners.length === 0 && delete this._listeners), t.event ? t.event.post.apply(t.event, l) : t.handler && t.handler.apply(typeof t.boundTo == "object" ? t.boundTo : this, l)));
|
|
62
|
+
}, r;
|
|
63
|
+
})()
|
|
64
|
+
);
|
|
65
|
+
return B.BaseEvent = e, B;
|
|
66
|
+
}
|
|
67
|
+
var m = {}, de;
|
|
68
|
+
function N() {
|
|
69
|
+
if (de) return m;
|
|
70
|
+
de = 1;
|
|
71
|
+
var e = m && m.__extends || /* @__PURE__ */ (function() {
|
|
72
|
+
var v = function(u, a) {
|
|
73
|
+
return v = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(i, c) {
|
|
74
|
+
i.__proto__ = c;
|
|
75
|
+
} || function(i, c) {
|
|
76
|
+
for (var s in c) c.hasOwnProperty(s) && (i[s] = c[s]);
|
|
77
|
+
}, v(u, a);
|
|
78
|
+
};
|
|
79
|
+
return function(u, a) {
|
|
80
|
+
v(u, a);
|
|
81
|
+
function i() {
|
|
82
|
+
this.constructor = u;
|
|
83
|
+
}
|
|
84
|
+
u.prototype = a === null ? Object.create(a) : (i.prototype = a.prototype, new i());
|
|
85
|
+
};
|
|
86
|
+
})();
|
|
87
|
+
Object.defineProperty(m, "__esModule", { value: !0 }), m.ErrorSyncEvent = m.VoidSyncEvent = m.SyncEvent = void 0;
|
|
88
|
+
var r = K(), t = (
|
|
89
|
+
/** @class */
|
|
90
|
+
(function(v) {
|
|
91
|
+
e(u, v);
|
|
92
|
+
function u() {
|
|
93
|
+
var a = v !== null && v.apply(this, arguments) || this;
|
|
94
|
+
return a._recursion = 0, a;
|
|
95
|
+
}
|
|
96
|
+
return Object.defineProperty(u.prototype, "evtListenersChanged", {
|
|
97
|
+
/**
|
|
98
|
+
* Sent when someone attaches or detaches
|
|
99
|
+
*/
|
|
100
|
+
get: function() {
|
|
101
|
+
return this._listenersChanged || (this._listenersChanged = new l()), this._listenersChanged;
|
|
102
|
+
},
|
|
103
|
+
enumerable: !1,
|
|
104
|
+
configurable: !0
|
|
105
|
+
}), u.prototype.post = function() {
|
|
106
|
+
for (var a = [], i = 0; i < arguments.length; i++)
|
|
107
|
+
a[i] = arguments[i];
|
|
108
|
+
if (!(!this._listeners || this._listeners.length === 0)) {
|
|
109
|
+
if (this._recursion++, typeof u.MAX_RECURSION_DEPTH == "number" && Number.isInteger(u.MAX_RECURSION_DEPTH) && u.MAX_RECURSION_DEPTH > 0 && this._recursion > u.MAX_RECURSION_DEPTH)
|
|
110
|
+
throw new Error("event fired recursively");
|
|
111
|
+
for (var c = this._listeners, s = 0; s < c.length; ++s) {
|
|
112
|
+
var n = c[s];
|
|
113
|
+
this._call(n, a);
|
|
114
|
+
}
|
|
115
|
+
this._recursion--;
|
|
116
|
+
}
|
|
117
|
+
}, u.prototype._attach = function(a, i, c) {
|
|
118
|
+
var s, n, o, f, d = (n = (s = this._listeners) === null || s === void 0 ? void 0 : s.length) !== null && n !== void 0 ? n : 0, p = v.prototype._attach.call(this, a, i, c);
|
|
119
|
+
return this.evtListenersChanged && d !== ((f = (o = this._listeners) === null || o === void 0 ? void 0 : o.length) !== null && f !== void 0 ? f : 0) && this.evtListenersChanged.post(), p;
|
|
120
|
+
}, u.prototype._detach = function() {
|
|
121
|
+
for (var a, i, c, s, n = [], o = 0; o < arguments.length; o++)
|
|
122
|
+
n[o] = arguments[o];
|
|
123
|
+
var f = (i = (a = this._listeners) === null || a === void 0 ? void 0 : a.length) !== null && i !== void 0 ? i : 0, d = v.prototype._detach.apply(this, n);
|
|
124
|
+
return this.evtListenersChanged && f !== ((s = (c = this._listeners) === null || c === void 0 ? void 0 : c.length) !== null && s !== void 0 ? s : 0) && this.evtListenersChanged.post(), d;
|
|
125
|
+
}, u.MAX_RECURSION_DEPTH = 10, u;
|
|
126
|
+
})(r.BaseEvent)
|
|
127
|
+
);
|
|
128
|
+
m.SyncEvent = t;
|
|
129
|
+
var l = (
|
|
130
|
+
/** @class */
|
|
131
|
+
(function(v) {
|
|
132
|
+
e(u, v);
|
|
133
|
+
function u() {
|
|
134
|
+
return v !== null && v.apply(this, arguments) || this;
|
|
135
|
+
}
|
|
136
|
+
return u.prototype.post = function() {
|
|
137
|
+
v.prototype.post.call(this, void 0);
|
|
138
|
+
}, u;
|
|
139
|
+
})(t)
|
|
140
|
+
);
|
|
141
|
+
m.VoidSyncEvent = l;
|
|
142
|
+
var h = (
|
|
143
|
+
/** @class */
|
|
144
|
+
(function(v) {
|
|
145
|
+
e(u, v);
|
|
146
|
+
function u() {
|
|
147
|
+
return v !== null && v.apply(this, arguments) || this;
|
|
148
|
+
}
|
|
149
|
+
return u.prototype.post = function(a) {
|
|
150
|
+
if (this.listenerCount() === 0)
|
|
151
|
+
throw new Error("error event posted while no listeners attached. Error: " + a.message);
|
|
152
|
+
v.prototype.post.call(this, a);
|
|
153
|
+
}, u;
|
|
154
|
+
})(t)
|
|
155
|
+
);
|
|
156
|
+
return m.ErrorSyncEvent = h, m;
|
|
157
|
+
}
|
|
158
|
+
var C = {}, F = {}, pe;
|
|
159
|
+
function ee() {
|
|
160
|
+
if (pe) return F;
|
|
161
|
+
pe = 1, Object.defineProperty(F, "__esModule", { value: !0 });
|
|
162
|
+
var e = N(), r = (
|
|
163
|
+
/** @class */
|
|
164
|
+
(function() {
|
|
165
|
+
function t() {
|
|
166
|
+
this.evtFilled = new e.SyncEvent(), this.evtDrained = new e.SyncEvent(), this._queue = [], this._flushing = !1;
|
|
167
|
+
}
|
|
168
|
+
return t.global = function() {
|
|
169
|
+
return t._instance || t.resetGlobal(), t._instance;
|
|
170
|
+
}, t.resetGlobal = function() {
|
|
171
|
+
t._instance = new t();
|
|
172
|
+
}, t.prototype.empty = function() {
|
|
173
|
+
return this._queue.length === 0;
|
|
174
|
+
}, t.prototype.add = function(l) {
|
|
175
|
+
this._queue.push(l), this._queue.length === 1 && !this._flushing && this.evtFilled.post(this);
|
|
176
|
+
}, t.prototype.flushOnce = function() {
|
|
177
|
+
var l = this._queue.length === 0, h = this._flushing;
|
|
178
|
+
this._flushing = !0;
|
|
179
|
+
try {
|
|
180
|
+
var v = this._queue;
|
|
181
|
+
this._queue = [];
|
|
182
|
+
for (var u = 0; u < v.length; ++u)
|
|
183
|
+
v[u]();
|
|
184
|
+
} finally {
|
|
185
|
+
this._flushing = h, !l && !h && this._queue.length === 0 && this.evtDrained.post(this);
|
|
186
|
+
}
|
|
187
|
+
}, t.prototype.flush = function(l) {
|
|
188
|
+
l === void 0 && (l = 10);
|
|
189
|
+
var h = this._queue.length === 0, v = this._flushing;
|
|
190
|
+
this._flushing = !0;
|
|
191
|
+
try {
|
|
192
|
+
for (var u = 0; this._queue.length > 0; ) {
|
|
193
|
+
if (typeof l == "number" && u >= l)
|
|
194
|
+
throw this._queue = [], new Error("unable to flush the queue due to recursively added event. Clearing queue now");
|
|
195
|
+
this.flushOnce(), ++u;
|
|
196
|
+
}
|
|
197
|
+
} finally {
|
|
198
|
+
this._flushing = v, !h && !v && this._queue.length === 0 && this.evtDrained.post(this);
|
|
199
|
+
}
|
|
200
|
+
}, t;
|
|
201
|
+
})()
|
|
202
|
+
);
|
|
203
|
+
return F.default = r, F;
|
|
204
|
+
}
|
|
205
|
+
var ye;
|
|
206
|
+
function Ae() {
|
|
207
|
+
if (ye) return C;
|
|
208
|
+
ye = 1;
|
|
209
|
+
var e = C && C.__extends || /* @__PURE__ */ (function() {
|
|
210
|
+
var a = function(i, c) {
|
|
211
|
+
return a = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(s, n) {
|
|
212
|
+
s.__proto__ = n;
|
|
213
|
+
} || function(s, n) {
|
|
214
|
+
for (var o in n) n.hasOwnProperty(o) && (s[o] = n[o]);
|
|
215
|
+
}, a(i, c);
|
|
216
|
+
};
|
|
217
|
+
return function(i, c) {
|
|
218
|
+
a(i, c);
|
|
219
|
+
function s() {
|
|
220
|
+
this.constructor = i;
|
|
221
|
+
}
|
|
222
|
+
i.prototype = c === null ? Object.create(c) : (s.prototype = c.prototype, new s());
|
|
223
|
+
};
|
|
224
|
+
})();
|
|
225
|
+
Object.defineProperty(C, "__esModule", { value: !0 }), C.ErrorQueuedEvent = C.VoidQueuedEvent = C.QueuedEvent = void 0;
|
|
226
|
+
var r = K(), t = ee(), l = N(), h = (
|
|
227
|
+
/** @class */
|
|
228
|
+
(function(a) {
|
|
229
|
+
e(i, a);
|
|
230
|
+
function i(c) {
|
|
231
|
+
c === void 0 && (c = {});
|
|
232
|
+
var s = a.call(this) || this;
|
|
233
|
+
return s._queued = !1, s.options = c, typeof c.condensed == "boolean" ? s._condensed = c.condensed : s._condensed = !1, typeof c.queue == "object" && c.queue !== null && (s._queue = c.queue), s;
|
|
234
|
+
}
|
|
235
|
+
return Object.defineProperty(i.prototype, "evtListenersChanged", {
|
|
236
|
+
/**
|
|
237
|
+
* Sent when someone attaches or detaches
|
|
238
|
+
*/
|
|
239
|
+
get: function() {
|
|
240
|
+
return this._listenersChanged || (this._listenersChanged = new l.VoidSyncEvent()), this._listenersChanged;
|
|
241
|
+
},
|
|
242
|
+
enumerable: !1,
|
|
243
|
+
configurable: !0
|
|
244
|
+
}), i.prototype.post = function() {
|
|
245
|
+
for (var c = this, s = [], n = 0; n < arguments.length; n++)
|
|
246
|
+
s[n] = arguments[n];
|
|
247
|
+
if (!(!this._listeners || this._listeners.length === 0)) {
|
|
248
|
+
var o = this._queue ? this._queue : t.default.global();
|
|
249
|
+
if (this._condensed) {
|
|
250
|
+
if (this._queuedData = s, this._queuedListeners = this._listeners, this._queued)
|
|
251
|
+
return;
|
|
252
|
+
this._queued = !0, o.add(function() {
|
|
253
|
+
c._queued = !1;
|
|
254
|
+
for (var d = c._queuedData, p = c._queuedListeners, y = 0; y < p.length; ++y) {
|
|
255
|
+
var _ = p[y];
|
|
256
|
+
c._call(_, d);
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
} else {
|
|
260
|
+
var f = this._listeners;
|
|
261
|
+
o.add(function() {
|
|
262
|
+
for (var d = 0; d < f.length; ++d) {
|
|
263
|
+
var p = f[d];
|
|
264
|
+
c._call(p, s);
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}, i.prototype._attach = function(c, s, n) {
|
|
270
|
+
var o, f, d, p, y = (f = (o = this._listeners) === null || o === void 0 ? void 0 : o.length) !== null && f !== void 0 ? f : 0, _ = a.prototype._attach.call(this, c, s, n);
|
|
271
|
+
return this.evtListenersChanged && y !== ((p = (d = this._listeners) === null || d === void 0 ? void 0 : d.length) !== null && p !== void 0 ? p : 0) && this.evtListenersChanged.post(), _;
|
|
272
|
+
}, i.prototype._detach = function() {
|
|
273
|
+
for (var c, s, n, o, f = [], d = 0; d < arguments.length; d++)
|
|
274
|
+
f[d] = arguments[d];
|
|
275
|
+
var p = (s = (c = this._listeners) === null || c === void 0 ? void 0 : c.length) !== null && s !== void 0 ? s : 0, y = a.prototype._detach.apply(this, f);
|
|
276
|
+
return this.evtListenersChanged && p !== ((o = (n = this._listeners) === null || n === void 0 ? void 0 : n.length) !== null && o !== void 0 ? o : 0) && this.evtListenersChanged.post(), y;
|
|
277
|
+
}, i;
|
|
278
|
+
})(r.BaseEvent)
|
|
279
|
+
);
|
|
280
|
+
C.QueuedEvent = h;
|
|
281
|
+
var v = (
|
|
282
|
+
/** @class */
|
|
283
|
+
(function(a) {
|
|
284
|
+
e(i, a);
|
|
285
|
+
function i() {
|
|
286
|
+
return a !== null && a.apply(this, arguments) || this;
|
|
287
|
+
}
|
|
288
|
+
return i.prototype.post = function() {
|
|
289
|
+
a.prototype.post.call(this, void 0);
|
|
290
|
+
}, i;
|
|
291
|
+
})(h)
|
|
292
|
+
);
|
|
293
|
+
C.VoidQueuedEvent = v;
|
|
294
|
+
var u = (
|
|
295
|
+
/** @class */
|
|
296
|
+
(function(a) {
|
|
297
|
+
e(i, a);
|
|
298
|
+
function i() {
|
|
299
|
+
return a !== null && a.apply(this, arguments) || this;
|
|
300
|
+
}
|
|
301
|
+
return i.prototype.post = function(c) {
|
|
302
|
+
if (!this._listeners || this._listeners.length === 0)
|
|
303
|
+
throw new Error("error event posted while no listeners attached. Error: " + c.message);
|
|
304
|
+
a.prototype.post.call(this, c);
|
|
305
|
+
}, i;
|
|
306
|
+
})(h)
|
|
307
|
+
);
|
|
308
|
+
return C.ErrorQueuedEvent = u, C;
|
|
309
|
+
}
|
|
310
|
+
var A = {}, ge;
|
|
311
|
+
function Se() {
|
|
312
|
+
if (ge) return A;
|
|
313
|
+
ge = 1;
|
|
314
|
+
var e = A && A.__extends || /* @__PURE__ */ (function() {
|
|
315
|
+
var u = function(a, i) {
|
|
316
|
+
return u = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(c, s) {
|
|
317
|
+
c.__proto__ = s;
|
|
318
|
+
} || function(c, s) {
|
|
319
|
+
for (var n in s) s.hasOwnProperty(n) && (c[n] = s[n]);
|
|
320
|
+
}, u(a, i);
|
|
321
|
+
};
|
|
322
|
+
return function(a, i) {
|
|
323
|
+
u(a, i);
|
|
324
|
+
function c() {
|
|
325
|
+
this.constructor = a;
|
|
326
|
+
}
|
|
327
|
+
a.prototype = i === null ? Object.create(i) : (c.prototype = i.prototype, new c());
|
|
328
|
+
};
|
|
329
|
+
})();
|
|
330
|
+
Object.defineProperty(A, "__esModule", { value: !0 }), A.ErrorAsyncEvent = A.VoidAsyncEvent = A.AsyncEvent = void 0;
|
|
331
|
+
var r = K(), t = N(), l = (
|
|
332
|
+
/** @class */
|
|
333
|
+
(function(u) {
|
|
334
|
+
e(a, u);
|
|
335
|
+
function a(i) {
|
|
336
|
+
i === void 0 && (i = {});
|
|
337
|
+
var c = u.call(this) || this;
|
|
338
|
+
return c._queued = !1, c.options = i, typeof i.condensed == "boolean" ? c._condensed = i.condensed : c._condensed = !1, c;
|
|
339
|
+
}
|
|
340
|
+
return Object.defineProperty(a.prototype, "evtListenersChanged", {
|
|
341
|
+
/**
|
|
342
|
+
* Sent when someone attaches or detaches
|
|
343
|
+
*/
|
|
344
|
+
get: function() {
|
|
345
|
+
return this._listenersChanged || (this._listenersChanged = new t.VoidSyncEvent()), this._listenersChanged;
|
|
346
|
+
},
|
|
347
|
+
enumerable: !1,
|
|
348
|
+
configurable: !0
|
|
349
|
+
}), a.defaultScheduler = function(i) {
|
|
350
|
+
typeof window < "u" ? setTimeout(i, 0) : setImmediate(i);
|
|
351
|
+
}, a.setScheduler = function(i) {
|
|
352
|
+
a._scheduler = i;
|
|
353
|
+
}, a.prototype.post = function() {
|
|
354
|
+
for (var i = this, c = [], s = 0; s < arguments.length; s++)
|
|
355
|
+
c[s] = arguments[s];
|
|
356
|
+
if (!(!this._listeners || this._listeners.length === 0))
|
|
357
|
+
if (this._condensed) {
|
|
358
|
+
if (this._queuedData = c, this._queuedListeners = this._listeners, this._queued)
|
|
359
|
+
return;
|
|
360
|
+
this._queued = !0, a._scheduler(function() {
|
|
361
|
+
i._queued = !1;
|
|
362
|
+
for (var o = i._queuedData, f = i._queuedListeners, d = 0; d < f.length; ++d) {
|
|
363
|
+
var p = f[d];
|
|
364
|
+
i._call(p, o);
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
} else {
|
|
368
|
+
var n = this._listeners;
|
|
369
|
+
a._scheduler(function() {
|
|
370
|
+
for (var o = 0; o < n.length; ++o) {
|
|
371
|
+
var f = n[o];
|
|
372
|
+
i._call(f, c);
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
}, a.prototype._call = function(i, c) {
|
|
377
|
+
i.event && i.event instanceof a ? i.event._postDirect(c) : u.prototype._call.call(this, i, c);
|
|
378
|
+
}, a.prototype._postDirect = function(i) {
|
|
379
|
+
if (!(!this._listeners || this._listeners.length === 0))
|
|
380
|
+
for (var c = this._listeners, s = 0; s < c.length; ++s) {
|
|
381
|
+
var n = c[s];
|
|
382
|
+
this._call(n, i);
|
|
383
|
+
}
|
|
384
|
+
}, a.prototype._attach = function(i, c, s) {
|
|
385
|
+
var n, o, f, d, p = (o = (n = this._listeners) === null || n === void 0 ? void 0 : n.length) !== null && o !== void 0 ? o : 0, y = u.prototype._attach.call(this, i, c, s);
|
|
386
|
+
return this.evtListenersChanged && p !== ((d = (f = this._listeners) === null || f === void 0 ? void 0 : f.length) !== null && d !== void 0 ? d : 0) && this.evtListenersChanged.post(), y;
|
|
387
|
+
}, a.prototype._detach = function() {
|
|
388
|
+
for (var i, c, s, n, o = [], f = 0; f < arguments.length; f++)
|
|
389
|
+
o[f] = arguments[f];
|
|
390
|
+
var d = (c = (i = this._listeners) === null || i === void 0 ? void 0 : i.length) !== null && c !== void 0 ? c : 0, p = u.prototype._detach.apply(this, o);
|
|
391
|
+
return this.evtListenersChanged && d !== ((n = (s = this._listeners) === null || s === void 0 ? void 0 : s.length) !== null && n !== void 0 ? n : 0) && this.evtListenersChanged.post(), p;
|
|
392
|
+
}, a._scheduler = a.defaultScheduler, a;
|
|
393
|
+
})(r.BaseEvent)
|
|
394
|
+
);
|
|
395
|
+
A.AsyncEvent = l;
|
|
396
|
+
var h = (
|
|
397
|
+
/** @class */
|
|
398
|
+
(function(u) {
|
|
399
|
+
e(a, u);
|
|
400
|
+
function a() {
|
|
401
|
+
return u !== null && u.apply(this, arguments) || this;
|
|
402
|
+
}
|
|
403
|
+
return a.prototype.post = function() {
|
|
404
|
+
u.prototype.post.call(this, void 0);
|
|
405
|
+
}, a;
|
|
406
|
+
})(l)
|
|
407
|
+
);
|
|
408
|
+
A.VoidAsyncEvent = h;
|
|
409
|
+
var v = (
|
|
410
|
+
/** @class */
|
|
411
|
+
(function(u) {
|
|
412
|
+
e(a, u);
|
|
413
|
+
function a() {
|
|
414
|
+
return u !== null && u.apply(this, arguments) || this;
|
|
415
|
+
}
|
|
416
|
+
return a.prototype.post = function(i) {
|
|
417
|
+
if (this.listenerCount() === 0)
|
|
418
|
+
throw new Error("error event posted while no listeners attached. Error: " + i.message);
|
|
419
|
+
u.prototype.post.call(this, i);
|
|
420
|
+
}, a;
|
|
421
|
+
})(l)
|
|
422
|
+
);
|
|
423
|
+
return A.ErrorAsyncEvent = v, A;
|
|
424
|
+
}
|
|
425
|
+
var Q = {}, R = {}, _e;
|
|
426
|
+
function $e() {
|
|
427
|
+
if (_e) return R;
|
|
428
|
+
_e = 1, Object.defineProperty(R, "__esModule", { value: !0 }), R.shallowEquals = void 0;
|
|
429
|
+
function e(r, t) {
|
|
430
|
+
if (r === t)
|
|
431
|
+
return !0;
|
|
432
|
+
if (typeof r != typeof t)
|
|
433
|
+
return !1;
|
|
434
|
+
switch (typeof r) {
|
|
435
|
+
case "boolean":
|
|
436
|
+
case "number":
|
|
437
|
+
case "string":
|
|
438
|
+
case "function":
|
|
439
|
+
case "symbol":
|
|
440
|
+
case "undefined":
|
|
441
|
+
return !1;
|
|
442
|
+
case "object":
|
|
443
|
+
if (r === null || t === null)
|
|
444
|
+
return !1;
|
|
445
|
+
if (Array.isArray(r) || Array.isArray(t)) {
|
|
446
|
+
if (!Array.isArray(r) || !Array.isArray(t) || r.length !== t.length)
|
|
447
|
+
return !1;
|
|
448
|
+
for (var l = 0; l < r.length; ++l)
|
|
449
|
+
if (r[l] !== t[l])
|
|
450
|
+
return !1;
|
|
451
|
+
return !0;
|
|
452
|
+
}
|
|
453
|
+
var h = [], v = [];
|
|
454
|
+
for (var u in r)
|
|
455
|
+
r.hasOwnProperty(u) && h.push(u);
|
|
456
|
+
for (var a in t)
|
|
457
|
+
t.hasOwnProperty(a) && v.push(a);
|
|
458
|
+
if (h.sort(), v.sort(), h.join(",") !== v.join(","))
|
|
459
|
+
return !1;
|
|
460
|
+
for (var l = 0; l < h.length; ++l)
|
|
461
|
+
if (r[h[l]] !== t[h[l]])
|
|
462
|
+
return !1;
|
|
463
|
+
return !0;
|
|
464
|
+
default:
|
|
465
|
+
return !1;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return R.shallowEquals = e, R;
|
|
469
|
+
}
|
|
470
|
+
var Ee;
|
|
471
|
+
function Fe() {
|
|
472
|
+
return Ee || (Ee = 1, (function(e) {
|
|
473
|
+
var r = Q && Q.__extends || /* @__PURE__ */ (function() {
|
|
474
|
+
var s = function(n, o) {
|
|
475
|
+
return s = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(f, d) {
|
|
476
|
+
f.__proto__ = d;
|
|
477
|
+
} || function(f, d) {
|
|
478
|
+
for (var p in d) d.hasOwnProperty(p) && (f[p] = d[p]);
|
|
479
|
+
}, s(n, o);
|
|
480
|
+
};
|
|
481
|
+
return function(n, o) {
|
|
482
|
+
s(n, o);
|
|
483
|
+
function f() {
|
|
484
|
+
this.constructor = n;
|
|
485
|
+
}
|
|
486
|
+
n.prototype = o === null ? Object.create(o) : (f.prototype = o.prototype, new f());
|
|
487
|
+
};
|
|
488
|
+
})();
|
|
489
|
+
Object.defineProperty(e, "__esModule", { value: !0 }), e.ErrorAnyEvent = e.VoidAnyEvent = e.AnyEvent = e.EventType = void 0;
|
|
490
|
+
var t = $e(), l = N(), h = Se(), v = Ae(), u;
|
|
491
|
+
(function(s) {
|
|
492
|
+
s[s.Sync = 0] = "Sync", s[s.Async = 1] = "Async", s[s.Queued = 2] = "Queued";
|
|
493
|
+
})(u = e.EventType || (e.EventType = {}));
|
|
494
|
+
var a = (
|
|
495
|
+
/** @class */
|
|
496
|
+
(function() {
|
|
497
|
+
function s(n) {
|
|
498
|
+
this._events = [], n && n.monitorAttach && (this.evtFirstAttached = new i(), this.evtLastDetached = new i());
|
|
499
|
+
}
|
|
500
|
+
return Object.defineProperty(s.prototype, "evtListenersChanged", {
|
|
501
|
+
/**
|
|
502
|
+
* Sent when someone attaches or detaches
|
|
503
|
+
*/
|
|
504
|
+
get: function() {
|
|
505
|
+
return this._listenersChanged || (this._listenersChanged = new l.VoidSyncEvent()), this._listenersChanged;
|
|
506
|
+
},
|
|
507
|
+
enumerable: !1,
|
|
508
|
+
configurable: !0
|
|
509
|
+
}), s.prototype.attach = function() {
|
|
510
|
+
for (var n = [], o = 0; o < arguments.length; o++)
|
|
511
|
+
n[o] = arguments[o];
|
|
512
|
+
var f = u.Sync;
|
|
513
|
+
n.length > 0 && typeof n[0] == "number" && (f = n.shift());
|
|
514
|
+
var d = this, p, y, _;
|
|
515
|
+
return typeof n[0] == "function" || n[0] && typeof n[0] == "object" && typeof n[0].post == "function" ? (typeof n[0] == "function" ? p = n[0] : _ = n[0], y = n[1]) : (d = n[0], p = n[1], y = n[2]), this._attach(f, d, p, _, y, !1);
|
|
516
|
+
}, s.prototype.once = function() {
|
|
517
|
+
for (var n = [], o = 0; o < arguments.length; o++)
|
|
518
|
+
n[o] = arguments[o];
|
|
519
|
+
var f = u.Sync;
|
|
520
|
+
n.length > 0 && typeof n[0] == "number" && (f = n.shift());
|
|
521
|
+
var d = this, p, y, _;
|
|
522
|
+
return typeof n[0] == "function" || n[0] && typeof n[0] == "object" && typeof n[0].post == "function" ? (typeof n[0] == "function" ? p = n[0] : _ = n[0], y = n[1]) : (d = n[0], p = n[1], y = n[2]), this._attach(f, d, p, _, y, !0);
|
|
523
|
+
}, s.prototype._attach = function(n, o, f, d, p, y) {
|
|
524
|
+
var _ = this, ue = this.evtFirstAttached ? this.listenerCount() : 0, E;
|
|
525
|
+
switch (n) {
|
|
526
|
+
case u.Sync:
|
|
527
|
+
{
|
|
528
|
+
for (var z = 0, ce = this._events; z < ce.length; z++) {
|
|
529
|
+
var S = ce[z];
|
|
530
|
+
S instanceof l.SyncEvent && (E = S);
|
|
531
|
+
}
|
|
532
|
+
E || (E = new l.SyncEvent(), this._events.push(E));
|
|
533
|
+
}
|
|
534
|
+
break;
|
|
535
|
+
case u.Async:
|
|
536
|
+
{
|
|
537
|
+
for (var W = 0, le = this._events; W < le.length; W++) {
|
|
538
|
+
var S = le[W];
|
|
539
|
+
S instanceof h.AsyncEvent && t.shallowEquals(S.options, p) && (E = S);
|
|
540
|
+
}
|
|
541
|
+
E || (E = new h.AsyncEvent(p), this._events.push(E));
|
|
542
|
+
}
|
|
543
|
+
break;
|
|
544
|
+
case u.Queued:
|
|
545
|
+
{
|
|
546
|
+
for (var J = 0, he = this._events; J < he.length; J++) {
|
|
547
|
+
var S = he[J];
|
|
548
|
+
S instanceof v.QueuedEvent && t.shallowEquals(S.options, p) && (E = S);
|
|
549
|
+
}
|
|
550
|
+
E || (E = new v.QueuedEvent(p), this._events.push(E));
|
|
551
|
+
}
|
|
552
|
+
break;
|
|
553
|
+
default:
|
|
554
|
+
throw new Error("unknown EventType");
|
|
555
|
+
}
|
|
556
|
+
var U;
|
|
557
|
+
return y ? d ? U = E.once(d) : U = E.once(o, f) : d ? U = E.attach(d) : U = E.attach(o, f), this.evtFirstAttached && ue === 0 && this.evtFirstAttached.post(), this.evtListenersChanged && ue !== this.listenerCount() && this.evtListenersChanged.post(), function() {
|
|
558
|
+
var fe = _.evtLastDetached ? _.listenerCount() : 0;
|
|
559
|
+
U(), _.evtLastDetached && fe > 0 && _.listenerCount() === 0 && _.evtLastDetached.post(), _.evtListenersChanged && fe !== _.listenerCount() && _.evtListenersChanged.post();
|
|
560
|
+
};
|
|
561
|
+
}, s.prototype.attachSync = function() {
|
|
562
|
+
for (var n = [], o = 0; o < arguments.length; o++)
|
|
563
|
+
n[o] = arguments[o];
|
|
564
|
+
return n.unshift(u.Sync), this.attach.apply(this, n);
|
|
565
|
+
}, s.prototype.onceSync = function() {
|
|
566
|
+
for (var n = [], o = 0; o < arguments.length; o++)
|
|
567
|
+
n[o] = arguments[o];
|
|
568
|
+
return n.unshift(u.Sync), this.once.apply(this, n);
|
|
569
|
+
}, s.prototype.attachAsync = function() {
|
|
570
|
+
for (var n = [], o = 0; o < arguments.length; o++)
|
|
571
|
+
n[o] = arguments[o];
|
|
572
|
+
return n.unshift(u.Async), this.attach.apply(this, n);
|
|
573
|
+
}, s.prototype.onceAsync = function() {
|
|
574
|
+
for (var n = [], o = 0; o < arguments.length; o++)
|
|
575
|
+
n[o] = arguments[o];
|
|
576
|
+
return n.unshift(u.Async), this.once.apply(this, n);
|
|
577
|
+
}, s.prototype.attachQueued = function() {
|
|
578
|
+
for (var n = [], o = 0; o < arguments.length; o++)
|
|
579
|
+
n[o] = arguments[o];
|
|
580
|
+
return n.unshift(u.Queued), this.attach.apply(this, n);
|
|
581
|
+
}, s.prototype.onceQueued = function() {
|
|
582
|
+
for (var n = [], o = 0; o < arguments.length; o++)
|
|
583
|
+
n[o] = arguments[o];
|
|
584
|
+
return n.unshift(u.Queued), this.once.apply(this, n);
|
|
585
|
+
}, s.prototype.detach = function() {
|
|
586
|
+
for (var n = [], o = 0; o < arguments.length; o++)
|
|
587
|
+
n[o] = arguments[o];
|
|
588
|
+
for (var f = this.listenerCount(), d = 0; d < this._events.length; ++d)
|
|
589
|
+
this._events[d].detach.apply(this._events[d], n);
|
|
590
|
+
this.evtListenersChanged && f !== this.listenerCount() && this.evtListenersChanged.post(), this.evtLastDetached && f > 0 && this.listenerCount() === 0 && this.evtLastDetached.post();
|
|
591
|
+
}, s.prototype.post = function(n) {
|
|
592
|
+
for (var o = [], f = 0; f < this._events.length; ++f)
|
|
593
|
+
o.push(this._events[f]);
|
|
594
|
+
for (var f = 0; f < o.length; ++f)
|
|
595
|
+
o[f].post(n);
|
|
596
|
+
}, s.prototype.listenerCount = function() {
|
|
597
|
+
for (var n = 0, o = 0; o < this._events.length; ++o)
|
|
598
|
+
n += this._events[o].listenerCount();
|
|
599
|
+
return n;
|
|
600
|
+
}, s;
|
|
601
|
+
})()
|
|
602
|
+
);
|
|
603
|
+
e.AnyEvent = a;
|
|
604
|
+
var i = (
|
|
605
|
+
/** @class */
|
|
606
|
+
(function(s) {
|
|
607
|
+
r(n, s);
|
|
608
|
+
function n() {
|
|
609
|
+
return s !== null && s.apply(this, arguments) || this;
|
|
610
|
+
}
|
|
611
|
+
return n.prototype.post = function() {
|
|
612
|
+
s.prototype.post.call(this, void 0);
|
|
613
|
+
}, n;
|
|
614
|
+
})(a)
|
|
615
|
+
);
|
|
616
|
+
e.VoidAnyEvent = i;
|
|
617
|
+
var c = (
|
|
618
|
+
/** @class */
|
|
619
|
+
(function(s) {
|
|
620
|
+
r(n, s);
|
|
621
|
+
function n() {
|
|
622
|
+
return s !== null && s.apply(this, arguments) || this;
|
|
623
|
+
}
|
|
624
|
+
return n.prototype.post = function(o) {
|
|
625
|
+
if (this.listenerCount() === 0)
|
|
626
|
+
throw new Error("error event posted while no listeners attached. Error: " + o.message);
|
|
627
|
+
s.prototype.post.call(this, o);
|
|
628
|
+
}, n;
|
|
629
|
+
})(a)
|
|
630
|
+
);
|
|
631
|
+
e.ErrorAnyEvent = c;
|
|
632
|
+
})(Q)), Q;
|
|
633
|
+
}
|
|
634
|
+
var we;
|
|
635
|
+
function He() {
|
|
636
|
+
return we || (we = 1, (function(e) {
|
|
637
|
+
var r = O && O.__createBinding || (Object.create ? (function(i, c, s, n) {
|
|
638
|
+
n === void 0 && (n = s), Object.defineProperty(i, n, { enumerable: !0, get: function() {
|
|
639
|
+
return c[s];
|
|
640
|
+
} });
|
|
641
|
+
}) : (function(i, c, s, n) {
|
|
642
|
+
n === void 0 && (n = s), i[n] = c[s];
|
|
643
|
+
})), t = O && O.__exportStar || function(i, c) {
|
|
644
|
+
for (var s in i) s !== "default" && !c.hasOwnProperty(s) && r(c, i, s);
|
|
645
|
+
};
|
|
646
|
+
Object.defineProperty(e, "__esModule", { value: !0 }), e.flush = e.flushOnce = e.queue = void 0, t(K(), e), t(N(), e), t(Ae(), e), t(Se(), e), t(Fe(), e);
|
|
647
|
+
var l = ee(), h = ee();
|
|
648
|
+
Object.defineProperty(e, "EventQueue", { enumerable: !0, get: function() {
|
|
649
|
+
return h.default;
|
|
650
|
+
} });
|
|
651
|
+
function v() {
|
|
652
|
+
return l.default.global();
|
|
653
|
+
}
|
|
654
|
+
e.queue = v;
|
|
655
|
+
function u() {
|
|
656
|
+
l.default.global().flushOnce();
|
|
657
|
+
}
|
|
658
|
+
e.flushOnce = u;
|
|
659
|
+
function a(i) {
|
|
660
|
+
i === void 0 && (i = 10), l.default.global().flush(i);
|
|
661
|
+
}
|
|
662
|
+
e.flush = a;
|
|
663
|
+
})(O)), O;
|
|
664
|
+
}
|
|
665
|
+
var w = He();
|
|
666
|
+
let be = null;
|
|
667
|
+
function Nt(e) {
|
|
668
|
+
be = e;
|
|
669
|
+
}
|
|
670
|
+
function V() {
|
|
671
|
+
return be;
|
|
672
|
+
}
|
|
673
|
+
let Z = !1, b, ne;
|
|
674
|
+
const X = /* @__PURE__ */ new Map(), re = new w.SyncEvent(), Te = new w.SyncEvent();
|
|
675
|
+
async function Xe(e) {
|
|
676
|
+
const r = V();
|
|
677
|
+
if (r) return r.connect(e);
|
|
678
|
+
try {
|
|
679
|
+
if (b = await navigator.bluetooth.requestDevice(e), b.gatt === void 0)
|
|
680
|
+
throw new Error("Device does not support GATT");
|
|
681
|
+
ne = await b.gatt.connect(), b.addEventListener("gattserverdisconnected", te), Z = !0, re.post();
|
|
682
|
+
} catch (t) {
|
|
683
|
+
throw t;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
async function Ze() {
|
|
687
|
+
const e = V();
|
|
688
|
+
if (e) return e.reconnect();
|
|
689
|
+
if (Z)
|
|
690
|
+
return;
|
|
691
|
+
const r = await navigator.bluetooth.getDevices();
|
|
692
|
+
if (r.length === 0)
|
|
693
|
+
throw new Error("No devices found");
|
|
694
|
+
if (b = r[0], b.gatt === void 0)
|
|
695
|
+
throw new Error("Device does not support GATT");
|
|
696
|
+
ne = await b.gatt.connect(), b.removeEventListener("gattserverdisconnected", te), b.addEventListener("gattserverdisconnected", te), Z = !0, re.post();
|
|
697
|
+
}
|
|
698
|
+
function te() {
|
|
699
|
+
X.clear(), Z = !1, Te.post();
|
|
700
|
+
}
|
|
701
|
+
async function se(e, r) {
|
|
702
|
+
if (X.has(r)) {
|
|
703
|
+
const h = X.get(r);
|
|
704
|
+
if (h === void 0)
|
|
705
|
+
throw new Error("Characteristic not found");
|
|
706
|
+
return h;
|
|
707
|
+
}
|
|
708
|
+
const l = await (await ne.getPrimaryService(e)).getCharacteristic(r);
|
|
709
|
+
return X.set(r, l), l;
|
|
710
|
+
}
|
|
711
|
+
async function Ke(e, r) {
|
|
712
|
+
const t = V();
|
|
713
|
+
return t ? t.readCharacteristic(e, r) : await (await se(e, r)).readValue();
|
|
714
|
+
}
|
|
715
|
+
async function Ye(e, r, t) {
|
|
716
|
+
const l = V();
|
|
717
|
+
if (l) return l.writeCharacteristic(e, r, t);
|
|
718
|
+
const h = new DataView(new ArrayBuffer(t.length));
|
|
719
|
+
for (let u = 0; u < t.length; u++)
|
|
720
|
+
h.setUint8(u, t[u]);
|
|
721
|
+
await (await se(e, r)).writeValue(h);
|
|
722
|
+
}
|
|
723
|
+
async function Ge(e, r, t) {
|
|
724
|
+
const l = V();
|
|
725
|
+
if (l) return l.subscribe(e, r, t);
|
|
726
|
+
const h = await se(e, r);
|
|
727
|
+
h.addEventListener(
|
|
728
|
+
"characteristicvaluechanged",
|
|
729
|
+
(v) => {
|
|
730
|
+
let u = v.target.value;
|
|
731
|
+
u === void 0 && (u = new DataView(new ArrayBuffer(0))), t(u);
|
|
732
|
+
}
|
|
733
|
+
), await h.startNotifications();
|
|
734
|
+
}
|
|
735
|
+
function oe() {
|
|
736
|
+
return {
|
|
737
|
+
onConnect: re,
|
|
738
|
+
onDisconnect: Te,
|
|
739
|
+
reconnect: Ze,
|
|
740
|
+
connect: Xe,
|
|
741
|
+
readCharacteristic: Ke,
|
|
742
|
+
writeCharacteristic: Ye,
|
|
743
|
+
subscribe: Ge
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
const qe = "19b10000-e8f2-537e-4f6c-d104768a1214", ze = "6b061bdc-9bc1-4952-a96f-c6ed551b2c3e", We = "6357e3bb-874c-4f35-b31e-2bcdf59d5419", Je = "998ff920-81af-42a9-a915-f88025f9647d", xe = {
|
|
747
|
+
filters: [{ namePrefix: "BLE-STANDEE" }],
|
|
748
|
+
optionalServices: [qe]
|
|
749
|
+
}, et = 10, tt = 13, nt = 20, rt = 5e3, st = 3, ot = 2e3, it = 5;
|
|
750
|
+
function Y() {
|
|
751
|
+
return {
|
|
752
|
+
serviceUuid: qe,
|
|
753
|
+
messageCharUuid: ze,
|
|
754
|
+
handshakeCharUuid: Je,
|
|
755
|
+
messageFloodCharUuid: We,
|
|
756
|
+
options: xe,
|
|
757
|
+
TTL: et,
|
|
758
|
+
PACKET_SIZE: tt,
|
|
759
|
+
BATCH_SIZE: nt,
|
|
760
|
+
ACK_TIMEOUT: rt,
|
|
761
|
+
MAX_RETRIES: st,
|
|
762
|
+
RECONNECT_DELAY: ot,
|
|
763
|
+
RECONNECT_MAX_RETRIES: it
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
class at {
|
|
767
|
+
id;
|
|
768
|
+
data;
|
|
769
|
+
constructor(r, t) {
|
|
770
|
+
this.id = r, this.data = t;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
const { serviceUuid: ut, messageCharUuid: ct } = Y(), Oe = new w.SyncEvent(), De = new w.SyncEvent(), Pe = new w.SyncEvent();
|
|
774
|
+
function lt() {
|
|
775
|
+
return new Promise((e, r) => {
|
|
776
|
+
oe().subscribe(ut, ct, ht).then(() => e()).catch((t) => r(t));
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
function ht(e) {
|
|
780
|
+
console.log(e), e !== void 0 && e.getUint8(g.TYPE) === Ve.BUTTON_PRESS && ft(e);
|
|
781
|
+
}
|
|
782
|
+
function ft(e) {
|
|
783
|
+
const r = e.getUint8(g.DATA), t = new at(
|
|
784
|
+
e.getUint8(g.ID),
|
|
785
|
+
vt(e)
|
|
786
|
+
);
|
|
787
|
+
r === x.MINUS && De.post(t), r === x.PLUS && Oe.post(t), r === x.EITHER && Pe.post(t);
|
|
788
|
+
}
|
|
789
|
+
function vt(e) {
|
|
790
|
+
const r = e.buffer, t = g.DATA + 1, l = e.byteLength - t;
|
|
791
|
+
return Array.from(new Uint8Array(r, t, l)).map((h) => String.fromCharCode(h)).join("").replace(/\0/g, "").trim();
|
|
792
|
+
}
|
|
793
|
+
function Vt() {
|
|
794
|
+
return {
|
|
795
|
+
subscribe: lt,
|
|
796
|
+
onPlusButton: Oe,
|
|
797
|
+
onMinButton: De,
|
|
798
|
+
onEitherButton: Pe
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
const { serviceUuid: dt, messageFloodCharUuid: pt } = Y(), Le = new w.SyncEvent(), Me = new w.SyncEvent(), je = new w.SyncEvent(), Ue = new w.SyncEvent();
|
|
802
|
+
function yt() {
|
|
803
|
+
return new Promise((e, r) => {
|
|
804
|
+
oe().subscribe(dt, pt, gt).then(() => e()).catch((t) => r(t));
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
function gt(e) {
|
|
808
|
+
if (console.log(e), e !== void 0 && (e.getUint8(g.TYPE) === $.NODES && Me.post(_t(e)), e.getUint8(g.TYPE) === $.LOST_NODE && je.post(e.getUint8(g.ID)), e.getUint8(g.TYPE) === $.MESSAGE_DONE && Le.post(e.getUint8(g.DATA)), e.getUint8(g.TYPE) === $.DATA_FEEDBACK)) {
|
|
809
|
+
const r = [];
|
|
810
|
+
for (let t = g.DATA; t < e.byteLength; t++)
|
|
811
|
+
r.push(e.getUint8(t));
|
|
812
|
+
console.log("received packets"), console.log(r), Ue.post(r);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
function _t(e) {
|
|
816
|
+
const r = e.getUint8(g.DATA), t = e.buffer.byteLength, l = [];
|
|
817
|
+
for (let h = g.DATA + 1; h < t; h++)
|
|
818
|
+
l.push(e.getUint8(h));
|
|
819
|
+
return /* @__PURE__ */ new Map([[r, l]]);
|
|
820
|
+
}
|
|
821
|
+
function Et() {
|
|
822
|
+
return {
|
|
823
|
+
subscribe: yt,
|
|
824
|
+
onMessageDone: Le,
|
|
825
|
+
onReceivedPackets: Ue,
|
|
826
|
+
onNode: Me,
|
|
827
|
+
onNodeLost: je
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
const k = [];
|
|
831
|
+
function wt() {
|
|
832
|
+
let e = Math.floor(Math.random() * 256);
|
|
833
|
+
for (; k.includes(e); ) e = Math.floor(Math.random() * 256);
|
|
834
|
+
return e;
|
|
835
|
+
}
|
|
836
|
+
function mt(e) {
|
|
837
|
+
k.push(e), Ct();
|
|
838
|
+
}
|
|
839
|
+
function Ct() {
|
|
840
|
+
k.length <= 20 || k.splice(0, k.length - 20);
|
|
841
|
+
}
|
|
842
|
+
function At() {
|
|
843
|
+
const e = wt();
|
|
844
|
+
return mt(e), e;
|
|
845
|
+
}
|
|
846
|
+
function St() {
|
|
847
|
+
return {
|
|
848
|
+
create: At
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
const { TTL: me, PACKET_SIZE: Ce } = Y();
|
|
852
|
+
function bt(e) {
|
|
853
|
+
if (e.data == null) {
|
|
854
|
+
let h = [e.id, e.cache, me, 0, 0, 2, 0, e.type, 0];
|
|
855
|
+
return [new Uint8Array(h)];
|
|
856
|
+
}
|
|
857
|
+
const r = new Uint8Array(2 + e.data.length), t = e.data.length + 2, l = [];
|
|
858
|
+
r.set([e.type, t], 0), r.set(e.data, 2);
|
|
859
|
+
for (let h = 0; h < t; h += Ce) {
|
|
860
|
+
const v = Math.min(Ce, t - h), u = new Uint8Array(v), a = [
|
|
861
|
+
e.id,
|
|
862
|
+
e.cache,
|
|
863
|
+
me,
|
|
864
|
+
h & 255,
|
|
865
|
+
h >> 8 & 255,
|
|
866
|
+
t & 255,
|
|
867
|
+
t >> 8 & 255
|
|
868
|
+
];
|
|
869
|
+
u.set(r.subarray(h, h + v), 0), l.push(new Uint8Array([...a, ...u]));
|
|
870
|
+
}
|
|
871
|
+
return l;
|
|
872
|
+
}
|
|
873
|
+
class $t {
|
|
874
|
+
cache = St().create();
|
|
875
|
+
type;
|
|
876
|
+
id;
|
|
877
|
+
data;
|
|
878
|
+
packets = [];
|
|
879
|
+
resolve;
|
|
880
|
+
constructor(r, t, l) {
|
|
881
|
+
this.type = r, this.id = t, this.data = l, this.packets = bt(this);
|
|
882
|
+
}
|
|
883
|
+
send() {
|
|
884
|
+
return kt().write(this);
|
|
885
|
+
}
|
|
886
|
+
then(r) {
|
|
887
|
+
return this.resolve = r, this;
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
const { serviceUuid: Tt, messageCharUuid: qt, BATCH_SIZE: Ot, ACK_TIMEOUT: Be, MAX_RETRIES: H } = Y(), { onMessageDone: Dt, onReceivedPackets: Pt } = Et(), Lt = oe(), T = [], G = /* @__PURE__ */ new Map(), I = /* @__PURE__ */ new Map(), P = /* @__PURE__ */ new Map(), q = /* @__PURE__ */ new Map();
|
|
891
|
+
let M = !1, D = 0, L = !1;
|
|
892
|
+
const Qe = new w.SyncEvent(), Re = new w.SyncEvent(), ie = new w.SyncEvent(), ke = new w.SyncEvent(), Ie = new w.SyncEvent();
|
|
893
|
+
Dt.attach(jt);
|
|
894
|
+
Pt.attach(Ut);
|
|
895
|
+
function Mt(e) {
|
|
896
|
+
return P.set(e.cache, e), e.packets.forEach((r) => T.push(r)), Re.post({
|
|
897
|
+
cacheId: e.cache,
|
|
898
|
+
type: e.type,
|
|
899
|
+
targetId: e.id,
|
|
900
|
+
packetCount: e.packets.length,
|
|
901
|
+
totalBytes: e.data?.length ?? 0,
|
|
902
|
+
timestamp: Date.now()
|
|
903
|
+
}), new Promise((r, t) => {
|
|
904
|
+
G.set(e.cache, () => {
|
|
905
|
+
e.resolve?.(), r();
|
|
906
|
+
}), I.set(e.cache, t), q.set(e.cache, { timer: 0, retries: 0 }), !M && !L && j();
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
function j() {
|
|
910
|
+
if (M || L)
|
|
911
|
+
return;
|
|
912
|
+
if (D >= Ot) {
|
|
913
|
+
L = !0;
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
916
|
+
const e = T.shift();
|
|
917
|
+
if (e == null) {
|
|
918
|
+
M = !1;
|
|
919
|
+
return;
|
|
920
|
+
}
|
|
921
|
+
const r = e[g.CACHE];
|
|
922
|
+
if (!P.has(r)) {
|
|
923
|
+
j();
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
M = !0, ae(r), Qe.post({
|
|
927
|
+
cacheId: r,
|
|
928
|
+
position: e[g.POSITION] | e[g.POSITION + 1] << 8,
|
|
929
|
+
dataSize: e[g.DATA_SIZE] | e[g.DATA_SIZE + 1] << 8,
|
|
930
|
+
packetBytes: e.length,
|
|
931
|
+
batchIndex: D,
|
|
932
|
+
timestamp: Date.now()
|
|
933
|
+
}), Lt.writeCharacteristic(Tt, qt, e).catch((t) => console.log(t)).finally(() => {
|
|
934
|
+
M = !1, D++, j();
|
|
935
|
+
});
|
|
936
|
+
}
|
|
937
|
+
function jt(e) {
|
|
938
|
+
Ie.post({
|
|
939
|
+
cacheId: e,
|
|
940
|
+
timestamp: Date.now()
|
|
941
|
+
}), G.get(e)?.(), Ne(e), L = !1, D = 0, j();
|
|
942
|
+
}
|
|
943
|
+
function Ut(e) {
|
|
944
|
+
D = 0, L = !1;
|
|
945
|
+
const r = /* @__PURE__ */ new Set();
|
|
946
|
+
for (const t of e) {
|
|
947
|
+
if (t === 0 || r.has(t)) continue;
|
|
948
|
+
r.add(t);
|
|
949
|
+
const l = P.get(t);
|
|
950
|
+
if (l == null) continue;
|
|
951
|
+
const h = q.get(t);
|
|
952
|
+
h != null && (h.retries = 0, ae(t)), ie.post({
|
|
953
|
+
cacheId: t,
|
|
954
|
+
packetCount: l.packets.length,
|
|
955
|
+
reason: "feedback",
|
|
956
|
+
timestamp: Date.now()
|
|
957
|
+
}), l.packets.forEach((v) => T.unshift(v));
|
|
958
|
+
}
|
|
959
|
+
j();
|
|
960
|
+
}
|
|
961
|
+
function ae(e) {
|
|
962
|
+
const r = q.get(e);
|
|
963
|
+
r != null && (clearTimeout(r.timer), r.timer = setTimeout(() => {
|
|
964
|
+
Qt(e);
|
|
965
|
+
}, Be));
|
|
966
|
+
}
|
|
967
|
+
function Bt(e) {
|
|
968
|
+
const r = q.get(e);
|
|
969
|
+
r != null && (clearTimeout(r.timer), q.delete(e));
|
|
970
|
+
}
|
|
971
|
+
function Qt(e) {
|
|
972
|
+
if (!P.has(e)) return;
|
|
973
|
+
const r = q.get(e);
|
|
974
|
+
if (r == null) return;
|
|
975
|
+
if (r.retries++, ke.post({
|
|
976
|
+
cacheId: e,
|
|
977
|
+
retryCount: r.retries,
|
|
978
|
+
maxRetries: H,
|
|
979
|
+
willRetry: r.retries <= H,
|
|
980
|
+
timestamp: Date.now()
|
|
981
|
+
}), r.retries > H) {
|
|
982
|
+
I.get(e)?.(new Error(
|
|
983
|
+
`Buffer ${e} timed out after ${H} retries (${Be}ms timeout)`
|
|
984
|
+
)), Ne(e);
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
const t = P.get(e);
|
|
988
|
+
t != null && (ie.post({
|
|
989
|
+
cacheId: e,
|
|
990
|
+
packetCount: t.packets.length,
|
|
991
|
+
reason: "timeout",
|
|
992
|
+
timestamp: Date.now()
|
|
993
|
+
}), t.packets.forEach((l) => T.unshift(l))), ae(e), L = !1, D = 0, j();
|
|
994
|
+
}
|
|
995
|
+
function Ne(e) {
|
|
996
|
+
G.delete(e), I.delete(e), P.delete(e), Bt(e);
|
|
997
|
+
for (let r = T.length - 1; r >= 0; r--)
|
|
998
|
+
T[r][g.CACHE] === e && T.splice(r, 1);
|
|
999
|
+
}
|
|
1000
|
+
function Rt(e) {
|
|
1001
|
+
for (const [, r] of I)
|
|
1002
|
+
r(e);
|
|
1003
|
+
G.clear(), I.clear();
|
|
1004
|
+
for (const r of q.values())
|
|
1005
|
+
clearTimeout(r.timer);
|
|
1006
|
+
q.clear(), P.clear(), T.length = 0, M = !1, D = 0, L = !1;
|
|
1007
|
+
}
|
|
1008
|
+
function kt() {
|
|
1009
|
+
return {
|
|
1010
|
+
write: Mt,
|
|
1011
|
+
abortAll: Rt,
|
|
1012
|
+
onPacketSent: Qe,
|
|
1013
|
+
onMessageQueued: Re,
|
|
1014
|
+
onRetransmit: ie,
|
|
1015
|
+
onTimeout: ke,
|
|
1016
|
+
onMessageComplete: Ie
|
|
1017
|
+
};
|
|
1018
|
+
}
|
|
1019
|
+
class Ft {
|
|
1020
|
+
id;
|
|
1021
|
+
elements = [];
|
|
1022
|
+
onPlus = new w.SyncEvent();
|
|
1023
|
+
onMin = new w.SyncEvent();
|
|
1024
|
+
neighbors = [];
|
|
1025
|
+
constructor(r) {
|
|
1026
|
+
this.id = r;
|
|
1027
|
+
}
|
|
1028
|
+
name() {
|
|
1029
|
+
return this.id.toString(16).padStart(2, "0");
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
export {
|
|
1033
|
+
$t as B,
|
|
1034
|
+
Ft as S,
|
|
1035
|
+
Y as a,
|
|
1036
|
+
Et as b,
|
|
1037
|
+
Vt as c,
|
|
1038
|
+
kt as d,
|
|
1039
|
+
at as e,
|
|
1040
|
+
w as l,
|
|
1041
|
+
Nt as s,
|
|
1042
|
+
oe as u
|
|
1043
|
+
};
|