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
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const y=require("./enums.cjs");var q={},P={},se;function N(){if(se)return P;se=1,Object.defineProperty(P,"__esModule",{value:!0}),P.BaseEvent=void 0;var t=(function(){function u(){}return u.prototype.attach=function(n,h){return this._attach(n,h,!1)},u.prototype.once=function(n,h){return this._attach(n,h,!0)},u.prototype._attach=function(n,h,f){var l=this,c,o,i,a;if(typeof n=="function")o=n,a=function(){return l.detach(o)};else if(!h&&typeof n.post=="function")i=n,a=function(){return l.detach(i)};else{if(typeof n!="object"||n===void 0)throw new Error("Expect a function or object as first argument");if(typeof h!="function")throw new Error("Expect a function as second argument");c=n,o=h,a=function(){return l.detach(c,o)}}return this._listeners?this._listeners=this._listeners.slice():this._listeners=[],this._listeners.push({deleted:!1,boundTo:c,handler:o,event:i,once:f}),a},u.prototype.detach=function(){for(var n=[],h=0;h<arguments.length;h++)n[h]=arguments[h];this._detach.apply(this,n)},u.prototype._detach=function(){for(var n=[],h=0;h<arguments.length;h++)n[h]=arguments[h];if(!(!this._listeners||this._listeners.length===0)){var f,l,c;n.length>=1&&(typeof n[0]=="function"?l=n[0]:n.length===1&&typeof n[0].post=="function"?c=n[0]:f=n[0]),n.length>=2&&(l=n[1]),this._listeners=this._listeners.filter(function(o){return(typeof l>"u"||o.handler===l)&&(typeof c>"u"||o.event===c)&&(typeof f>"u"||o.boundTo===f)?(o.deleted=!0,!1):!0}),this._listeners.length===0&&delete this._listeners}},u.prototype.post=function(n){throw new Error("abstract")},u.prototype.listenerCount=function(){return this._listeners?this._listeners.length:0},u.prototype._call=function(n,h){this._listeners&&(n.deleted||(n.once&&(n.deleted=!0,this._listeners=this._listeners.filter(function(f){return f!==n}),this._listeners.length===0&&delete this._listeners),n.event?n.event.post.apply(n.event,h):n.handler&&n.handler.apply(typeof n.boundTo=="object"?n.boundTo:this,h)))},u})();return P.BaseEvent=t,P}var C={},ie;function M(){if(ie)return C;ie=1;var t=C&&C.__extends||(function(){var l=function(c,o){return l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,a){i.__proto__=a}||function(i,a){for(var r in a)a.hasOwnProperty(r)&&(i[r]=a[r])},l(c,o)};return function(c,o){l(c,o);function i(){this.constructor=c}c.prototype=o===null?Object.create(o):(i.prototype=o.prototype,new i)}})();Object.defineProperty(C,"__esModule",{value:!0}),C.ErrorSyncEvent=C.VoidSyncEvent=C.SyncEvent=void 0;var u=N(),n=(function(l){t(c,l);function c(){var o=l!==null&&l.apply(this,arguments)||this;return o._recursion=0,o}return Object.defineProperty(c.prototype,"evtListenersChanged",{get:function(){return this._listenersChanged||(this._listenersChanged=new h),this._listenersChanged},enumerable:!1,configurable:!0}),c.prototype.post=function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];if(!(!this._listeners||this._listeners.length===0)){if(this._recursion++,typeof c.MAX_RECURSION_DEPTH=="number"&&Number.isInteger(c.MAX_RECURSION_DEPTH)&&c.MAX_RECURSION_DEPTH>0&&this._recursion>c.MAX_RECURSION_DEPTH)throw new Error("event fired recursively");for(var a=this._listeners,r=0;r<a.length;++r){var e=a[r];this._call(e,o)}this._recursion--}},c.prototype._attach=function(o,i,a){var r,e,s,v,d=(e=(r=this._listeners)===null||r===void 0?void 0:r.length)!==null&&e!==void 0?e:0,p=l.prototype._attach.call(this,o,i,a);return this.evtListenersChanged&&d!==((v=(s=this._listeners)===null||s===void 0?void 0:s.length)!==null&&v!==void 0?v:0)&&this.evtListenersChanged.post(),p},c.prototype._detach=function(){for(var o,i,a,r,e=[],s=0;s<arguments.length;s++)e[s]=arguments[s];var v=(i=(o=this._listeners)===null||o===void 0?void 0:o.length)!==null&&i!==void 0?i:0,d=l.prototype._detach.apply(this,e);return this.evtListenersChanged&&v!==((r=(a=this._listeners)===null||a===void 0?void 0:a.length)!==null&&r!==void 0?r:0)&&this.evtListenersChanged.post(),d},c.MAX_RECURSION_DEPTH=10,c})(u.BaseEvent);C.SyncEvent=n;var h=(function(l){t(c,l);function c(){return l!==null&&l.apply(this,arguments)||this}return c.prototype.post=function(){l.prototype.post.call(this,void 0)},c})(n);C.VoidSyncEvent=h;var f=(function(l){t(c,l);function c(){return l!==null&&l.apply(this,arguments)||this}return c.prototype.post=function(o){if(this.listenerCount()===0)throw new Error("error event posted while no listeners attached. Error: "+o.message);l.prototype.post.call(this,o)},c})(n);return C.ErrorSyncEvent=f,C}var A={},V={},oe;function X(){if(oe)return V;oe=1,Object.defineProperty(V,"__esModule",{value:!0});var t=M(),u=(function(){function n(){this.evtFilled=new t.SyncEvent,this.evtDrained=new t.SyncEvent,this._queue=[],this._flushing=!1}return n.global=function(){return n._instance||n.resetGlobal(),n._instance},n.resetGlobal=function(){n._instance=new n},n.prototype.empty=function(){return this._queue.length===0},n.prototype.add=function(h){this._queue.push(h),this._queue.length===1&&!this._flushing&&this.evtFilled.post(this)},n.prototype.flushOnce=function(){var h=this._queue.length===0,f=this._flushing;this._flushing=!0;try{var l=this._queue;this._queue=[];for(var c=0;c<l.length;++c)l[c]()}finally{this._flushing=f,!h&&!f&&this._queue.length===0&&this.evtDrained.post(this)}},n.prototype.flush=function(h){h===void 0&&(h=10);var f=this._queue.length===0,l=this._flushing;this._flushing=!0;try{for(var c=0;this._queue.length>0;){if(typeof h=="number"&&c>=h)throw this._queue=[],new Error("unable to flush the queue due to recursively added event. Clearing queue now");this.flushOnce(),++c}}finally{this._flushing=l,!f&&!l&&this._queue.length===0&&this.evtDrained.post(this)}},n})();return V.default=u,V}var ae;function de(){if(ae)return A;ae=1;var t=A&&A.__extends||(function(){var o=function(i,a){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,e){r.__proto__=e}||function(r,e){for(var s in e)e.hasOwnProperty(s)&&(r[s]=e[s])},o(i,a)};return function(i,a){o(i,a);function r(){this.constructor=i}i.prototype=a===null?Object.create(a):(r.prototype=a.prototype,new r)}})();Object.defineProperty(A,"__esModule",{value:!0}),A.ErrorQueuedEvent=A.VoidQueuedEvent=A.QueuedEvent=void 0;var u=N(),n=X(),h=M(),f=(function(o){t(i,o);function i(a){a===void 0&&(a={});var r=o.call(this)||this;return r._queued=!1,r.options=a,typeof a.condensed=="boolean"?r._condensed=a.condensed:r._condensed=!1,typeof a.queue=="object"&&a.queue!==null&&(r._queue=a.queue),r}return Object.defineProperty(i.prototype,"evtListenersChanged",{get:function(){return this._listenersChanged||(this._listenersChanged=new h.VoidSyncEvent),this._listenersChanged},enumerable:!1,configurable:!0}),i.prototype.post=function(){for(var a=this,r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];if(!(!this._listeners||this._listeners.length===0)){var s=this._queue?this._queue:n.default.global();if(this._condensed){if(this._queuedData=r,this._queuedListeners=this._listeners,this._queued)return;this._queued=!0,s.add(function(){a._queued=!1;for(var d=a._queuedData,p=a._queuedListeners,g=0;g<p.length;++g){var _=p[g];a._call(_,d)}})}else{var v=this._listeners;s.add(function(){for(var d=0;d<v.length;++d){var p=v[d];a._call(p,r)}})}}},i.prototype._attach=function(a,r,e){var s,v,d,p,g=(v=(s=this._listeners)===null||s===void 0?void 0:s.length)!==null&&v!==void 0?v:0,_=o.prototype._attach.call(this,a,r,e);return this.evtListenersChanged&&g!==((p=(d=this._listeners)===null||d===void 0?void 0:d.length)!==null&&p!==void 0?p:0)&&this.evtListenersChanged.post(),_},i.prototype._detach=function(){for(var a,r,e,s,v=[],d=0;d<arguments.length;d++)v[d]=arguments[d];var p=(r=(a=this._listeners)===null||a===void 0?void 0:a.length)!==null&&r!==void 0?r:0,g=o.prototype._detach.apply(this,v);return this.evtListenersChanged&&p!==((s=(e=this._listeners)===null||e===void 0?void 0:e.length)!==null&&s!==void 0?s:0)&&this.evtListenersChanged.post(),g},i})(u.BaseEvent);A.QueuedEvent=f;var l=(function(o){t(i,o);function i(){return o!==null&&o.apply(this,arguments)||this}return i.prototype.post=function(){o.prototype.post.call(this,void 0)},i})(f);A.VoidQueuedEvent=l;var c=(function(o){t(i,o);function i(){return o!==null&&o.apply(this,arguments)||this}return i.prototype.post=function(a){if(!this._listeners||this._listeners.length===0)throw new Error("error event posted while no listeners attached. Error: "+a.message);o.prototype.post.call(this,a)},i})(f);return A.ErrorQueuedEvent=c,A}var b={},ue;function pe(){if(ue)return b;ue=1;var t=b&&b.__extends||(function(){var c=function(o,i){return c=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(a,r){a.__proto__=r}||function(a,r){for(var e in r)r.hasOwnProperty(e)&&(a[e]=r[e])},c(o,i)};return function(o,i){c(o,i);function a(){this.constructor=o}o.prototype=i===null?Object.create(i):(a.prototype=i.prototype,new a)}})();Object.defineProperty(b,"__esModule",{value:!0}),b.ErrorAsyncEvent=b.VoidAsyncEvent=b.AsyncEvent=void 0;var u=N(),n=M(),h=(function(c){t(o,c);function o(i){i===void 0&&(i={});var a=c.call(this)||this;return a._queued=!1,a.options=i,typeof i.condensed=="boolean"?a._condensed=i.condensed:a._condensed=!1,a}return Object.defineProperty(o.prototype,"evtListenersChanged",{get:function(){return this._listenersChanged||(this._listenersChanged=new n.VoidSyncEvent),this._listenersChanged},enumerable:!1,configurable:!0}),o.defaultScheduler=function(i){typeof window<"u"?setTimeout(i,0):setImmediate(i)},o.setScheduler=function(i){o._scheduler=i},o.prototype.post=function(){for(var i=this,a=[],r=0;r<arguments.length;r++)a[r]=arguments[r];if(!(!this._listeners||this._listeners.length===0))if(this._condensed){if(this._queuedData=a,this._queuedListeners=this._listeners,this._queued)return;this._queued=!0,o._scheduler(function(){i._queued=!1;for(var s=i._queuedData,v=i._queuedListeners,d=0;d<v.length;++d){var p=v[d];i._call(p,s)}})}else{var e=this._listeners;o._scheduler(function(){for(var s=0;s<e.length;++s){var v=e[s];i._call(v,a)}})}},o.prototype._call=function(i,a){i.event&&i.event instanceof o?i.event._postDirect(a):c.prototype._call.call(this,i,a)},o.prototype._postDirect=function(i){if(!(!this._listeners||this._listeners.length===0))for(var a=this._listeners,r=0;r<a.length;++r){var e=a[r];this._call(e,i)}},o.prototype._attach=function(i,a,r){var e,s,v,d,p=(s=(e=this._listeners)===null||e===void 0?void 0:e.length)!==null&&s!==void 0?s:0,g=c.prototype._attach.call(this,i,a,r);return this.evtListenersChanged&&p!==((d=(v=this._listeners)===null||v===void 0?void 0:v.length)!==null&&d!==void 0?d:0)&&this.evtListenersChanged.post(),g},o.prototype._detach=function(){for(var i,a,r,e,s=[],v=0;v<arguments.length;v++)s[v]=arguments[v];var d=(a=(i=this._listeners)===null||i===void 0?void 0:i.length)!==null&&a!==void 0?a:0,p=c.prototype._detach.apply(this,s);return this.evtListenersChanged&&d!==((e=(r=this._listeners)===null||r===void 0?void 0:r.length)!==null&&e!==void 0?e:0)&&this.evtListenersChanged.post(),p},o._scheduler=o.defaultScheduler,o})(u.BaseEvent);b.AsyncEvent=h;var f=(function(c){t(o,c);function o(){return c!==null&&c.apply(this,arguments)||this}return o.prototype.post=function(){c.prototype.post.call(this,void 0)},o})(h);b.VoidAsyncEvent=f;var l=(function(c){t(o,c);function o(){return c!==null&&c.apply(this,arguments)||this}return o.prototype.post=function(i){if(this.listenerCount()===0)throw new Error("error event posted while no listeners attached. Error: "+i.message);c.prototype.post.call(this,i)},o})(h);return b.ErrorAsyncEvent=l,b}var O={},T={},ce;function Pe(){if(ce)return T;ce=1,Object.defineProperty(T,"__esModule",{value:!0}),T.shallowEquals=void 0;function t(u,n){if(u===n)return!0;if(typeof u!=typeof n)return!1;switch(typeof u){case"boolean":case"number":case"string":case"function":case"symbol":case"undefined":return!1;case"object":if(u===null||n===null)return!1;if(Array.isArray(u)||Array.isArray(n)){if(!Array.isArray(u)||!Array.isArray(n)||u.length!==n.length)return!1;for(var h=0;h<u.length;++h)if(u[h]!==n[h])return!1;return!0}var f=[],l=[];for(var c in u)u.hasOwnProperty(c)&&f.push(c);for(var o in n)n.hasOwnProperty(o)&&l.push(o);if(f.sort(),l.sort(),f.join(",")!==l.join(","))return!1;for(var h=0;h<f.length;++h)if(u[f[h]]!==n[f[h]])return!1;return!0;default:return!1}}return T.shallowEquals=t,T}var he;function Oe(){return he||(he=1,(function(t){var u=O&&O.__extends||(function(){var r=function(e,s){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(v,d){v.__proto__=d}||function(v,d){for(var p in d)d.hasOwnProperty(p)&&(v[p]=d[p])},r(e,s)};return function(e,s){r(e,s);function v(){this.constructor=e}e.prototype=s===null?Object.create(s):(v.prototype=s.prototype,new v)}})();Object.defineProperty(t,"__esModule",{value:!0}),t.ErrorAnyEvent=t.VoidAnyEvent=t.AnyEvent=t.EventType=void 0;var n=Pe(),h=M(),f=pe(),l=de(),c;(function(r){r[r.Sync=0]="Sync",r[r.Async=1]="Async",r[r.Queued=2]="Queued"})(c=t.EventType||(t.EventType={}));var o=(function(){function r(e){this._events=[],e&&e.monitorAttach&&(this.evtFirstAttached=new i,this.evtLastDetached=new i)}return Object.defineProperty(r.prototype,"evtListenersChanged",{get:function(){return this._listenersChanged||(this._listenersChanged=new h.VoidSyncEvent),this._listenersChanged},enumerable:!1,configurable:!0}),r.prototype.attach=function(){for(var e=[],s=0;s<arguments.length;s++)e[s]=arguments[s];var v=c.Sync;e.length>0&&typeof e[0]=="number"&&(v=e.shift());var d=this,p,g,_;return typeof e[0]=="function"||e[0]&&typeof e[0]=="object"&&typeof e[0].post=="function"?(typeof e[0]=="function"?p=e[0]:_=e[0],g=e[1]):(d=e[0],p=e[1],g=e[2]),this._attach(v,d,p,_,g,!1)},r.prototype.once=function(){for(var e=[],s=0;s<arguments.length;s++)e[s]=arguments[s];var v=c.Sync;e.length>0&&typeof e[0]=="number"&&(v=e.shift());var d=this,p,g,_;return typeof e[0]=="function"||e[0]&&typeof e[0]=="object"&&typeof e[0].post=="function"?(typeof e[0]=="function"?p=e[0]:_=e[0],g=e[1]):(d=e[0],p=e[1],g=e[2]),this._attach(v,d,p,_,g,!0)},r.prototype._attach=function(e,s,v,d,p,g){var _=this,x=this.evtFirstAttached?this.listenerCount():0,E;switch(e){case c.Sync:{for(var H=0,ee=this._events;H<ee.length;H++){var m=ee[H];m instanceof h.SyncEvent&&(E=m)}E||(E=new h.SyncEvent,this._events.push(E))}break;case c.Async:{for(var Z=0,te=this._events;Z<te.length;Z++){var m=te[Z];m instanceof f.AsyncEvent&&n.shallowEquals(m.options,p)&&(E=m)}E||(E=new f.AsyncEvent(p),this._events.push(E))}break;case c.Queued:{for(var G=0,ne=this._events;G<ne.length;G++){var m=ne[G];m instanceof l.QueuedEvent&&n.shallowEquals(m.options,p)&&(E=m)}E||(E=new l.QueuedEvent(p),this._events.push(E))}break;default:throw new Error("unknown EventType")}var D;return g?d?D=E.once(d):D=E.once(s,v):d?D=E.attach(d):D=E.attach(s,v),this.evtFirstAttached&&x===0&&this.evtFirstAttached.post(),this.evtListenersChanged&&x!==this.listenerCount()&&this.evtListenersChanged.post(),function(){var re=_.evtLastDetached?_.listenerCount():0;D(),_.evtLastDetached&&re>0&&_.listenerCount()===0&&_.evtLastDetached.post(),_.evtListenersChanged&&re!==_.listenerCount()&&_.evtListenersChanged.post()}},r.prototype.attachSync=function(){for(var e=[],s=0;s<arguments.length;s++)e[s]=arguments[s];return e.unshift(c.Sync),this.attach.apply(this,e)},r.prototype.onceSync=function(){for(var e=[],s=0;s<arguments.length;s++)e[s]=arguments[s];return e.unshift(c.Sync),this.once.apply(this,e)},r.prototype.attachAsync=function(){for(var e=[],s=0;s<arguments.length;s++)e[s]=arguments[s];return e.unshift(c.Async),this.attach.apply(this,e)},r.prototype.onceAsync=function(){for(var e=[],s=0;s<arguments.length;s++)e[s]=arguments[s];return e.unshift(c.Async),this.once.apply(this,e)},r.prototype.attachQueued=function(){for(var e=[],s=0;s<arguments.length;s++)e[s]=arguments[s];return e.unshift(c.Queued),this.attach.apply(this,e)},r.prototype.onceQueued=function(){for(var e=[],s=0;s<arguments.length;s++)e[s]=arguments[s];return e.unshift(c.Queued),this.once.apply(this,e)},r.prototype.detach=function(){for(var e=[],s=0;s<arguments.length;s++)e[s]=arguments[s];for(var v=this.listenerCount(),d=0;d<this._events.length;++d)this._events[d].detach.apply(this._events[d],e);this.evtListenersChanged&&v!==this.listenerCount()&&this.evtListenersChanged.post(),this.evtLastDetached&&v>0&&this.listenerCount()===0&&this.evtLastDetached.post()},r.prototype.post=function(e){for(var s=[],v=0;v<this._events.length;++v)s.push(this._events[v]);for(var v=0;v<s.length;++v)s[v].post(e)},r.prototype.listenerCount=function(){for(var e=0,s=0;s<this._events.length;++s)e+=this._events[s].listenerCount();return e},r})();t.AnyEvent=o;var i=(function(r){u(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e.prototype.post=function(){r.prototype.post.call(this,void 0)},e})(o);t.VoidAnyEvent=i;var a=(function(r){u(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e.prototype.post=function(s){if(this.listenerCount()===0)throw new Error("error event posted while no listeners attached. Error: "+s.message);r.prototype.post.call(this,s)},e})(o);t.ErrorAnyEvent=a})(O)),O}var le;function Te(){return le||(le=1,(function(t){var u=q&&q.__createBinding||(Object.create?(function(i,a,r,e){e===void 0&&(e=r),Object.defineProperty(i,e,{enumerable:!0,get:function(){return a[r]}})}):(function(i,a,r,e){e===void 0&&(e=r),i[e]=a[r]})),n=q&&q.__exportStar||function(i,a){for(var r in i)r!=="default"&&!a.hasOwnProperty(r)&&u(a,i,r)};Object.defineProperty(t,"__esModule",{value:!0}),t.flush=t.flushOnce=t.queue=void 0,n(N(),t),n(M(),t),n(de(),t),n(pe(),t),n(Oe(),t);var h=X(),f=X();Object.defineProperty(t,"EventQueue",{enumerable:!0,get:function(){return f.default}});function l(){return h.default.global()}t.queue=l;function c(){h.default.global().flushOnce()}t.flushOnce=c;function o(i){i===void 0&&(i=10),h.default.global().flush(i)}t.flush=o})(q)),q}var w=Te();let R=!1,S,K;const I=new Map,z=new w.SyncEvent,ye=new w.SyncEvent;async function Le(t){try{if(S=await navigator.bluetooth.requestDevice(t),S.gatt===void 0)throw new Error("Device does not support GATT");K=await S.gatt.connect(),S.addEventListener("gattserverdisconnected",ge),R=!0,z.post()}catch(u){throw u}}async function Ue(){if(R)return;const t=await navigator.bluetooth.getDevices();if(t.length===0)throw new Error("No devices found");if(S=t[0],S.gatt===void 0)throw new Error("Device does not support GATT");K=await S.gatt.connect(),S.addEventListener("gattserverdisconnected",ge),R=!0,z.post()}function ge(){I.clear(),R=!1,ye.post()}async function W(t,u){if(I.has(u)){const f=I.get(u);if(f===void 0)throw new Error("Characteristic not found");return f}const h=await(await K.getPrimaryService(t)).getCharacteristic(u);return I.set(u,h),h}async function je(t,u){return await(await W(t,u)).readValue()}async function Be(t,u,n){const h=new DataView(new ArrayBuffer(n.length));for(let l=0;l<n.length;l++)h.setUint8(l,n[l]);await(await W(t,u)).writeValue(h)}async function Me(t,u,n){const h=await W(t,u);h.addEventListener("characteristicvaluechanged",f=>{let l=f.target.value;l===void 0&&(l=new DataView(new ArrayBuffer(0))),n(l)}),await h.startNotifications()}function k(){return{onConnect:z,onDisconnect:ye,reconnect:Ue,connect:Le,readCharacteristic:je,writeCharacteristic:Be,subscribe:Me}}const _e="19b10000-e8f2-537e-4f6c-d104768a1214",Qe="6b061bdc-9bc1-4952-a96f-c6ed551b2c3e",Ve="6357e3bb-874c-4f35-b31e-2bcdf59d5419",Ie="998ff920-81af-42a9-a915-f88025f9647d",Re={filters:[{namePrefix:"BLE-STANDEE"}],optionalServices:[_e]},Fe=10,Ne=13,ke=20;function Q(){return{serviceUuid:_e,messageCharUuid:Qe,handshakeCharUuid:Ie,messageFloodCharUuid:Ve,options:Re,TTL:Fe,PACKET_SIZE:Ne,BATCH_SIZE:ke}}class Ee{id;data;constructor(u,n){this.id=u,this.data=n}}const{serviceUuid:$e,messageCharUuid:He}=Q(),we=new w.SyncEvent,Ce=new w.SyncEvent,Ae=new w.SyncEvent;function Ze(){return new Promise((t,u)=>{k().subscribe($e,He,Ge).then(()=>t()).catch(n=>u(n))})}function Ge(t){console.log(t),t!==void 0&&t.getUint8(y.Data.TYPE)===y.DataType.BUTTON_PRESS&&Xe(t)}function Xe(t){const u=t.getUint8(y.Data.DATA),n=new Ee(t.getUint8(y.Data.ID),Ye(t));u===y.Button.MINUS&&Ce.post(n),u===y.Button.PLUS&&we.post(n),u===y.Button.EITHER&&Ae.post(n)}function Ye(t){const u=t.buffer,n=y.Data.DATA+1,h=t.byteLength-n;return Array.from(new Uint8Array(u,n,h)).map(f=>String.fromCharCode(f)).join("").replace(/\0/g,"").trim()}function Ke(){return{subscribe:Ze,onPlusButton:we,onMinButton:Ce,onEitherButton:Ae}}const{serviceUuid:ze,messageFloodCharUuid:We}=Q(),be=new w.SyncEvent,me=new w.SyncEvent,Se=new w.SyncEvent,qe=new w.SyncEvent;function Je(){return new Promise((t,u)=>{k().subscribe(ze,We,xe).then(()=>t()).catch(n=>u(n))})}function xe(t){if(console.log(t),t!==void 0&&(t.getUint8(y.Data.TYPE)===y.FloodTypes.NODES&&me.post(et(t)),t.getUint8(y.Data.TYPE)===y.FloodTypes.LOST_NODE&&Se.post(t.getUint8(y.Data.ID)),t.getUint8(y.Data.TYPE)===y.FloodTypes.MESSAGE_DONE&&be.post(t.getUint8(y.Data.DATA)),t.getUint8(y.Data.TYPE)===y.FloodTypes.DATA_FEEDBACK)){const u=[];for(let n=y.Data.DATA;n<t.byteLength;n++)u.push(t.getUint8(n));console.log("received packets"),console.log(u),qe.post(u)}}function et(t){const u=t.getUint8(y.Data.DATA),n=t.buffer.byteLength,h=[];for(let f=y.Data.DATA+1;f<n;f++)h.push(t.getUint8(f));return new Map([[u,h]])}function De(){return{subscribe:Je,onMessageDone:be,onReceivedPackets:qe,onNode:me,onNodeLost:Se}}const U=[];function tt(){let t=Math.floor(Math.random()*256);for(;U.includes(t);)t=Math.floor(Math.random()*256);return t}function nt(t){U.push(t),rt()}function rt(){U.length<=20||U.splice(0,U.length-20)}function st(){const t=tt();return nt(t),t}function it(){return{create:st}}const{serviceUuid:ot,messageCharUuid:at,BATCH_SIZE:ut}=Q(),{onMessageDone:ct,onReceivedPackets:ht}=De(),lt=k(),J=[],Y=new Map,$=new Map;let L=!1,F=0,j=!1;ct.attach(vt);ht.attach(dt);function ft(t){return $.set(t.cache,t),t.packets.forEach(u=>J.push(u)),new Promise(u=>{Y.set(t.cache,()=>{t.resolve?.(),u()}),!L&&!j&&B()})}function B(){if(L||j)return;if(F>=ut){j=!0;return}const t=J.shift();if(t==null){L=!1;return}const u=t[y.Data.CACHE];if(!$.has(u)){B();return}L=!0,lt.writeCharacteristic(ot,at,t).catch(n=>console.log(n)).finally(()=>{L=!1,F++,B()})}function vt(t){Y.get(t)?.(),Y.delete(t),$.delete(t),j=!1,F=0,B()}function dt(t){F=0,j=!1;const u=new Set;for(const n of t){if(n===0||u.has(n))continue;u.add(n);const h=$.get(n);h?.packets.forEach(f=>J.unshift(f))}B()}function pt(){return{write:ft}}const{TTL:fe,PACKET_SIZE:ve}=Q();function yt(t){if(t.data==null){let f=[t.id,t.cache,fe,0,0,2,0,t.type,0];return[new Uint8Array(f)]}const u=new Uint8Array(2+t.data.length),n=t.data.length+2,h=[];u.set([t.type,n],0),u.set(t.data,2);for(let f=0;f<n;f+=ve){const l=Math.min(ve,n-f),c=new Uint8Array(l),o=[t.id,t.cache,fe,f&255,f>>8&255,n&255,n>>8&255];c.set(u.subarray(f,f+l),0),h.push(new Uint8Array([...o,...c]))}return h}class gt{cache=it().create();type;id;data;packets=[];resolve;constructor(u,n,h){this.type=u,this.id=n,this.data=h,this.packets=yt(this)}send(){return pt().write(this)}then(u){return this.resolve=u,this}}class _t{id;elements=[];onPlus=new w.SyncEvent;onMin=new w.SyncEvent;neighbors=[];constructor(u){this.id=u}name(){return this.id.toString(16).padStart(2,"0")}}exports.Buffer=gt;exports.ButtonResult=Ee;exports.Standee=_t;exports.libExports=w;exports.useBluetooth=k;exports.useBluetoothSettings=Q;exports.useFloodCharacteristic=De;exports.useMessageCharacteristic=Ke;
|
package/readme.md
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# NotSoDoom standees bluetooth
|
|
2
|
-
|
|
3
|
-
This package is needed to communicate with the bluetooth standees. You can send to it what you want to be displayed on the screen. You can also give instructions on what the buttons need to do as well as upload graphics to them to be displayed. The standees communicate through a mesh they create on their own. You inly have to connect to one standee to be part of the mesh.
|
|
4
|
-
|
|
5
|
-
## Mesh
|
|
6
|
-
|
|
7
|
-
The mesh lets you read and write to the standees.
|
|
8
|
-
|
|
9
|
-
#### `useMesh()`
|
|
10
|
-
|
|
11
|
-
- `connect()` is the method to call when you want to search for a bluetooth device through the browser. This needs to be on a user action like a click.
|
|
12
|
-
- `onConnected` is a `SyncEvent<DataView<ArrayBufferLike>>` event that you can attach your method to. This will be called when the mesh is connected.
|
|
13
|
-
|
|
14
|
-
```javascript
|
|
15
|
-
let connected = false;
|
|
16
|
-
const mesh = useMesh();
|
|
17
|
-
|
|
18
|
-
mesh.onConnected.attach(() => (connected = true));
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
- `onDisconnected` is a `SyncEvent<DataView<ArrayBufferLike>>` event that you can attach your method to. This will be called when the mesh is connected.
|
|
22
|
-
|
|
23
|
-
```javascript
|
|
24
|
-
let connected = false;
|
|
25
|
-
const mesh = useMesh();
|
|
26
|
-
|
|
27
|
-
mesh.onDisconnected.attach(() => (connected = false));
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
for more information on the events package check out https://github.com/rogierschouten/ts-events.
|