Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bleat

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bleat - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

4

dist/adapter-template.js

@@ -45,2 +45,5 @@ /* @license

// Guard against bleat being navigator.bluetooth
if (!bleat._addAdapter) return;
bleat._addAdapter("<template-name>", {

@@ -151,4 +154,3 @@

) {}
});
}));

@@ -48,2 +48,5 @@ /* @license

// Guard against bleat being navigator.bluetooth
if (!bleat._addAdapter) return;
// Object that holds Bleat adapter functions.

@@ -50,0 +53,0 @@ var adapter = {};

@@ -45,2 +45,5 @@ /* @license

// Guard against bleat being navigator.bluetooth
if (!bleat._addAdapter) return;
function checkForError(errorFn, continueFn) {

@@ -47,0 +50,0 @@ return function(error) {

@@ -75,22 +75,21 @@ /* @license

var events = {};
function createListenerFn(eventTypes) {
return function(type, callback, capture) {
if (eventTypes.indexOf(type) < 0) return; //error
if (!events[this]) events[this] = {};
if (!events[this][type]) events[this][type] = [];
events[this][type].push(callback);
if (!this.__events) this.__events = {};
if (!this.__events[type]) this.__events[type] = [];
this.__events[type].push(callback);
};
}
function removeEventListener(type, callback, capture) {
if (!events[this] || !events[this][type]) return; //error
var i = events[this][type].indexOf(callback);
if (i >= 0) events[this][type].splice(i, 1);
if (events[this][type].length === 0) delete events[this][type];
if (Object.keys(events[this]).length === 0) delete events[this];
if (!this.__events || !this.__events[type]) return; //error
var i = this.__events[type].indexOf(callback);
if (i >= 0) this.__events[type].splice(i, 1);
if (this.__events[type].length === 0) delete this.__events[type];
if (Object.keys(this.__events).length === 0) delete this.__events;
}
function dispatchEvent(event) {
if (!events[this] || !events[this][event.type]) return; //error
if (!this.__events || !this.__events[event.type]) return; //error
event.target = this;
events[this][event.type].forEach(function(callback) {
this.__events[event.type].forEach(function(callback) {
if (typeof callback === "function") callback(event);

@@ -503,3 +502,5 @@ });

this.dispatchEvent({ type: "characteristicvaluechanged", bubbles: true });
}.bind(this), resolve, wrapReject(reject, "startNotifications error"));
}.bind(this), function() {
resolve(this);
}.bind(this), wrapReject(reject, "startNotifications error"));
}.bind(this));

@@ -511,3 +512,5 @@ };

adapter.disableNotify(this._handle, resolve, wrapReject(reject, "stopNotifications error"));
adapter.disableNotify(this._handle, function() {
resolve(this);
}.bind(this), wrapReject(reject, "stopNotifications error"));
}.bind(this));

@@ -563,2 +566,2 @@ };

};
}));
}));

@@ -53,2 +53,2 @@ /* @license

*/
function(a,b){"function"==typeof define&&define.amd?define(["bluetooth.helpers"],b):"object"==typeof exports?module.exports=b(require("./bluetooth.helpers")):a.bleat=b(a.bleatHelpers)}(this,function(a){"use strict";function b(a,b){return function(c){a&&a(b+": "+c)}}function c(a){return function(){if("function"==typeof a){var b=[].slice.call(arguments);a.apply(this,b)}}}function d(a,b){var c=0,d=!1;this.addCallback=function(b){return c++,d=!0,function(){b&&b.apply(null,arguments),0==--c&&a&&a()}},this.error=function(){b&&b.apply(null,arguments),0==--c&&a&&a()},this.finish=function(){!d&&a&&a()}}var e=null,f={},g=function(a){this._handle=a._handle,this.address=a._handle,this.name=a.name,this.serviceUUIDs=a.uuids,this.adData=a.adData,this.connected=!1,this.services={}};g.prototype.hasService=function(a){return this.serviceUUIDs.some(function(b){return b===a})},g.prototype.connect=function(a,d,f,g){e.connect(this._handle,function(){if(this.connected=!0,"boolean"==typeof f&&(g=f,f=null),g)return c(a)();this.discoverAll(a,f)}.bind(this),function(){this.connected=!1,this.services={},c(d)()}.bind(this),b(f,"connect error"))},g.prototype.disconnect=function(a){e.disconnect(this._handle,b(a,"disconnect error"))},g.prototype.discoverServices=function(a,c,d){if(!1===this.connected)return b(d,"discovery error")("device not connected");"function"==typeof a?(c=a,a=[]):"string"==typeof a&&(a=[a]),e.discoverServices(this._handle,a,function(a){a.forEach(function(a){this.services[a.uuid]=new h(a)},this),c&&c()}.bind(this),b(d,"service discovery error"))},g.prototype.discoverAll=function(a,c){if(!1===this.connected)return b(c,"discovery error")("device not connected");var e=new d(a,c);this.discoverServices(e.addCallback(function(){Object.keys(this.services).forEach(function(a){var b=this.services[a];b.discoverIncludedServices(e.addCallback(),e.error),b.discoverCharacteristics(e.addCallback(function(){Object.keys(b.characteristics).forEach(function(a){b.characteristics[a].discoverDescriptors(e.addCallback(),e.error)},this)}.bind(this)),e.error)},this)}.bind(this)),e.error),e.finish()};var h=function(a){this._handle=a._handle,this.uuid=a.uuid,this.primary=a.primary,this.includedServices={},this.characteristics={}};h.prototype.discoverIncludedServices=function(a,c,d){"function"==typeof a?(c=a,a=[]):"string"==typeof a&&(a=[a]),e.discoverIncludedServices(this._handle,a,function(a){a.forEach(function(a){this.includedServices[a.uuid]=new h(a)},this),c&&c()}.bind(this),b(d,"included service discovery error"))},h.prototype.discoverCharacteristics=function(a,c,d){"function"==typeof a?(c=a,a=[]):"string"==typeof a&&(a=[a]),e.discoverCharacteristics(this._handle,a,function(a){a.forEach(function(a){this.characteristics[a.uuid]=new i(a)},this),c&&c()}.bind(this),b(d,"characteristic discovery error"))};var i=function(a){this._handle=a._handle,this.uuid=a.uuid,this.properties=a.properties,this.descriptors={}};i.prototype.discoverDescriptors=function(a,c,d){"function"==typeof a?(c=a,a=[]):"string"==typeof a&&(a=[a]),e.discoverDescriptors(this._handle,a,function(a){a.forEach(function(a){this.descriptors[a.uuid]=new j(a)},this),c&&c()}.bind(this),b(d,"descriptor discovery error"))},i.prototype.read=function(a,d){e.readCharacteristic(this._handle,c(a),b(d,"read characteristic error"))},i.prototype.write=function(a,d,f){e.writeCharacteristic(this._handle,a,c(d),b(f,"write characteristic error"))},i.prototype.enableNotify=function(a,d,f){e.enableNotify(this._handle,c(a),c(d),b(f,"enable notify error"))},i.prototype.disableNotify=function(a,d){e.disableNotify(this._handle,c(a),b(d,"disable notify error"))};var j=function(a){this._handle=a._handle,this.uuid=a.uuid};return j.prototype.read=function(a,d){e.readDescriptor(this._handle,c(a),b(d,"read descriptor error"))},j.prototype.write=function(a,d,f){e.writeDescriptor(this._handle,a,c(d),b(f,"write descriptor error"))},{_addAdapter:function(a,b){f[a]=b,e=b},startScan:function(a,c,d,f,h){"function"==typeof a?(h=f,f=d,d=c,c=a,a=[]):"string"==typeof a&&(a=[a]),e.stopScan(b(f,"stop scan error"));var i={};e.startScan(a,function(a){var b=new g(a);i[b.address]&&!h||(i[b.address]=b,c&&c(b))}.bind(this),d,b(f,"scan error"))},stopScan:function(a){e.stopScan(b(a,"stop scan error"))}}}),function(a,b){"function"==typeof define&&define.amd?define(["bleat","bluetooth.helpers"],b.bind(this,a)):"object"==typeof exports?module.exports=function(c){return b(a,c,require("./bluetooth.helpers"))}:b(a,a.bleat,a.bleatHelpers)}(this,function(a,b,c){"use strict";function d(b){a.evothings&&evothings.ble?b():document.addEventListener("deviceready",b)}function e(a){var b=x[a];b&&(evothings.ble.close(b),delete x[a],f(b,y),f(b,z,!0),f(b,A))}function f(a,b,c){for(var d in b)a===b[d]&&(delete b[d],c&&B[d]&&delete B[d])}function g(a,b){var c=x[a];return c||(b&&b("Device does not exist for device id: "+a),null)}function h(a,b){var c=y[a];return c||(b&&b("Device does not exist for service handle: "+a),null)}function i(a,b){var c=z[a];return c||(b&&b("Device does not exist for characteristic handle: "+a),null)}function j(a,b,c,d){function e(b){evothings.ble.writeDescriptor(a,b,new Uint8Array([1,0]),function(){c()},function(a){d(a)})}function f(){w.discoverDescriptors(b,"00002902-0000-1000-8000-00805f9b34fb",function(a){var c=B[b];c?e(c):d("Could not find CCCD for characteristic: "+b)},function(a){d(a)})}var g=B[b];g?e(g):f()}function k(a){var b={};return b._handle=a.address,b.id=a.address,b.name=a.name,b.uuids=[],b.adData={},b.adData.rssi=a.rssi,b.adData.txPower=null,b.adData.serviceData={},b.adData.manufacturerData=null,a.advertisementData?l(a,b):a.scanRecord&&m(a,b),b}function l(a,b){if(a.advertisementData){if(a.advertisementData.kCBAdvDataLocalName&&(b.name=a.advertisementData.kCBAdvDataLocalName),a.advertisementData.kCBAdvDataTxPowerLevel&&(b.adData.txPower=a.advertisementData.kCBAdvDataTxPowerLevel),a.advertisementData.kCBAdvDataServiceUUIDs&&a.advertisementData.kCBAdvDataServiceUUIDs.forEach(function(a){b.uuids.push(c.getCanonicalUUID(a))}),a.advertisementData.kCBAdvDataServiceData)for(var d in a.advertisementData.kCBAdvDataServiceData){var e=a.advertisementData.kCBAdvDataServiceData[d];b.adData.serviceData[c.getCanonicalUUID(d)]=t(o(e))}a.advertisementData.kCBAdvDataManufacturerData&&(b.adData.manufacturerDataRaw=a.advertisementData.kCBAdvDataManufacturerData)}}function m(a,b){for(var d=o(a.scanRecord),e=0;e<d.length;){var f=d[e++];if(0===f)break;f-=1;var g,h=d[e++];if(8===h||9===h)b.name=evothings.ble.fromUtf8(new Uint8Array(d.buffer,e,f)).replace("\0","");else if(10===h)b.adData.txPower=p(d,e);else if(2===h||3===h)for(g=0;g<f;g+=2)b.uuids.push(c.getCanonicalUUID(q(d,e+g).toString(16)));else if(4===h||5===h)for(g=0;g<f;g+=4)b.uuids.push(c.getCanonicalUUID(r(d,e+g).toString(16)));else if(6===h||7===h)for(g=0;g<f;g+=16)b.uuids.push(c.getCanonicalUUID(s(d,e+g)));e+=f}}function n(a){return a>64&&a<91?a-65:a>96&&a<123?a-71:a>47&&a<58?a+4:43===a?62:47===a?63:0}function o(a,b){for(var c,d,e=a.replace(/[^A-Za-z0-9\+\/]/g,""),f=e.length,g=b?Math.ceil((3*f+1>>2)/b)*b:3*f+1>>2,h=new Uint8Array(g),i=0,j=0,k=0;k<f;k++)if(d=3&k,i|=n(e.charCodeAt(k))<<18-6*d,3===d||f-k==1){for(c=0;c<3&&j<g;c++,j++)h[j]=i>>>(16>>>c&24)&255;i=0}return h}function p(a,b){var c=a[b];return 128&c&&(c-=256),c}function q(a,b){return(a[b+1]<<8)+a[b]}function r(a,b){return(a[b+3]<<24)+(a[b+2]<<16)+(a[b+1]<<8)+a[b]}function s(a,b){for(var c="",d=0;d<16;d++)c+=("00"+a[b+d].toString(16)).slice(-2);return c}function t(a){var b=new Uint8Array(a).buffer;return new DataView(b)}function u(){return a.cordova?a.cordova.platformId:null}function v(){return"ios"===u()}var w={},x={},y={},z={},A={},B={};b._addAdapter("evothings",w),w.startScan=function(a,b,c,e){d(function(){evothings.ble.stopScan(),evothings.ble.startScan(a,function(a){b&&b(k(a))},function(a){e&&e(a)}),c&&c()})},w.stopScan=function(a){d(function(){evothings.ble.stopScan()})},w.connect=function(a,b,c,d){if(x[a])return void(d&&d("device already connected"));evothings.ble.connect(a,function(d){2===d.state&&b?(x[a]=d.deviceHandle,b()):0===d.state&&c&&(e(a),c())},function(a){d&&d(a)})},w.disconnect=function(a,b){e(a)},w.discoverServices=function(a,b,d,e){var f=g(a,e);f&&evothings.ble.services(f,function(a){var e=[];a.forEach(function(a){var d=c.getCanonicalUUID(a.uuid);(!b||0===b.length||b.indexOf(d)>=0)&&(y[a.handle]=f,e.push({_handle:a.handle,uuid:d,primary:!0}))}),d&&d(e)},function(a){e&&e(a)})},w.discoverIncludedServices=function(a,b,c,d){c([])},w.discoverCharacteristics=function(a,b,d,e){var f=h(a,e);f&&evothings.ble.characteristics(f,a,function(a){var e=[];a.forEach(function(a){var d=c.getCanonicalUUID(a.uuid);(!b||0===b.length||b.indexOf(d)>=0)&&(z[a.handle]=f,e.push({_handle:a.handle,uuid:d,properties:{broadcast:1&a.property,read:2&a.property,writeWithoutResponse:4&a.property&&1&a.writeType,write:8&a.property,notify:16&a.property,indicate:32&a.property,authenticatedSignedWrites:64&a.property&&4&a.writeType,reliableWrite:!1,writableAuxiliaries:!1}}))}),d&&d(e)},function(a){e&&e(a)})},w.discoverDescriptors=function(a,b,d,e){var f=i(a,e);f&&evothings.ble.descriptors(f,a,function(e){var g=[];e.forEach(function(d){var e=c.getCanonicalUUID(d.uuid);"00002902-0000-1000-8000-00805f9b34fb"===e&&(B[a]=d.handle),(!b||0===b.length||b.indexOf(e)>=0)&&(A[d.handle]=f,g.push({_handle:d.handle,uuid:e}))}),d&&d(g)},function(a){e&&e(a)})},w.readCharacteristic=function(a,b,c){var d=i(a,c);d&&evothings.ble.readCharacteristic(d,a,function(a){b&&b(t(a))},function(a){c&&c(a)})},w.writeCharacteristic=function(a,b,c,d){var e=i(a,d);e&&evothings.ble.writeCharacteristic(e,a,b,function(){c&&c()},function(a){d&&d(a)})},w.enableNotify=function(a,b,c,d){function e(){evothings.ble.enableNotification(f,a,function(a){b&&b(t(a))},function(a){d&&d(a)}),c&&c()}var f=i(a,d);f&&j(f,a,e,function(a){d&&d(a)})},w.disableNotify=function(a,b,c){var d=i(a,c);d&&(evothings.ble.disableNotification(d,a,function(){b&&b()},function(a){c&&c(a)}),v()&&setTimeout(b,0))},w.readDescriptor=function(a,b,c){var d=getDeviceHandleFromDescriptorHandle(a,c);d&&evothings.ble.readDescriptor(d,a,function(a){b&&b(t(a))},function(a){c&&c(a)})},w.writeDescriptor=function(a,b,c,d){var e=getDeviceHandleFromDescriptorHandle(a,d);e&&evothings.ble.writeDescriptor(e,a,b,function(){c&&c()},function(a){d&&d(a)})}});
function(a,b){"function"==typeof define&&define.amd?define(["bluetooth.helpers"],b):"object"==typeof exports?module.exports=b(require("./bluetooth.helpers")):a.bleat=b(a.bleatHelpers)}(this,function(a){"use strict";function b(a,b){return function(c){a&&a(b+": "+c)}}function c(a){return function(){if("function"==typeof a){var b=[].slice.call(arguments);a.apply(this,b)}}}function d(a,b){var c=0,d=!1;this.addCallback=function(b){return c++,d=!0,function(){b&&b.apply(null,arguments),0==--c&&a&&a()}},this.error=function(){b&&b.apply(null,arguments),0==--c&&a&&a()},this.finish=function(){!d&&a&&a()}}var e=null,f={},g=function(a){this._handle=a._handle,this.address=a._handle,this.name=a.name,this.serviceUUIDs=a.uuids,this.adData=a.adData,this.connected=!1,this.services={}};g.prototype.hasService=function(a){return this.serviceUUIDs.some(function(b){return b===a})},g.prototype.connect=function(a,d,f,g){e.connect(this._handle,function(){if(this.connected=!0,"boolean"==typeof f&&(g=f,f=null),g)return c(a)();this.discoverAll(a,f)}.bind(this),function(){this.connected=!1,this.services={},c(d)()}.bind(this),b(f,"connect error"))},g.prototype.disconnect=function(a){e.disconnect(this._handle,b(a,"disconnect error"))},g.prototype.discoverServices=function(a,c,d){if(!1===this.connected)return b(d,"discovery error")("device not connected");"function"==typeof a?(c=a,a=[]):"string"==typeof a&&(a=[a]),e.discoverServices(this._handle,a,function(a){a.forEach(function(a){this.services[a.uuid]=new h(a)},this),c&&c()}.bind(this),b(d,"service discovery error"))},g.prototype.discoverAll=function(a,c){if(!1===this.connected)return b(c,"discovery error")("device not connected");var e=new d(a,c);this.discoverServices(e.addCallback(function(){Object.keys(this.services).forEach(function(a){var b=this.services[a];b.discoverIncludedServices(e.addCallback(),e.error),b.discoverCharacteristics(e.addCallback(function(){Object.keys(b.characteristics).forEach(function(a){b.characteristics[a].discoverDescriptors(e.addCallback(),e.error)},this)}.bind(this)),e.error)},this)}.bind(this)),e.error),e.finish()};var h=function(a){this._handle=a._handle,this.uuid=a.uuid,this.primary=a.primary,this.includedServices={},this.characteristics={}};h.prototype.discoverIncludedServices=function(a,c,d){"function"==typeof a?(c=a,a=[]):"string"==typeof a&&(a=[a]),e.discoverIncludedServices(this._handle,a,function(a){a.forEach(function(a){this.includedServices[a.uuid]=new h(a)},this),c&&c()}.bind(this),b(d,"included service discovery error"))},h.prototype.discoverCharacteristics=function(a,c,d){"function"==typeof a?(c=a,a=[]):"string"==typeof a&&(a=[a]),e.discoverCharacteristics(this._handle,a,function(a){a.forEach(function(a){this.characteristics[a.uuid]=new i(a)},this),c&&c()}.bind(this),b(d,"characteristic discovery error"))};var i=function(a){this._handle=a._handle,this.uuid=a.uuid,this.properties=a.properties,this.descriptors={}};i.prototype.discoverDescriptors=function(a,c,d){"function"==typeof a?(c=a,a=[]):"string"==typeof a&&(a=[a]),e.discoverDescriptors(this._handle,a,function(a){a.forEach(function(a){this.descriptors[a.uuid]=new j(a)},this),c&&c()}.bind(this),b(d,"descriptor discovery error"))},i.prototype.read=function(a,d){e.readCharacteristic(this._handle,c(a),b(d,"read characteristic error"))},i.prototype.write=function(a,d,f){e.writeCharacteristic(this._handle,a,c(d),b(f,"write characteristic error"))},i.prototype.enableNotify=function(a,d,f){e.enableNotify(this._handle,c(a),c(d),b(f,"enable notify error"))},i.prototype.disableNotify=function(a,d){e.disableNotify(this._handle,c(a),b(d,"disable notify error"))};var j=function(a){this._handle=a._handle,this.uuid=a.uuid};return j.prototype.read=function(a,d){e.readDescriptor(this._handle,c(a),b(d,"read descriptor error"))},j.prototype.write=function(a,d,f){e.writeDescriptor(this._handle,a,c(d),b(f,"write descriptor error"))},{_addAdapter:function(a,b){f[a]=b,e=b},startScan:function(a,c,d,f,h){"function"==typeof a?(h=f,f=d,d=c,c=a,a=[]):"string"==typeof a&&(a=[a]),e.stopScan(b(f,"stop scan error"));var i={};e.startScan(a,function(a){var b=new g(a);i[b.address]&&!h||(i[b.address]=b,c&&c(b))}.bind(this),d,b(f,"scan error"))},stopScan:function(a){e.stopScan(b(a,"stop scan error"))}}}),function(a,b){"function"==typeof define&&define.amd?define(["bleat","bluetooth.helpers"],b.bind(this,a)):"object"==typeof exports?module.exports=function(c){return b(a,c,require("./bluetooth.helpers"))}:b(a,a.bleat,a.bleatHelpers)}(this,function(a,b,c){"use strict";function d(b){a.evothings&&evothings.ble?b():document.addEventListener("deviceready",b)}function e(a){var b=x[a];b&&(evothings.ble.close(b),delete x[a],f(b,y),f(b,z,!0),f(b,A))}function f(a,b,c){for(var d in b)a===b[d]&&(delete b[d],c&&B[d]&&delete B[d])}function g(a,b){var c=x[a];return c||(b&&b("Device does not exist for device id: "+a),null)}function h(a,b){var c=y[a];return c||(b&&b("Device does not exist for service handle: "+a),null)}function i(a,b){var c=z[a];return c||(b&&b("Device does not exist for characteristic handle: "+a),null)}function j(a,b,c,d){function e(b){evothings.ble.writeDescriptor(a,b,new Uint8Array([1,0]),function(){c()},function(a){d(a)})}function f(){w.discoverDescriptors(b,"00002902-0000-1000-8000-00805f9b34fb",function(a){var c=B[b];c?e(c):d("Could not find CCCD for characteristic: "+b)},function(a){d(a)})}var g=B[b];g?e(g):f()}function k(a){var b={};return b._handle=a.address,b.id=a.address,b.name=a.name,b.uuids=[],b.adData={},b.adData.rssi=a.rssi,b.adData.txPower=null,b.adData.serviceData={},b.adData.manufacturerData=null,a.advertisementData?l(a,b):a.scanRecord&&m(a,b),b}function l(a,b){if(a.advertisementData){if(a.advertisementData.kCBAdvDataLocalName&&(b.name=a.advertisementData.kCBAdvDataLocalName),a.advertisementData.kCBAdvDataTxPowerLevel&&(b.adData.txPower=a.advertisementData.kCBAdvDataTxPowerLevel),a.advertisementData.kCBAdvDataServiceUUIDs&&a.advertisementData.kCBAdvDataServiceUUIDs.forEach(function(a){b.uuids.push(c.getCanonicalUUID(a))}),a.advertisementData.kCBAdvDataServiceData)for(var d in a.advertisementData.kCBAdvDataServiceData){var e=a.advertisementData.kCBAdvDataServiceData[d];b.adData.serviceData[c.getCanonicalUUID(d)]=t(o(e))}a.advertisementData.kCBAdvDataManufacturerData&&(b.adData.manufacturerDataRaw=a.advertisementData.kCBAdvDataManufacturerData)}}function m(a,b){for(var d=o(a.scanRecord),e=0;e<d.length;){var f=d[e++];if(0===f)break;f-=1;var g,h=d[e++];if(8===h||9===h)b.name=evothings.ble.fromUtf8(new Uint8Array(d.buffer,e,f)).replace("\0","");else if(10===h)b.adData.txPower=p(d,e);else if(2===h||3===h)for(g=0;g<f;g+=2)b.uuids.push(c.getCanonicalUUID(q(d,e+g).toString(16)));else if(4===h||5===h)for(g=0;g<f;g+=4)b.uuids.push(c.getCanonicalUUID(r(d,e+g).toString(16)));else if(6===h||7===h)for(g=0;g<f;g+=16)b.uuids.push(c.getCanonicalUUID(s(d,e+g)));e+=f}}function n(a){return a>64&&a<91?a-65:a>96&&a<123?a-71:a>47&&a<58?a+4:43===a?62:47===a?63:0}function o(a,b){for(var c,d,e=a.replace(/[^A-Za-z0-9\+\/]/g,""),f=e.length,g=b?Math.ceil((3*f+1>>2)/b)*b:3*f+1>>2,h=new Uint8Array(g),i=0,j=0,k=0;k<f;k++)if(d=3&k,i|=n(e.charCodeAt(k))<<18-6*d,3===d||f-k==1){for(c=0;c<3&&j<g;c++,j++)h[j]=i>>>(16>>>c&24)&255;i=0}return h}function p(a,b){var c=a[b];return 128&c&&(c-=256),c}function q(a,b){return(a[b+1]<<8)+a[b]}function r(a,b){return(a[b+3]<<24)+(a[b+2]<<16)+(a[b+1]<<8)+a[b]}function s(a,b){for(var c="",d=0;d<16;d++)c+=("00"+a[b+d].toString(16)).slice(-2);return c}function t(a){var b=new Uint8Array(a).buffer;return new DataView(b)}function u(){return a.cordova?a.cordova.platformId:null}function v(){return"ios"===u()}if(b._addAdapter){var w={},x={},y={},z={},A={},B={};b._addAdapter("evothings",w),w.startScan=function(a,b,c,e){d(function(){evothings.ble.stopScan(),evothings.ble.startScan(a,function(a){b&&b(k(a))},function(a){e&&e(a)}),c&&c()})},w.stopScan=function(a){d(function(){evothings.ble.stopScan()})},w.connect=function(a,b,c,d){if(x[a])return void(d&&d("device already connected"));evothings.ble.connect(a,function(d){2===d.state&&b?(x[a]=d.deviceHandle,b()):0===d.state&&c&&(e(a),c())},function(a){d&&d(a)})},w.disconnect=function(a,b){e(a)},w.discoverServices=function(a,b,d,e){var f=g(a,e);f&&evothings.ble.services(f,function(a){var e=[];a.forEach(function(a){var d=c.getCanonicalUUID(a.uuid);(!b||0===b.length||b.indexOf(d)>=0)&&(y[a.handle]=f,e.push({_handle:a.handle,uuid:d,primary:!0}))}),d&&d(e)},function(a){e&&e(a)})},w.discoverIncludedServices=function(a,b,c,d){c([])},w.discoverCharacteristics=function(a,b,d,e){var f=h(a,e);f&&evothings.ble.characteristics(f,a,function(a){var e=[];a.forEach(function(a){var d=c.getCanonicalUUID(a.uuid);(!b||0===b.length||b.indexOf(d)>=0)&&(z[a.handle]=f,e.push({_handle:a.handle,uuid:d,properties:{broadcast:1&a.property,read:2&a.property,writeWithoutResponse:4&a.property&&1&a.writeType,write:8&a.property,notify:16&a.property,indicate:32&a.property,authenticatedSignedWrites:64&a.property&&4&a.writeType,reliableWrite:!1,writableAuxiliaries:!1}}))}),d&&d(e)},function(a){e&&e(a)})},w.discoverDescriptors=function(a,b,d,e){var f=i(a,e);f&&evothings.ble.descriptors(f,a,function(e){var g=[];e.forEach(function(d){var e=c.getCanonicalUUID(d.uuid);"00002902-0000-1000-8000-00805f9b34fb"===e&&(B[a]=d.handle),(!b||0===b.length||b.indexOf(e)>=0)&&(A[d.handle]=f,g.push({_handle:d.handle,uuid:e}))}),d&&d(g)},function(a){e&&e(a)})},w.readCharacteristic=function(a,b,c){var d=i(a,c);d&&evothings.ble.readCharacteristic(d,a,function(a){b&&b(t(a))},function(a){c&&c(a)})},w.writeCharacteristic=function(a,b,c,d){var e=i(a,d);e&&evothings.ble.writeCharacteristic(e,a,b,function(){c&&c()},function(a){d&&d(a)})},w.enableNotify=function(a,b,c,d){function e(){evothings.ble.enableNotification(f,a,function(a){b&&b(t(a))},function(a){d&&d(a)}),c&&c()}var f=i(a,d);f&&j(f,a,e,function(a){d&&d(a)})},w.disableNotify=function(a,b,c){var d=i(a,c);d&&(evothings.ble.disableNotification(d,a,function(){b&&b()},function(a){c&&c(a)}),v()&&setTimeout(b,0))},w.readDescriptor=function(a,b,c){var d=getDeviceHandleFromDescriptorHandle(a,c);d&&evothings.ble.readDescriptor(d,a,function(a){b&&b(t(a))},function(a){c&&c(a)})},w.writeDescriptor=function(a,b,c,d){var e=getDeviceHandleFromDescriptorHandle(a,d);e&&evothings.ble.writeDescriptor(e,a,b,function(){c&&c()},function(a){d&&d(a)})}}});

@@ -79,2 +79,2 @@ /* @license

*/
function(a,b){"function"==typeof define&&define.amd?define(["noble","bleat","bluetooth.helpers"],b):"object"==typeof exports?module.exports=function(a){return b(require("noble"),a,require("./bluetooth.helpers"))}:b(a.noble,a.bleat,a.bleatHelpers)}(this,function(a,b,c){"use strict";function d(a,b){return function(c){if(c)a(c);else if("function"==typeof b){var d=[].slice.call(arguments,1);b.apply(this,d)}}}function e(a){var b=new Uint8Array(a).buffer;return new DataView(b)}function f(a){var b=new Uint8Array(a.buffer);return new Buffer(b)}a&&b._addAdapter("noble",{deviceHandles:{},serviceHandles:{},characteristicHandles:{},descriptorHandles:{},charNotifies:{},foundFn:null,initialised:!1,init:function(b,d){if(this.initialised)return b();a.on("discover",function(a){if(this.foundFn){var b=a.address&&"unknown"!==a.address?a.address:a.id;this.deviceHandles[b]||(this.deviceHandles[b]=a);var d=[];a.advertisement.serviceUuids&&a.advertisement.serviceUuids.forEach(function(a){d.push(c.getCanonicalUUID(a))});var f={};if(a.advertisement.manufacturerData){var g=a.advertisement.manufacturerData.readUInt16LE(0);g=("0000"+g.toString(16)).slice(-4);var h=a.advertisement.manufacturerData.slice(2);f[g]=e(h)}var i={};a.advertisement.serviceData&&a.advertisement.serviceData.forEach(function(a){i[c.getCanonicalUUID(a.uuid)]=e(a.data)}),this.foundFn({_handle:b,id:b,name:a.advertisement.localName,uuids:d,adData:{manufacturerData:f,serviceData:i,txPower:a.advertisement.txPowerLevel,rssi:a.rssi}})}}.bind(this)),this.initialised=!0,b()},startScan:function(b,c,e,f){this.init(function(){this.deviceHandles={};var g=function(g){"poweredOn"===g?(0===b.length?this.foundFn=c:this.foundFn=function(a){b.forEach(function(b){if(a.uuids.indexOf(b)>=0)return void c(a)})},a.startScanning([],!1,d(f,e))):f("adapter not enabled")}.bind(this);"unknown"===a.state?a.once("stateChange",g.bind(this)):g(a.state)}.bind(this),f)},stopScan:function(b){this.foundFn=null,a.stopScanning()},connect:function(a,b,c,e){var f=this.deviceHandles[a];f.once("connect",b),f.once("disconnect",function(){this.serviceHandles={},this.characteristicHandles={},this.descriptorHandles={},this.charNotifies={},c()}.bind(this)),f.connect(d(e))},disconnect:function(a,b){this.deviceHandles[a].disconnect(d(b))},discoverServices:function(a,b,e,f){this.deviceHandles[a].discoverServices([],d(f,function(a){var d=[];a.forEach(function(a){var e=c.getCanonicalUUID(a.uuid);(0===b.length||b.indexOf(e)>=0)&&(this.serviceHandles[e]||(this.serviceHandles[e]=a),d.push({_handle:e,uuid:e,primary:!0}))},this),e(d)}.bind(this)))},discoverIncludedServices:function(a,b,e,f){this.serviceHandles[a].discoverIncludedServices([],d(f,function(a){var d=[];a.forEach(function(a){var e=c.getCanonicalUUID(a.uuid);(0===b.length||b.indexOf(e)>=0)&&(this.serviceHandles[e]||(this.serviceHandles[e]=a),d.push({_handle:e,uuid:e,primary:!1}))},this),e(d)}.bind(this)))},discoverCharacteristics:function(a,b,f,g){this.serviceHandles[a].discoverCharacteristics([],d(g,function(a){var d=[];a.forEach(function(a){var f=c.getCanonicalUUID(a.uuid);(0===b.length||b.indexOf(f)>=0)&&(this.characteristicHandles[f]||(this.characteristicHandles[f]=a),d.push({_handle:f,uuid:f,properties:{broadcast:a.properties.indexOf("broadcast")>=0,read:a.properties.indexOf("read")>=0,writeWithoutResponse:a.properties.indexOf("writeWithoutResponse")>=0,write:a.properties.indexOf("write")>=0,notify:a.properties.indexOf("notify")>=0,indicate:a.properties.indexOf("indicate")>=0,authenticatedSignedWrites:a.properties.indexOf("authenticatedSignedWrites")>=0,reliableWrite:a.properties.indexOf("reliableWrite")>=0,writableAuxiliaries:a.properties.indexOf("writableAuxiliaries")>=0}}),a.on("data",function(a,b){if(!0===b&&"function"==typeof this.charNotifies[f]){var c=e(a);this.charNotifies[f](c)}}.bind(this)))},this),f(d)}.bind(this)))},discoverDescriptors:function(a,b,e,f){var g=this.characteristicHandles[a];g.discoverDescriptors(d(f,function(a){var d=[];a.forEach(function(a){var e=c.getCanonicalUUID(a.uuid);if(0===b.length||b.indexOf(e)>=0){var f=g.uuid+"-"+a.uuid;this.descriptorHandles[f]||(this.descriptorHandles[f]=a),d.push({_handle:f,uuid:e})}},this),e(d)}.bind(this)))},readCharacteristic:function(a,b,c){this.characteristicHandles[a].read(d(c,function(a){var c=e(a);b(c)}))},writeCharacteristic:function(a,b,c,e){var g=f(b);this.characteristicHandles[a].write(g,!0,d(e,c))},enableNotify:function(a,b,c,e){if(this.charNotifies[a])return this.charNotifies[a]=b,c();this.characteristicHandles[a].once("notify",function(d){if(!0!==d)return e("notify failed to enable");this.charNotifies[a]=b,c()}.bind(this)),this.characteristicHandles[a].notify(!0,d(e))},disableNotify:function(a,b,c){if(!this.charNotifies[characteristic.uuid])return b();this.characteristicHandles[a].once("notify",function(d){if(!1!==d)return c("notify failed to disable");this.charNotifies[a]&&delete this.charNotifies[a],b()}.bind(this)),this.characteristicHandles[a].notify(!1,d(c))},readDescriptor:function(a,b,c){this.descriptorHandles[a].readValue(d(c,function(a){var c=e(a);b(c)}))},writeDescriptor:function(a,b,c,e){var g=f(b);this.descriptorHandles[a].writeValue(g,d(e,c))}})});
function(a,b){"function"==typeof define&&define.amd?define(["noble","bleat","bluetooth.helpers"],b):"object"==typeof exports?module.exports=function(a){return b(require("noble"),a,require("./bluetooth.helpers"))}:b(a.noble,a.bleat,a.bleatHelpers)}(this,function(a,b,c){"use strict";function d(a,b){return function(c){if(c)a(c);else if("function"==typeof b){var d=[].slice.call(arguments,1);b.apply(this,d)}}}function e(a){var b=new Uint8Array(a).buffer;return new DataView(b)}function f(a){var b=new Uint8Array(a.buffer);return new Buffer(b)}b._addAdapter&&a&&b._addAdapter("noble",{deviceHandles:{},serviceHandles:{},characteristicHandles:{},descriptorHandles:{},charNotifies:{},foundFn:null,initialised:!1,init:function(b,d){if(this.initialised)return b();a.on("discover",function(a){if(this.foundFn){var b=a.address&&"unknown"!==a.address?a.address:a.id;this.deviceHandles[b]||(this.deviceHandles[b]=a);var d=[];a.advertisement.serviceUuids&&a.advertisement.serviceUuids.forEach(function(a){d.push(c.getCanonicalUUID(a))});var f={};if(a.advertisement.manufacturerData){var g=a.advertisement.manufacturerData.readUInt16LE(0);g=("0000"+g.toString(16)).slice(-4);var h=a.advertisement.manufacturerData.slice(2);f[g]=e(h)}var i={};a.advertisement.serviceData&&a.advertisement.serviceData.forEach(function(a){i[c.getCanonicalUUID(a.uuid)]=e(a.data)}),this.foundFn({_handle:b,id:b,name:a.advertisement.localName,uuids:d,adData:{manufacturerData:f,serviceData:i,txPower:a.advertisement.txPowerLevel,rssi:a.rssi}})}}.bind(this)),this.initialised=!0,b()},startScan:function(b,c,e,f){this.init(function(){this.deviceHandles={};var g=function(g){"poweredOn"===g?(0===b.length?this.foundFn=c:this.foundFn=function(a){b.forEach(function(b){if(a.uuids.indexOf(b)>=0)return void c(a)})},a.startScanning([],!1,d(f,e))):f("adapter not enabled")}.bind(this);"unknown"===a.state?a.once("stateChange",g.bind(this)):g(a.state)}.bind(this),f)},stopScan:function(b){this.foundFn=null,a.stopScanning()},connect:function(a,b,c,e){var f=this.deviceHandles[a];f.once("connect",b),f.once("disconnect",function(){this.serviceHandles={},this.characteristicHandles={},this.descriptorHandles={},this.charNotifies={},c()}.bind(this)),f.connect(d(e))},disconnect:function(a,b){this.deviceHandles[a].disconnect(d(b))},discoverServices:function(a,b,e,f){this.deviceHandles[a].discoverServices([],d(f,function(a){var d=[];a.forEach(function(a){var e=c.getCanonicalUUID(a.uuid);(0===b.length||b.indexOf(e)>=0)&&(this.serviceHandles[e]||(this.serviceHandles[e]=a),d.push({_handle:e,uuid:e,primary:!0}))},this),e(d)}.bind(this)))},discoverIncludedServices:function(a,b,e,f){this.serviceHandles[a].discoverIncludedServices([],d(f,function(a){var d=[];a.forEach(function(a){var e=c.getCanonicalUUID(a.uuid);(0===b.length||b.indexOf(e)>=0)&&(this.serviceHandles[e]||(this.serviceHandles[e]=a),d.push({_handle:e,uuid:e,primary:!1}))},this),e(d)}.bind(this)))},discoverCharacteristics:function(a,b,f,g){this.serviceHandles[a].discoverCharacteristics([],d(g,function(a){var d=[];a.forEach(function(a){var f=c.getCanonicalUUID(a.uuid);(0===b.length||b.indexOf(f)>=0)&&(this.characteristicHandles[f]||(this.characteristicHandles[f]=a),d.push({_handle:f,uuid:f,properties:{broadcast:a.properties.indexOf("broadcast")>=0,read:a.properties.indexOf("read")>=0,writeWithoutResponse:a.properties.indexOf("writeWithoutResponse")>=0,write:a.properties.indexOf("write")>=0,notify:a.properties.indexOf("notify")>=0,indicate:a.properties.indexOf("indicate")>=0,authenticatedSignedWrites:a.properties.indexOf("authenticatedSignedWrites")>=0,reliableWrite:a.properties.indexOf("reliableWrite")>=0,writableAuxiliaries:a.properties.indexOf("writableAuxiliaries")>=0}}),a.on("data",function(a,b){if(!0===b&&"function"==typeof this.charNotifies[f]){var c=e(a);this.charNotifies[f](c)}}.bind(this)))},this),f(d)}.bind(this)))},discoverDescriptors:function(a,b,e,f){var g=this.characteristicHandles[a];g.discoverDescriptors(d(f,function(a){var d=[];a.forEach(function(a){var e=c.getCanonicalUUID(a.uuid);if(0===b.length||b.indexOf(e)>=0){var f=g.uuid+"-"+a.uuid;this.descriptorHandles[f]||(this.descriptorHandles[f]=a),d.push({_handle:f,uuid:e})}},this),e(d)}.bind(this)))},readCharacteristic:function(a,b,c){this.characteristicHandles[a].read(d(c,function(a){var c=e(a);b(c)}))},writeCharacteristic:function(a,b,c,e){var g=f(b);this.characteristicHandles[a].write(g,!0,d(e,c))},enableNotify:function(a,b,c,e){if(this.charNotifies[a])return this.charNotifies[a]=b,c();this.characteristicHandles[a].once("notify",function(d){if(!0!==d)return e("notify failed to enable");this.charNotifies[a]=b,c()}.bind(this)),this.characteristicHandles[a].notify(!0,d(e))},disableNotify:function(a,b,c){if(!this.charNotifies[characteristic.uuid])return b();this.characteristicHandles[a].once("notify",function(d){if(!1!==d)return c("notify failed to disable");this.charNotifies[a]&&delete this.charNotifies[a],b()}.bind(this)),this.characteristicHandles[a].notify(!1,d(c))},readDescriptor:function(a,b,c){this.descriptorHandles[a].readValue(d(c,function(a){var c=e(a);b(c)}))},writeDescriptor:function(a,b,c,e){var g=f(b);this.descriptorHandles[a].writeValue(g,d(e,c))}})});

@@ -53,2 +53,2 @@ /* @license

*/
function(a,b){"function"==typeof define&&define.amd?a.navigator.bluetooth?define(a.navigator.bluetooth):define(["es6-promise","es6-map","bluetooth.helpers"],b):"object"==typeof exports?module.exports=b(Promise,Map,require("./bluetooth.helpers")):a.bleat=a.navigator.bluetooth||b(a.Promise,a.Map,a.bleatHelpers)}(this,function(a,b,c){"use strict";function d(a,b){return function(c){a(b+": "+c)}}function e(a,b){b&&Object.keys(b).forEach(function(c){b[c]&&a.hasOwnProperty(c)&&("[object Object]"===Object.prototype.toString.call(a[c])?e(a[c],b[c]):"[object Map]"===Object.prototype.toString.call(a[c])&&"[object Object]"===Object.prototype.toString.call(b[c])?Object.keys(b[c]).forEach(function(d){a[c].set(d,b[c][d])}):a[c]=b[c])})}function f(a){return function(b,c,d){a.indexOf(b)<0||(o[this]||(o[this]={}),o[this][b]||(o[this][b]=[]),o[this][b].push(c))}}function g(a,b,c){if(o[this]&&o[this][a]){var d=o[this][a].indexOf(b);d>=0&&o[this][a].splice(d,1),0===o[this][a].length&&delete o[this][a],0===Object.keys(o[this]).length&&delete o[this]}}function h(a){o[this]&&o[this][a.type]&&(a.target=this,o[this][a.type].forEach(function(b){"function"==typeof b&&b(a)}))}function i(a,b,d){var e=!1;return a.filters.forEach(function(a){if(!a.name||a.name===b.name){if(a.namePrefix){if(a.namePrefix.length>b.name.length)return;if(a.namePrefix!==b.name.substr(0,a.namePrefix.length))return}if(a.services){var f=a.services.map(c.getServiceUUID);if(!f.every(function(a){return b.uuids.indexOf(a)>-1}))return;d=d.concat(f)}e=!0}}),!!e&&b}function j(b){return new a(function(a,e){if(null!==p)return e("requestDevice error: request in progress");if(!b.acceptAllDevices&&!b.deviceFound){if(!b.filters||0===b.filters.length)return e(new TypeError("requestDevice error: no filters specified"));if(b.filters.some(function(a){return 0===Object.keys(a).length}))return e(new TypeError("requestDevice error: empty filter specified"));if(b.filters.some(function(a){return void 0!==a.namePrefix&&""===a.namePrefix}))return e(new TypeError("requestDevice error: empty namePrefix specified"))}var f=[];b.filters&&b.filters.forEach(function(a){a.services&&(f=f.concat(a.services.map(c.getServiceUUID)))}),f=f.filter(function(a,b,c){return c.indexOf(a)===b});var g=!1;m.startScan(f,function(d){function e(b){k().then(function(){a(b)})}function f(){e(j)}var h=[];if(b.filters&&(d=i(b,d,h)),d){g=!0,b.optionalServices&&(h=h.concat(b.optionalServices.map(c.getServiceUUID))),d._allowedServices=h.filter(function(a,b,c){return c.indexOf(a)===b});var j=new q(d);b.deviceFound&&!b.deviceFound(j,f)||e(j)}},function(){p=setTimeout(function(){k().then(function(){g||e("requestDevice error: no devices found")})},b.scanTime||l)},d(e,"requestDevice error"))})}function k(){return new a(function(a,b){p&&(clearTimeout(p),p=null,m.stopScan()),a()})}var l=10240,m=null,n={},o={},p=null,q=function(a){this._handle=null,this._allowedServices=[],this.id="unknown",this.name=null,this.adData={appearance:null,txPower:null,rssi:null,manufacturerData:new b,serviceData:new b},this.gatt=new r,this.gatt.device=this,this.uuids=[],e(this,a)};q.prototype.addEventListener=f(["gattserverdisconnected"]),q.prototype.removeEventListener=g,q.prototype.dispatchEvent=h;var r=function(){this._services=null,this.device=null,this.connected=!1};r.prototype.connect=function(){return new a(function(a,b){if(this.connected)return b("connect error: device already connected");m.connect(this.device._handle,function(){this.connected=!0,a(this)}.bind(this),function(){this._services=null,this.connected=!1,this.device.dispatchEvent({type:"gattserverdisconnected",bubbles:!0})}.bind(this),d(b,"connect error"))}.bind(this))},r.prototype.disconnect=function(){m.disconnect(this.device._handle),this.connected=!1},r.prototype.getPrimaryService=function(b){return new a(function(a,c){return this.connected?b?void this.getPrimaryServices(b).then(function(b){if(1!==b.length)return c("getPrimaryService error: service not found");a(b[0])}).catch(function(a){c(a)}):c("getPrimaryService error: no service specified"):c("getPrimaryService error: device not connected")}.bind(this))},r.prototype.getPrimaryServices=function(b){return new a(function(a,e){function f(){if(!b)return a(this._services);var d=this._services.filter(function(a){return a.uuid===c.getServiceUUID(b)});if(1!==d.length)return e("getPrimaryServices error: service not found");a(d)}return this.connected?this._services?f.call(this):void m.discoverServices(this.device._handle,this.device._allowedServices,function(a){this._services=a.map(function(a){return a.device=this.device,new s(a)}.bind(this)),f.call(this)}.bind(this),d(e,"getPrimaryServices error")):e("getPrimaryServices error: device not connected")}.bind(this))};var s=function(a){this._handle=null,this._services=null,this._characteristics=null,this.device=null,this.uuid=null,this.isPrimary=!1,e(this,a),this.dispatchEvent({type:"serviceadded",bubbles:!0})};s.prototype.getCharacteristic=function(b){return new a(function(a,c){return this.device.gatt.connected?b?void this.getCharacteristics(b).then(function(b){if(1!==b.length)return c("getCharacteristic error: characteristic not found");a(b[0])}).catch(function(a){c(a)}):c("getCharacteristic error: no characteristic specified"):c("getCharacteristic error: device not connected")}.bind(this))},s.prototype.getCharacteristics=function(b){return new a(function(a,e){function f(){if(!b)return a(this._characteristics);var d=this._characteristics.filter(function(a){return a.uuid===c.getCharacteristicUUID(b)});if(1!==d.length)return e("getCharacteristics error: characteristic not found");a(d)}return this.device.gatt.connected?this._characteristics?f.call(this):void m.discoverCharacteristics(this._handle,[],function(a){this._characteristics=a.map(function(a){return a.service=this,new t(a)}.bind(this)),f.call(this)}.bind(this),d(e,"getCharacteristics error")):e("getCharacteristics error: device not connected")}.bind(this))},s.prototype.getIncludedService=function(b){return new a(function(a,c){return this.device.gatt.connected?b?void this.getIncludedServices(b).then(function(b){if(1!==b.length)return c("getIncludedService error: service not found");a(b[0])}).catch(function(a){c(a)}):c("getIncludedService error: no service specified"):c("getIncludedService error: device not connected")}.bind(this))},s.prototype.getIncludedServices=function(b){return new a(function(a,e){function f(){if(!b)return a(this._services);var d=this._services.filter(function(a){return a.uuid===c.getServiceUUID(b)});if(1!==d.length)return e("getIncludedServices error: service not found");a(d)}return this.device.gatt.connected?this._services?f.call(this):void m.discoverIncludedServices(this._handle,this.device._allowedServices,function(a){this._services=a.map(function(a){return a.device=this.device,new s(a)}.bind(this)),f.call(this)}.bind(this),d(e,"getIncludedServices error")):e("getIncludedServices error: device not connected")}.bind(this))},s.prototype.addEventListener=f(["serviceadded","servicechanged","serviceremoved"]),s.prototype.removeEventListener=g,s.prototype.dispatchEvent=h;var t=function(a){this._handle=null,this._descriptors=null,this.service=null,this.uuid=null,this.properties={broadcast:!1,read:!1,writeWithoutResponse:!1,write:!1,notify:!1,indicate:!1,authenticatedSignedWrites:!1,reliableWrite:!1,writableAuxiliaries:!1},this.value=null,e(this,a)};t.prototype.getDescriptor=function(b){return new a(function(a,c){return this.service.device.gatt.connected?b?void this.getDescriptors(b).then(function(b){if(1!==b.length)return c("getDescriptor error: descriptor not found");a(b[0])}).catch(function(a){c(a)}):c("getDescriptor error: no descriptor specified"):c("getDescriptor error: device not connected")}.bind(this))},t.prototype.getDescriptors=function(b){return new a(function(a,e){function f(){if(!b)return a(this._descriptors);var d=this._descriptors.filter(function(a){return a.uuid===c.getDescriptorUUID(b)});if(1!==d.length)return e("getDescriptors error: descriptor not found");a(d)}return this.service.device.gatt.connected?this._descriptors?f.call(this):void m.discoverDescriptors(this._handle,[],function(a){this._descriptors=a.map(function(a){return a.characteristic=this,new u(a)}.bind(this)),f.call(this)}.bind(this),d(e,"getDescriptors error")):e("getDescriptors error: device not connected")}.bind(this))},t.prototype.readValue=function(){return new a(function(a,b){if(!this.service.device.gatt.connected)return b("readValue error: device not connected");m.readCharacteristic(this._handle,function(b){this.value=b,a(b),this.dispatchEvent({type:"characteristicvaluechanged",bubbles:!0})}.bind(this),d(b,"readValue error"))}.bind(this))},t.prototype.writeValue=function(b){return new a(function(a,c){if(!this.service.device.gatt.connected)return c("writeValue error: device not connected");var e=b.buffer||b,f=new DataView(e);m.writeCharacteristic(this._handle,f,function(){this.value=f,a()}.bind(this),d(c,"writeValue error"))}.bind(this))},t.prototype.startNotifications=function(){return new a(function(a,b){if(!this.service.device.gatt.connected)return b("startNotifications error: device not connected");m.enableNotify(this._handle,function(a){this.value=a,this.dispatchEvent({type:"characteristicvaluechanged",bubbles:!0})}.bind(this),a,d(b,"startNotifications error"))}.bind(this))},t.prototype.stopNotifications=function(){return new a(function(a,b){if(!this.service.device.gatt.connected)return b("stopNotifications error: device not connected");m.disableNotify(this._handle,a,d(b,"stopNotifications error"))}.bind(this))},t.prototype.addEventListener=f(["characteristicvaluechanged"]),t.prototype.removeEventListener=g,t.prototype.dispatchEvent=h;var u=function(a){this._handle=null,this.characteristic=null,this.uuid=null,this.value=null,e(this,a)};return u.prototype.readValue=function(){return new a(function(a,b){if(!this.characteristic.service.device.gatt.connected)return b("readValue error: device not connected");m.readDescriptor(this._handle,function(b){this.value=b,a(b)}.bind(this),d(b,"readValue error"))}.bind(this))},u.prototype.writeValue=function(b){return new a(function(a,c){if(!this.characteristic.service.device.gatt.connected)return c("writeValue error: device not connected");var e=b.buffer||b,f=new DataView(e);m.writeDescriptor(this._handle,f,function(){this.value=f,a()}.bind(this),d(c,"writeValue error"))}.bind(this))},{_addAdapter:function(a,b){n[a]=b,m=b},requestDevice:j,cancelRequest:k}}),function(a,b){"function"==typeof define&&define.amd?define(["bleat","bluetooth.helpers"],b.bind(this,a)):"object"==typeof exports?module.exports=function(c){return b(a,c,require("./bluetooth.helpers"))}:b(a,a.bleat,a.bleatHelpers)}(this,function(a,b,c){"use strict";function d(b){a.evothings&&evothings.ble?b():document.addEventListener("deviceready",b)}function e(a){var b=x[a];b&&(evothings.ble.close(b),delete x[a],f(b,y),f(b,z,!0),f(b,A))}function f(a,b,c){for(var d in b)a===b[d]&&(delete b[d],c&&B[d]&&delete B[d])}function g(a,b){var c=x[a];return c||(b&&b("Device does not exist for device id: "+a),null)}function h(a,b){var c=y[a];return c||(b&&b("Device does not exist for service handle: "+a),null)}function i(a,b){var c=z[a];return c||(b&&b("Device does not exist for characteristic handle: "+a),null)}function j(a,b,c,d){function e(b){evothings.ble.writeDescriptor(a,b,new Uint8Array([1,0]),function(){c()},function(a){d(a)})}function f(){w.discoverDescriptors(b,"00002902-0000-1000-8000-00805f9b34fb",function(a){var c=B[b];c?e(c):d("Could not find CCCD for characteristic: "+b)},function(a){d(a)})}var g=B[b];g?e(g):f()}function k(a){var b={};return b._handle=a.address,b.id=a.address,b.name=a.name,b.uuids=[],b.adData={},b.adData.rssi=a.rssi,b.adData.txPower=null,b.adData.serviceData={},b.adData.manufacturerData=null,a.advertisementData?l(a,b):a.scanRecord&&m(a,b),b}function l(a,b){if(a.advertisementData){if(a.advertisementData.kCBAdvDataLocalName&&(b.name=a.advertisementData.kCBAdvDataLocalName),a.advertisementData.kCBAdvDataTxPowerLevel&&(b.adData.txPower=a.advertisementData.kCBAdvDataTxPowerLevel),a.advertisementData.kCBAdvDataServiceUUIDs&&a.advertisementData.kCBAdvDataServiceUUIDs.forEach(function(a){b.uuids.push(c.getCanonicalUUID(a))}),a.advertisementData.kCBAdvDataServiceData)for(var d in a.advertisementData.kCBAdvDataServiceData){var e=a.advertisementData.kCBAdvDataServiceData[d];b.adData.serviceData[c.getCanonicalUUID(d)]=t(o(e))}a.advertisementData.kCBAdvDataManufacturerData&&(b.adData.manufacturerDataRaw=a.advertisementData.kCBAdvDataManufacturerData)}}function m(a,b){for(var d=o(a.scanRecord),e=0;e<d.length;){var f=d[e++];if(0===f)break;f-=1;var g,h=d[e++];if(8===h||9===h)b.name=evothings.ble.fromUtf8(new Uint8Array(d.buffer,e,f)).replace("\0","");else if(10===h)b.adData.txPower=p(d,e);else if(2===h||3===h)for(g=0;g<f;g+=2)b.uuids.push(c.getCanonicalUUID(q(d,e+g).toString(16)));else if(4===h||5===h)for(g=0;g<f;g+=4)b.uuids.push(c.getCanonicalUUID(r(d,e+g).toString(16)));else if(6===h||7===h)for(g=0;g<f;g+=16)b.uuids.push(c.getCanonicalUUID(s(d,e+g)));e+=f}}function n(a){return a>64&&a<91?a-65:a>96&&a<123?a-71:a>47&&a<58?a+4:43===a?62:47===a?63:0}function o(a,b){for(var c,d,e=a.replace(/[^A-Za-z0-9\+\/]/g,""),f=e.length,g=b?Math.ceil((3*f+1>>2)/b)*b:3*f+1>>2,h=new Uint8Array(g),i=0,j=0,k=0;k<f;k++)if(d=3&k,i|=n(e.charCodeAt(k))<<18-6*d,3===d||f-k==1){for(c=0;c<3&&j<g;c++,j++)h[j]=i>>>(16>>>c&24)&255;i=0}return h}function p(a,b){var c=a[b];return 128&c&&(c-=256),c}function q(a,b){return(a[b+1]<<8)+a[b]}function r(a,b){return(a[b+3]<<24)+(a[b+2]<<16)+(a[b+1]<<8)+a[b]}function s(a,b){for(var c="",d=0;d<16;d++)c+=("00"+a[b+d].toString(16)).slice(-2);return c}function t(a){var b=new Uint8Array(a).buffer;return new DataView(b)}function u(){return a.cordova?a.cordova.platformId:null}function v(){return"ios"===u()}var w={},x={},y={},z={},A={},B={};b._addAdapter("evothings",w),w.startScan=function(a,b,c,e){d(function(){evothings.ble.stopScan(),evothings.ble.startScan(a,function(a){b&&b(k(a))},function(a){e&&e(a)}),c&&c()})},w.stopScan=function(a){d(function(){evothings.ble.stopScan()})},w.connect=function(a,b,c,d){if(x[a])return void(d&&d("device already connected"));evothings.ble.connect(a,function(d){2===d.state&&b?(x[a]=d.deviceHandle,b()):0===d.state&&c&&(e(a),c())},function(a){d&&d(a)})},w.disconnect=function(a,b){e(a)},w.discoverServices=function(a,b,d,e){var f=g(a,e);f&&evothings.ble.services(f,function(a){var e=[];a.forEach(function(a){var d=c.getCanonicalUUID(a.uuid);(!b||0===b.length||b.indexOf(d)>=0)&&(y[a.handle]=f,e.push({_handle:a.handle,uuid:d,primary:!0}))}),d&&d(e)},function(a){e&&e(a)})},w.discoverIncludedServices=function(a,b,c,d){c([])},w.discoverCharacteristics=function(a,b,d,e){var f=h(a,e);f&&evothings.ble.characteristics(f,a,function(a){var e=[];a.forEach(function(a){var d=c.getCanonicalUUID(a.uuid);(!b||0===b.length||b.indexOf(d)>=0)&&(z[a.handle]=f,e.push({_handle:a.handle,uuid:d,properties:{broadcast:1&a.property,read:2&a.property,writeWithoutResponse:4&a.property&&1&a.writeType,write:8&a.property,notify:16&a.property,indicate:32&a.property,authenticatedSignedWrites:64&a.property&&4&a.writeType,reliableWrite:!1,writableAuxiliaries:!1}}))}),d&&d(e)},function(a){e&&e(a)})},w.discoverDescriptors=function(a,b,d,e){var f=i(a,e);f&&evothings.ble.descriptors(f,a,function(e){var g=[];e.forEach(function(d){var e=c.getCanonicalUUID(d.uuid);"00002902-0000-1000-8000-00805f9b34fb"===e&&(B[a]=d.handle),(!b||0===b.length||b.indexOf(e)>=0)&&(A[d.handle]=f,g.push({_handle:d.handle,uuid:e}))}),d&&d(g)},function(a){e&&e(a)})},w.readCharacteristic=function(a,b,c){var d=i(a,c);d&&evothings.ble.readCharacteristic(d,a,function(a){b&&b(t(a))},function(a){c&&c(a)})},w.writeCharacteristic=function(a,b,c,d){var e=i(a,d);e&&evothings.ble.writeCharacteristic(e,a,b,function(){c&&c()},function(a){d&&d(a)})},w.enableNotify=function(a,b,c,d){function e(){evothings.ble.enableNotification(f,a,function(a){b&&b(t(a))},function(a){d&&d(a)}),c&&c()}var f=i(a,d);f&&j(f,a,e,function(a){d&&d(a)})},w.disableNotify=function(a,b,c){var d=i(a,c);d&&(evothings.ble.disableNotification(d,a,function(){b&&b()},function(a){c&&c(a)}),v()&&setTimeout(b,0))},w.readDescriptor=function(a,b,c){var d=getDeviceHandleFromDescriptorHandle(a,c);d&&evothings.ble.readDescriptor(d,a,function(a){b&&b(t(a))},function(a){c&&c(a)})},w.writeDescriptor=function(a,b,c,d){var e=getDeviceHandleFromDescriptorHandle(a,d);e&&evothings.ble.writeDescriptor(e,a,b,function(){c&&c()},function(a){d&&d(a)})}});
function(a,b){"function"==typeof define&&define.amd?a.navigator.bluetooth?define(a.navigator.bluetooth):define(["es6-promise","es6-map","bluetooth.helpers"],b):"object"==typeof exports?module.exports=b(Promise,Map,require("./bluetooth.helpers")):a.bleat=a.navigator.bluetooth||b(a.Promise,a.Map,a.bleatHelpers)}(this,function(a,b,c){"use strict";function d(a,b){return function(c){a(b+": "+c)}}function e(a,b){b&&Object.keys(b).forEach(function(c){b[c]&&a.hasOwnProperty(c)&&("[object Object]"===Object.prototype.toString.call(a[c])?e(a[c],b[c]):"[object Map]"===Object.prototype.toString.call(a[c])&&"[object Object]"===Object.prototype.toString.call(b[c])?Object.keys(b[c]).forEach(function(d){a[c].set(d,b[c][d])}):a[c]=b[c])})}function f(a){return function(b,c,d){a.indexOf(b)<0||(this.__events||(this.__events={}),this.__events[b]||(this.__events[b]=[]),this.__events[b].push(c))}}function g(a,b,c){if(this.__events&&this.__events[a]){var d=this.__events[a].indexOf(b);d>=0&&this.__events[a].splice(d,1),0===this.__events[a].length&&delete this.__events[a],0===Object.keys(this.__events).length&&delete this.__events}}function h(a){this.__events&&this.__events[a.type]&&(a.target=this,this.__events[a.type].forEach(function(b){"function"==typeof b&&b(a)}))}function i(a,b,d){var e=!1;return a.filters.forEach(function(a){if(!a.name||a.name===b.name){if(a.namePrefix){if(a.namePrefix.length>b.name.length)return;if(a.namePrefix!==b.name.substr(0,a.namePrefix.length))return}if(a.services){var f=a.services.map(c.getServiceUUID);if(!f.every(function(a){return b.uuids.indexOf(a)>-1}))return;d=d.concat(f)}e=!0}}),!!e&&b}function j(b){return new a(function(a,e){if(null!==o)return e("requestDevice error: request in progress");if(!b.acceptAllDevices&&!b.deviceFound){if(!b.filters||0===b.filters.length)return e(new TypeError("requestDevice error: no filters specified"));if(b.filters.some(function(a){return 0===Object.keys(a).length}))return e(new TypeError("requestDevice error: empty filter specified"));if(b.filters.some(function(a){return void 0!==a.namePrefix&&""===a.namePrefix}))return e(new TypeError("requestDevice error: empty namePrefix specified"))}var f=[];b.filters&&b.filters.forEach(function(a){a.services&&(f=f.concat(a.services.map(c.getServiceUUID)))}),f=f.filter(function(a,b,c){return c.indexOf(a)===b});var g=!1;m.startScan(f,function(d){function e(b){k().then(function(){a(b)})}function f(){e(j)}var h=[];if(b.filters&&(d=i(b,d,h)),d){g=!0,b.optionalServices&&(h=h.concat(b.optionalServices.map(c.getServiceUUID))),d._allowedServices=h.filter(function(a,b,c){return c.indexOf(a)===b});var j=new p(d);b.deviceFound&&!b.deviceFound(j,f)||e(j)}},function(){o=setTimeout(function(){k().then(function(){g||e("requestDevice error: no devices found")})},b.scanTime||l)},d(e,"requestDevice error"))})}function k(){return new a(function(a,b){o&&(clearTimeout(o),o=null,m.stopScan()),a()})}var l=10240,m=null,n={},o=null,p=function(a){this._handle=null,this._allowedServices=[],this.id="unknown",this.name=null,this.adData={appearance:null,txPower:null,rssi:null,manufacturerData:new b,serviceData:new b},this.gatt=new q,this.gatt.device=this,this.uuids=[],e(this,a)};p.prototype.addEventListener=f(["gattserverdisconnected"]),p.prototype.removeEventListener=g,p.prototype.dispatchEvent=h;var q=function(){this._services=null,this.device=null,this.connected=!1};q.prototype.connect=function(){return new a(function(a,b){if(this.connected)return b("connect error: device already connected");m.connect(this.device._handle,function(){this.connected=!0,a(this)}.bind(this),function(){this._services=null,this.connected=!1,this.device.dispatchEvent({type:"gattserverdisconnected",bubbles:!0})}.bind(this),d(b,"connect error"))}.bind(this))},q.prototype.disconnect=function(){m.disconnect(this.device._handle),this.connected=!1},q.prototype.getPrimaryService=function(b){return new a(function(a,c){return this.connected?b?void this.getPrimaryServices(b).then(function(b){if(1!==b.length)return c("getPrimaryService error: service not found");a(b[0])}).catch(function(a){c(a)}):c("getPrimaryService error: no service specified"):c("getPrimaryService error: device not connected")}.bind(this))},q.prototype.getPrimaryServices=function(b){return new a(function(a,e){function f(){if(!b)return a(this._services);var d=this._services.filter(function(a){return a.uuid===c.getServiceUUID(b)});if(1!==d.length)return e("getPrimaryServices error: service not found");a(d)}return this.connected?this._services?f.call(this):void m.discoverServices(this.device._handle,this.device._allowedServices,function(a){this._services=a.map(function(a){return a.device=this.device,new r(a)}.bind(this)),f.call(this)}.bind(this),d(e,"getPrimaryServices error")):e("getPrimaryServices error: device not connected")}.bind(this))};var r=function(a){this._handle=null,this._services=null,this._characteristics=null,this.device=null,this.uuid=null,this.isPrimary=!1,e(this,a),this.dispatchEvent({type:"serviceadded",bubbles:!0})};r.prototype.getCharacteristic=function(b){return new a(function(a,c){return this.device.gatt.connected?b?void this.getCharacteristics(b).then(function(b){if(1!==b.length)return c("getCharacteristic error: characteristic not found");a(b[0])}).catch(function(a){c(a)}):c("getCharacteristic error: no characteristic specified"):c("getCharacteristic error: device not connected")}.bind(this))},r.prototype.getCharacteristics=function(b){return new a(function(a,e){function f(){if(!b)return a(this._characteristics);var d=this._characteristics.filter(function(a){return a.uuid===c.getCharacteristicUUID(b)});if(1!==d.length)return e("getCharacteristics error: characteristic not found");a(d)}return this.device.gatt.connected?this._characteristics?f.call(this):void m.discoverCharacteristics(this._handle,[],function(a){this._characteristics=a.map(function(a){return a.service=this,new s(a)}.bind(this)),f.call(this)}.bind(this),d(e,"getCharacteristics error")):e("getCharacteristics error: device not connected")}.bind(this))},r.prototype.getIncludedService=function(b){return new a(function(a,c){return this.device.gatt.connected?b?void this.getIncludedServices(b).then(function(b){if(1!==b.length)return c("getIncludedService error: service not found");a(b[0])}).catch(function(a){c(a)}):c("getIncludedService error: no service specified"):c("getIncludedService error: device not connected")}.bind(this))},r.prototype.getIncludedServices=function(b){return new a(function(a,e){function f(){if(!b)return a(this._services);var d=this._services.filter(function(a){return a.uuid===c.getServiceUUID(b)});if(1!==d.length)return e("getIncludedServices error: service not found");a(d)}return this.device.gatt.connected?this._services?f.call(this):void m.discoverIncludedServices(this._handle,this.device._allowedServices,function(a){this._services=a.map(function(a){return a.device=this.device,new r(a)}.bind(this)),f.call(this)}.bind(this),d(e,"getIncludedServices error")):e("getIncludedServices error: device not connected")}.bind(this))},r.prototype.addEventListener=f(["serviceadded","servicechanged","serviceremoved"]),r.prototype.removeEventListener=g,r.prototype.dispatchEvent=h;var s=function(a){this._handle=null,this._descriptors=null,this.service=null,this.uuid=null,this.properties={broadcast:!1,read:!1,writeWithoutResponse:!1,write:!1,notify:!1,indicate:!1,authenticatedSignedWrites:!1,reliableWrite:!1,writableAuxiliaries:!1},this.value=null,e(this,a)};s.prototype.getDescriptor=function(b){return new a(function(a,c){return this.service.device.gatt.connected?b?void this.getDescriptors(b).then(function(b){if(1!==b.length)return c("getDescriptor error: descriptor not found");a(b[0])}).catch(function(a){c(a)}):c("getDescriptor error: no descriptor specified"):c("getDescriptor error: device not connected")}.bind(this))},s.prototype.getDescriptors=function(b){return new a(function(a,e){function f(){if(!b)return a(this._descriptors);var d=this._descriptors.filter(function(a){return a.uuid===c.getDescriptorUUID(b)});if(1!==d.length)return e("getDescriptors error: descriptor not found");a(d)}return this.service.device.gatt.connected?this._descriptors?f.call(this):void m.discoverDescriptors(this._handle,[],function(a){this._descriptors=a.map(function(a){return a.characteristic=this,new t(a)}.bind(this)),f.call(this)}.bind(this),d(e,"getDescriptors error")):e("getDescriptors error: device not connected")}.bind(this))},s.prototype.readValue=function(){return new a(function(a,b){if(!this.service.device.gatt.connected)return b("readValue error: device not connected");m.readCharacteristic(this._handle,function(b){this.value=b,a(b),this.dispatchEvent({type:"characteristicvaluechanged",bubbles:!0})}.bind(this),d(b,"readValue error"))}.bind(this))},s.prototype.writeValue=function(b){return new a(function(a,c){if(!this.service.device.gatt.connected)return c("writeValue error: device not connected");var e=b.buffer||b,f=new DataView(e);m.writeCharacteristic(this._handle,f,function(){this.value=f,a()}.bind(this),d(c,"writeValue error"))}.bind(this))},s.prototype.startNotifications=function(){return new a(function(a,b){if(!this.service.device.gatt.connected)return b("startNotifications error: device not connected");m.enableNotify(this._handle,function(a){this.value=a,this.dispatchEvent({type:"characteristicvaluechanged",bubbles:!0})}.bind(this),function(){a(this)}.bind(this),d(b,"startNotifications error"))}.bind(this))},s.prototype.stopNotifications=function(){return new a(function(a,b){if(!this.service.device.gatt.connected)return b("stopNotifications error: device not connected");m.disableNotify(this._handle,function(){a(this)}.bind(this),d(b,"stopNotifications error"))}.bind(this))},s.prototype.addEventListener=f(["characteristicvaluechanged"]),s.prototype.removeEventListener=g,s.prototype.dispatchEvent=h;var t=function(a){this._handle=null,this.characteristic=null,this.uuid=null,this.value=null,e(this,a)};return t.prototype.readValue=function(){return new a(function(a,b){if(!this.characteristic.service.device.gatt.connected)return b("readValue error: device not connected");m.readDescriptor(this._handle,function(b){this.value=b,a(b)}.bind(this),d(b,"readValue error"))}.bind(this))},t.prototype.writeValue=function(b){return new a(function(a,c){if(!this.characteristic.service.device.gatt.connected)return c("writeValue error: device not connected");var e=b.buffer||b,f=new DataView(e);m.writeDescriptor(this._handle,f,function(){this.value=f,a()}.bind(this),d(c,"writeValue error"))}.bind(this))},{_addAdapter:function(a,b){n[a]=b,m=b},requestDevice:j,cancelRequest:k}}),function(a,b){"function"==typeof define&&define.amd?define(["bleat","bluetooth.helpers"],b.bind(this,a)):"object"==typeof exports?module.exports=function(c){return b(a,c,require("./bluetooth.helpers"))}:b(a,a.bleat,a.bleatHelpers)}(this,function(a,b,c){"use strict";function d(b){a.evothings&&evothings.ble?b():document.addEventListener("deviceready",b)}function e(a){var b=x[a];b&&(evothings.ble.close(b),delete x[a],f(b,y),f(b,z,!0),f(b,A))}function f(a,b,c){for(var d in b)a===b[d]&&(delete b[d],c&&B[d]&&delete B[d])}function g(a,b){var c=x[a];return c||(b&&b("Device does not exist for device id: "+a),null)}function h(a,b){var c=y[a];return c||(b&&b("Device does not exist for service handle: "+a),null)}function i(a,b){var c=z[a];return c||(b&&b("Device does not exist for characteristic handle: "+a),null)}function j(a,b,c,d){function e(b){evothings.ble.writeDescriptor(a,b,new Uint8Array([1,0]),function(){c()},function(a){d(a)})}function f(){w.discoverDescriptors(b,"00002902-0000-1000-8000-00805f9b34fb",function(a){var c=B[b];c?e(c):d("Could not find CCCD for characteristic: "+b)},function(a){d(a)})}var g=B[b];g?e(g):f()}function k(a){var b={};return b._handle=a.address,b.id=a.address,b.name=a.name,b.uuids=[],b.adData={},b.adData.rssi=a.rssi,b.adData.txPower=null,b.adData.serviceData={},b.adData.manufacturerData=null,a.advertisementData?l(a,b):a.scanRecord&&m(a,b),b}function l(a,b){if(a.advertisementData){if(a.advertisementData.kCBAdvDataLocalName&&(b.name=a.advertisementData.kCBAdvDataLocalName),a.advertisementData.kCBAdvDataTxPowerLevel&&(b.adData.txPower=a.advertisementData.kCBAdvDataTxPowerLevel),a.advertisementData.kCBAdvDataServiceUUIDs&&a.advertisementData.kCBAdvDataServiceUUIDs.forEach(function(a){b.uuids.push(c.getCanonicalUUID(a))}),a.advertisementData.kCBAdvDataServiceData)for(var d in a.advertisementData.kCBAdvDataServiceData){var e=a.advertisementData.kCBAdvDataServiceData[d];b.adData.serviceData[c.getCanonicalUUID(d)]=t(o(e))}a.advertisementData.kCBAdvDataManufacturerData&&(b.adData.manufacturerDataRaw=a.advertisementData.kCBAdvDataManufacturerData)}}function m(a,b){for(var d=o(a.scanRecord),e=0;e<d.length;){var f=d[e++];if(0===f)break;f-=1;var g,h=d[e++];if(8===h||9===h)b.name=evothings.ble.fromUtf8(new Uint8Array(d.buffer,e,f)).replace("\0","");else if(10===h)b.adData.txPower=p(d,e);else if(2===h||3===h)for(g=0;g<f;g+=2)b.uuids.push(c.getCanonicalUUID(q(d,e+g).toString(16)));else if(4===h||5===h)for(g=0;g<f;g+=4)b.uuids.push(c.getCanonicalUUID(r(d,e+g).toString(16)));else if(6===h||7===h)for(g=0;g<f;g+=16)b.uuids.push(c.getCanonicalUUID(s(d,e+g)));e+=f}}function n(a){return a>64&&a<91?a-65:a>96&&a<123?a-71:a>47&&a<58?a+4:43===a?62:47===a?63:0}function o(a,b){for(var c,d,e=a.replace(/[^A-Za-z0-9\+\/]/g,""),f=e.length,g=b?Math.ceil((3*f+1>>2)/b)*b:3*f+1>>2,h=new Uint8Array(g),i=0,j=0,k=0;k<f;k++)if(d=3&k,i|=n(e.charCodeAt(k))<<18-6*d,3===d||f-k==1){for(c=0;c<3&&j<g;c++,j++)h[j]=i>>>(16>>>c&24)&255;i=0}return h}function p(a,b){var c=a[b];return 128&c&&(c-=256),c}function q(a,b){return(a[b+1]<<8)+a[b]}function r(a,b){return(a[b+3]<<24)+(a[b+2]<<16)+(a[b+1]<<8)+a[b]}function s(a,b){for(var c="",d=0;d<16;d++)c+=("00"+a[b+d].toString(16)).slice(-2);return c}function t(a){var b=new Uint8Array(a).buffer;return new DataView(b)}function u(){return a.cordova?a.cordova.platformId:null}function v(){return"ios"===u()}if(b._addAdapter){var w={},x={},y={},z={},A={},B={};b._addAdapter("evothings",w),w.startScan=function(a,b,c,e){d(function(){evothings.ble.stopScan(),evothings.ble.startScan(a,function(a){b&&b(k(a))},function(a){e&&e(a)}),c&&c()})},w.stopScan=function(a){d(function(){evothings.ble.stopScan()})},w.connect=function(a,b,c,d){if(x[a])return void(d&&d("device already connected"));evothings.ble.connect(a,function(d){2===d.state&&b?(x[a]=d.deviceHandle,b()):0===d.state&&c&&(e(a),c())},function(a){d&&d(a)})},w.disconnect=function(a,b){e(a)},w.discoverServices=function(a,b,d,e){var f=g(a,e);f&&evothings.ble.services(f,function(a){var e=[];a.forEach(function(a){var d=c.getCanonicalUUID(a.uuid);(!b||0===b.length||b.indexOf(d)>=0)&&(y[a.handle]=f,e.push({_handle:a.handle,uuid:d,primary:!0}))}),d&&d(e)},function(a){e&&e(a)})},w.discoverIncludedServices=function(a,b,c,d){c([])},w.discoverCharacteristics=function(a,b,d,e){var f=h(a,e);f&&evothings.ble.characteristics(f,a,function(a){var e=[];a.forEach(function(a){var d=c.getCanonicalUUID(a.uuid);(!b||0===b.length||b.indexOf(d)>=0)&&(z[a.handle]=f,e.push({_handle:a.handle,uuid:d,properties:{broadcast:1&a.property,read:2&a.property,writeWithoutResponse:4&a.property&&1&a.writeType,write:8&a.property,notify:16&a.property,indicate:32&a.property,authenticatedSignedWrites:64&a.property&&4&a.writeType,reliableWrite:!1,writableAuxiliaries:!1}}))}),d&&d(e)},function(a){e&&e(a)})},w.discoverDescriptors=function(a,b,d,e){var f=i(a,e);f&&evothings.ble.descriptors(f,a,function(e){var g=[];e.forEach(function(d){var e=c.getCanonicalUUID(d.uuid);"00002902-0000-1000-8000-00805f9b34fb"===e&&(B[a]=d.handle),(!b||0===b.length||b.indexOf(e)>=0)&&(A[d.handle]=f,g.push({_handle:d.handle,uuid:e}))}),d&&d(g)},function(a){e&&e(a)})},w.readCharacteristic=function(a,b,c){var d=i(a,c);d&&evothings.ble.readCharacteristic(d,a,function(a){b&&b(t(a))},function(a){c&&c(a)})},w.writeCharacteristic=function(a,b,c,d){var e=i(a,d);e&&evothings.ble.writeCharacteristic(e,a,b,function(){c&&c()},function(a){d&&d(a)})},w.enableNotify=function(a,b,c,d){function e(){evothings.ble.enableNotification(f,a,function(a){b&&b(t(a))},function(a){d&&d(a)}),c&&c()}var f=i(a,d);f&&j(f,a,e,function(a){d&&d(a)})},w.disableNotify=function(a,b,c){var d=i(a,c);d&&(evothings.ble.disableNotification(d,a,function(){b&&b()},function(a){c&&c(a)}),v()&&setTimeout(b,0))},w.readDescriptor=function(a,b,c){var d=getDeviceHandleFromDescriptorHandle(a,c);d&&evothings.ble.readDescriptor(d,a,function(a){b&&b(t(a))},function(a){c&&c(a)})},w.writeDescriptor=function(a,b,c,d){var e=getDeviceHandleFromDescriptorHandle(a,d);e&&evothings.ble.writeDescriptor(e,a,b,function(){c&&c()},function(a){d&&d(a)})}}});

@@ -53,3 +53,3 @@ /* @license

*/
function(a,b){"function"==typeof define&&define.amd?a.navigator.bluetooth?define(a.navigator.bluetooth):define(["es6-promise","es6-map","bluetooth.helpers"],b):"object"==typeof exports?module.exports=b(Promise,Map,require("./bluetooth.helpers")):a.bleat=a.navigator.bluetooth||b(a.Promise,a.Map,a.bleatHelpers)}(this,function(a,b,c){"use strict";function d(a,b){return function(c){a(b+": "+c)}}function e(a,b){b&&Object.keys(b).forEach(function(c){b[c]&&a.hasOwnProperty(c)&&("[object Object]"===Object.prototype.toString.call(a[c])?e(a[c],b[c]):"[object Map]"===Object.prototype.toString.call(a[c])&&"[object Object]"===Object.prototype.toString.call(b[c])?Object.keys(b[c]).forEach(function(d){a[c].set(d,b[c][d])}):a[c]=b[c])})}function f(a){return function(b,c,d){a.indexOf(b)<0||(o[this]||(o[this]={}),o[this][b]||(o[this][b]=[]),o[this][b].push(c))}}function g(a,b,c){if(o[this]&&o[this][a]){var d=o[this][a].indexOf(b);d>=0&&o[this][a].splice(d,1),0===o[this][a].length&&delete o[this][a],0===Object.keys(o[this]).length&&delete o[this]}}function h(a){o[this]&&o[this][a.type]&&(a.target=this,o[this][a.type].forEach(function(b){"function"==typeof b&&b(a)}))}function i(a,b,d){var e=!1;return a.filters.forEach(function(a){if(!a.name||a.name===b.name){if(a.namePrefix){if(a.namePrefix.length>b.name.length)return;if(a.namePrefix!==b.name.substr(0,a.namePrefix.length))return}if(a.services){var f=a.services.map(c.getServiceUUID);if(!f.every(function(a){return b.uuids.indexOf(a)>-1}))return;d=d.concat(f)}e=!0}}),!!e&&b}function j(b){return new a(function(a,e){if(null!==p)return e("requestDevice error: request in progress");if(!b.acceptAllDevices&&!b.deviceFound){if(!b.filters||0===b.filters.length)return e(new TypeError("requestDevice error: no filters specified"));if(b.filters.some(function(a){return 0===Object.keys(a).length}))return e(new TypeError("requestDevice error: empty filter specified"));if(b.filters.some(function(a){return void 0!==a.namePrefix&&""===a.namePrefix}))return e(new TypeError("requestDevice error: empty namePrefix specified"))}var f=[];b.filters&&b.filters.forEach(function(a){a.services&&(f=f.concat(a.services.map(c.getServiceUUID)))}),f=f.filter(function(a,b,c){return c.indexOf(a)===b});var g=!1;m.startScan(f,function(d){function e(b){k().then(function(){a(b)})}function f(){e(j)}var h=[];if(b.filters&&(d=i(b,d,h)),d){g=!0,b.optionalServices&&(h=h.concat(b.optionalServices.map(c.getServiceUUID))),d._allowedServices=h.filter(function(a,b,c){return c.indexOf(a)===b});var j=new q(d);b.deviceFound&&!b.deviceFound(j,f)||e(j)}},function(){p=setTimeout(function(){k().then(function(){g||e("requestDevice error: no devices found")})},b.scanTime||l)},d(e,"requestDevice error"))})}function k(){return new a(function(a,b){p&&(clearTimeout(p),p=null,m.stopScan()),a()})}var l=10240,m=null,n={},o={},p=null,q=function(a){this._handle=null,this._allowedServices=[],this.id="unknown",this.name=null,this.adData={appearance:null,txPower:null,rssi:null,manufacturerData:new b,serviceData:new b},this.gatt=new r,this.gatt.device=this,this.uuids=[],e(this,a)};q.prototype.addEventListener=f(["gattserverdisconnected"]),q.prototype.removeEventListener=g,q.prototype.dispatchEvent=h;var r=function(){this._services=null,this.device=null,this.connected=!1};r.prototype.connect=function(){return new a(function(a,b){if(this.connected)return b("connect error: device already connected");m.connect(this.device._handle,function(){this.connected=!0,a(this)}.bind(this),function(){this._services=null,this.connected=!1,this.device.dispatchEvent({type:"gattserverdisconnected",bubbles:!0})}.bind(this),d(b,"connect error"))}.bind(this))},r.prototype.disconnect=function(){m.disconnect(this.device._handle),this.connected=!1},r.prototype.getPrimaryService=function(b){return new a(function(a,c){return this.connected?b?void this.getPrimaryServices(b).then(function(b){if(1!==b.length)return c("getPrimaryService error: service not found");a(b[0])}).catch(function(a){c(a)}):c("getPrimaryService error: no service specified"):c("getPrimaryService error: device not connected")}.bind(this))},r.prototype.getPrimaryServices=function(b){return new a(function(a,e){function f(){if(!b)return a(this._services);var d=this._services.filter(function(a){return a.uuid===c.getServiceUUID(b)});if(1!==d.length)return e("getPrimaryServices error: service not found");a(d)}return this.connected?this._services?f.call(this):void m.discoverServices(this.device._handle,this.device._allowedServices,function(a){this._services=a.map(function(a){return a.device=this.device,new s(a)}.bind(this)),f.call(this)}.bind(this),d(e,"getPrimaryServices error")):e("getPrimaryServices error: device not connected")}.bind(this))};var s=function(a){this._handle=null,this._services=null,this._characteristics=null,this.device=null,this.uuid=null,this.isPrimary=!1,e(this,a),this.dispatchEvent({type:"serviceadded",bubbles:!0})};s.prototype.getCharacteristic=function(b){return new a(function(a,c){return this.device.gatt.connected?b?void this.getCharacteristics(b).then(function(b){if(1!==b.length)return c("getCharacteristic error: characteristic not found");a(b[0])}).catch(function(a){c(a)}):c("getCharacteristic error: no characteristic specified"):c("getCharacteristic error: device not connected")}.bind(this))},s.prototype.getCharacteristics=function(b){return new a(function(a,e){function f(){if(!b)return a(this._characteristics);var d=this._characteristics.filter(function(a){return a.uuid===c.getCharacteristicUUID(b)});if(1!==d.length)return e("getCharacteristics error: characteristic not found");a(d)}return this.device.gatt.connected?this._characteristics?f.call(this):void m.discoverCharacteristics(this._handle,[],function(a){this._characteristics=a.map(function(a){return a.service=this,new t(a)}.bind(this)),f.call(this)}.bind(this),d(e,"getCharacteristics error")):e("getCharacteristics error: device not connected")}.bind(this))},s.prototype.getIncludedService=function(b){return new a(function(a,c){return this.device.gatt.connected?b?void this.getIncludedServices(b).then(function(b){if(1!==b.length)return c("getIncludedService error: service not found");a(b[0])}).catch(function(a){c(a)}):c("getIncludedService error: no service specified"):c("getIncludedService error: device not connected")}.bind(this))},s.prototype.getIncludedServices=function(b){return new a(function(a,e){function f(){if(!b)return a(this._services);var d=this._services.filter(function(a){return a.uuid===c.getServiceUUID(b)});if(1!==d.length)return e("getIncludedServices error: service not found");a(d)}return this.device.gatt.connected?this._services?f.call(this):void m.discoverIncludedServices(this._handle,this.device._allowedServices,function(a){this._services=a.map(function(a){return a.device=this.device,new s(a)}.bind(this)),f.call(this)}.bind(this),d(e,"getIncludedServices error")):e("getIncludedServices error: device not connected")}.bind(this))},s.prototype.addEventListener=f(["serviceadded","servicechanged","serviceremoved"]),s.prototype.removeEventListener=g,s.prototype.dispatchEvent=h;var t=function(a){this._handle=null,this._descriptors=null,this.service=null,this.uuid=null,this.properties={broadcast:!1,read:!1,writeWithoutResponse:!1,write:!1,notify:!1,indicate:!1,authenticatedSignedWrites:!1,reliableWrite:!1,writableAuxiliaries:!1},this.value=null,e(this,a)};t.prototype.getDescriptor=function(b){return new a(function(a,c){return this.service.device.gatt.connected?b?void this.getDescriptors(b).then(function(b){if(1!==b.length)return c("getDescriptor error: descriptor not found");a(b[0])}).catch(function(a){c(a)}):c("getDescriptor error: no descriptor specified"):c("getDescriptor error: device not connected")}.bind(this))},t.prototype.getDescriptors=function(b){return new a(function(a,e){function f(){if(!b)return a(this._descriptors);var d=this._descriptors.filter(function(a){return a.uuid===c.getDescriptorUUID(b)});if(1!==d.length)return e("getDescriptors error: descriptor not found");a(d)}return this.service.device.gatt.connected?this._descriptors?f.call(this):void m.discoverDescriptors(this._handle,[],function(a){this._descriptors=a.map(function(a){return a.characteristic=this,new u(a)}.bind(this)),f.call(this)}.bind(this),d(e,"getDescriptors error")):e("getDescriptors error: device not connected")}.bind(this))},t.prototype.readValue=function(){return new a(function(a,b){if(!this.service.device.gatt.connected)return b("readValue error: device not connected");m.readCharacteristic(this._handle,function(b){this.value=b,a(b),this.dispatchEvent({type:"characteristicvaluechanged",bubbles:!0})}.bind(this),d(b,"readValue error"))}.bind(this))},t.prototype.writeValue=function(b){return new a(function(a,c){if(!this.service.device.gatt.connected)return c("writeValue error: device not connected");var e=b.buffer||b,f=new DataView(e);m.writeCharacteristic(this._handle,f,function(){this.value=f,a()}.bind(this),d(c,"writeValue error"))}.bind(this))},t.prototype.startNotifications=function(){return new a(function(a,b){if(!this.service.device.gatt.connected)return b("startNotifications error: device not connected");m.enableNotify(this._handle,function(a){this.value=a,this.dispatchEvent({type:"characteristicvaluechanged",bubbles:!0})}.bind(this),a,d(b,"startNotifications error"))}.bind(this))},t.prototype.stopNotifications=function(){return new a(function(a,b){if(!this.service.device.gatt.connected)return b("stopNotifications error: device not connected");m.disableNotify(this._handle,a,d(b,"stopNotifications error"))}.bind(this))},t.prototype.addEventListener=f(["characteristicvaluechanged"]),t.prototype.removeEventListener=g,t.prototype.dispatchEvent=h;var u=function(a){this._handle=null,this.characteristic=null,this.uuid=null,this.value=null,e(this,a)};return u.prototype.readValue=function(){return new a(function(a,b){if(!this.characteristic.service.device.gatt.connected)return b("readValue error: device not connected");m.readDescriptor(this._handle,function(b){this.value=b,a(b)}.bind(this),d(b,"readValue error"))}.bind(this))},u.prototype.writeValue=function(b){return new a(function(a,c){if(!this.characteristic.service.device.gatt.connected)return c("writeValue error: device not connected");var e=b.buffer||b,f=new DataView(e);m.writeDescriptor(this._handle,f,function(){this.value=f,a()}.bind(this),d(c,"writeValue error"))}.bind(this))},{_addAdapter:function(a,b){n[a]=b,m=b},requestDevice:j,cancelRequest:k}}),/* @license
function(a,b){"function"==typeof define&&define.amd?a.navigator.bluetooth?define(a.navigator.bluetooth):define(["es6-promise","es6-map","bluetooth.helpers"],b):"object"==typeof exports?module.exports=b(Promise,Map,require("./bluetooth.helpers")):a.bleat=a.navigator.bluetooth||b(a.Promise,a.Map,a.bleatHelpers)}(this,function(a,b,c){"use strict";function d(a,b){return function(c){a(b+": "+c)}}function e(a,b){b&&Object.keys(b).forEach(function(c){b[c]&&a.hasOwnProperty(c)&&("[object Object]"===Object.prototype.toString.call(a[c])?e(a[c],b[c]):"[object Map]"===Object.prototype.toString.call(a[c])&&"[object Object]"===Object.prototype.toString.call(b[c])?Object.keys(b[c]).forEach(function(d){a[c].set(d,b[c][d])}):a[c]=b[c])})}function f(a){return function(b,c,d){a.indexOf(b)<0||(this.__events||(this.__events={}),this.__events[b]||(this.__events[b]=[]),this.__events[b].push(c))}}function g(a,b,c){if(this.__events&&this.__events[a]){var d=this.__events[a].indexOf(b);d>=0&&this.__events[a].splice(d,1),0===this.__events[a].length&&delete this.__events[a],0===Object.keys(this.__events).length&&delete this.__events}}function h(a){this.__events&&this.__events[a.type]&&(a.target=this,this.__events[a.type].forEach(function(b){"function"==typeof b&&b(a)}))}function i(a,b,d){var e=!1;return a.filters.forEach(function(a){if(!a.name||a.name===b.name){if(a.namePrefix){if(a.namePrefix.length>b.name.length)return;if(a.namePrefix!==b.name.substr(0,a.namePrefix.length))return}if(a.services){var f=a.services.map(c.getServiceUUID);if(!f.every(function(a){return b.uuids.indexOf(a)>-1}))return;d=d.concat(f)}e=!0}}),!!e&&b}function j(b){return new a(function(a,e){if(null!==o)return e("requestDevice error: request in progress");if(!b.acceptAllDevices&&!b.deviceFound){if(!b.filters||0===b.filters.length)return e(new TypeError("requestDevice error: no filters specified"));if(b.filters.some(function(a){return 0===Object.keys(a).length}))return e(new TypeError("requestDevice error: empty filter specified"));if(b.filters.some(function(a){return void 0!==a.namePrefix&&""===a.namePrefix}))return e(new TypeError("requestDevice error: empty namePrefix specified"))}var f=[];b.filters&&b.filters.forEach(function(a){a.services&&(f=f.concat(a.services.map(c.getServiceUUID)))}),f=f.filter(function(a,b,c){return c.indexOf(a)===b});var g=!1;m.startScan(f,function(d){function e(b){k().then(function(){a(b)})}function f(){e(j)}var h=[];if(b.filters&&(d=i(b,d,h)),d){g=!0,b.optionalServices&&(h=h.concat(b.optionalServices.map(c.getServiceUUID))),d._allowedServices=h.filter(function(a,b,c){return c.indexOf(a)===b});var j=new p(d);b.deviceFound&&!b.deviceFound(j,f)||e(j)}},function(){o=setTimeout(function(){k().then(function(){g||e("requestDevice error: no devices found")})},b.scanTime||l)},d(e,"requestDevice error"))})}function k(){return new a(function(a,b){o&&(clearTimeout(o),o=null,m.stopScan()),a()})}var l=10240,m=null,n={},o=null,p=function(a){this._handle=null,this._allowedServices=[],this.id="unknown",this.name=null,this.adData={appearance:null,txPower:null,rssi:null,manufacturerData:new b,serviceData:new b},this.gatt=new q,this.gatt.device=this,this.uuids=[],e(this,a)};p.prototype.addEventListener=f(["gattserverdisconnected"]),p.prototype.removeEventListener=g,p.prototype.dispatchEvent=h;var q=function(){this._services=null,this.device=null,this.connected=!1};q.prototype.connect=function(){return new a(function(a,b){if(this.connected)return b("connect error: device already connected");m.connect(this.device._handle,function(){this.connected=!0,a(this)}.bind(this),function(){this._services=null,this.connected=!1,this.device.dispatchEvent({type:"gattserverdisconnected",bubbles:!0})}.bind(this),d(b,"connect error"))}.bind(this))},q.prototype.disconnect=function(){m.disconnect(this.device._handle),this.connected=!1},q.prototype.getPrimaryService=function(b){return new a(function(a,c){return this.connected?b?void this.getPrimaryServices(b).then(function(b){if(1!==b.length)return c("getPrimaryService error: service not found");a(b[0])}).catch(function(a){c(a)}):c("getPrimaryService error: no service specified"):c("getPrimaryService error: device not connected")}.bind(this))},q.prototype.getPrimaryServices=function(b){return new a(function(a,e){function f(){if(!b)return a(this._services);var d=this._services.filter(function(a){return a.uuid===c.getServiceUUID(b)});if(1!==d.length)return e("getPrimaryServices error: service not found");a(d)}return this.connected?this._services?f.call(this):void m.discoverServices(this.device._handle,this.device._allowedServices,function(a){this._services=a.map(function(a){return a.device=this.device,new r(a)}.bind(this)),f.call(this)}.bind(this),d(e,"getPrimaryServices error")):e("getPrimaryServices error: device not connected")}.bind(this))};var r=function(a){this._handle=null,this._services=null,this._characteristics=null,this.device=null,this.uuid=null,this.isPrimary=!1,e(this,a),this.dispatchEvent({type:"serviceadded",bubbles:!0})};r.prototype.getCharacteristic=function(b){return new a(function(a,c){return this.device.gatt.connected?b?void this.getCharacteristics(b).then(function(b){if(1!==b.length)return c("getCharacteristic error: characteristic not found");a(b[0])}).catch(function(a){c(a)}):c("getCharacteristic error: no characteristic specified"):c("getCharacteristic error: device not connected")}.bind(this))},r.prototype.getCharacteristics=function(b){return new a(function(a,e){function f(){if(!b)return a(this._characteristics);var d=this._characteristics.filter(function(a){return a.uuid===c.getCharacteristicUUID(b)});if(1!==d.length)return e("getCharacteristics error: characteristic not found");a(d)}return this.device.gatt.connected?this._characteristics?f.call(this):void m.discoverCharacteristics(this._handle,[],function(a){this._characteristics=a.map(function(a){return a.service=this,new s(a)}.bind(this)),f.call(this)}.bind(this),d(e,"getCharacteristics error")):e("getCharacteristics error: device not connected")}.bind(this))},r.prototype.getIncludedService=function(b){return new a(function(a,c){return this.device.gatt.connected?b?void this.getIncludedServices(b).then(function(b){if(1!==b.length)return c("getIncludedService error: service not found");a(b[0])}).catch(function(a){c(a)}):c("getIncludedService error: no service specified"):c("getIncludedService error: device not connected")}.bind(this))},r.prototype.getIncludedServices=function(b){return new a(function(a,e){function f(){if(!b)return a(this._services);var d=this._services.filter(function(a){return a.uuid===c.getServiceUUID(b)});if(1!==d.length)return e("getIncludedServices error: service not found");a(d)}return this.device.gatt.connected?this._services?f.call(this):void m.discoverIncludedServices(this._handle,this.device._allowedServices,function(a){this._services=a.map(function(a){return a.device=this.device,new r(a)}.bind(this)),f.call(this)}.bind(this),d(e,"getIncludedServices error")):e("getIncludedServices error: device not connected")}.bind(this))},r.prototype.addEventListener=f(["serviceadded","servicechanged","serviceremoved"]),r.prototype.removeEventListener=g,r.prototype.dispatchEvent=h;var s=function(a){this._handle=null,this._descriptors=null,this.service=null,this.uuid=null,this.properties={broadcast:!1,read:!1,writeWithoutResponse:!1,write:!1,notify:!1,indicate:!1,authenticatedSignedWrites:!1,reliableWrite:!1,writableAuxiliaries:!1},this.value=null,e(this,a)};s.prototype.getDescriptor=function(b){return new a(function(a,c){return this.service.device.gatt.connected?b?void this.getDescriptors(b).then(function(b){if(1!==b.length)return c("getDescriptor error: descriptor not found");a(b[0])}).catch(function(a){c(a)}):c("getDescriptor error: no descriptor specified"):c("getDescriptor error: device not connected")}.bind(this))},s.prototype.getDescriptors=function(b){return new a(function(a,e){function f(){if(!b)return a(this._descriptors);var d=this._descriptors.filter(function(a){return a.uuid===c.getDescriptorUUID(b)});if(1!==d.length)return e("getDescriptors error: descriptor not found");a(d)}return this.service.device.gatt.connected?this._descriptors?f.call(this):void m.discoverDescriptors(this._handle,[],function(a){this._descriptors=a.map(function(a){return a.characteristic=this,new t(a)}.bind(this)),f.call(this)}.bind(this),d(e,"getDescriptors error")):e("getDescriptors error: device not connected")}.bind(this))},s.prototype.readValue=function(){return new a(function(a,b){if(!this.service.device.gatt.connected)return b("readValue error: device not connected");m.readCharacteristic(this._handle,function(b){this.value=b,a(b),this.dispatchEvent({type:"characteristicvaluechanged",bubbles:!0})}.bind(this),d(b,"readValue error"))}.bind(this))},s.prototype.writeValue=function(b){return new a(function(a,c){if(!this.service.device.gatt.connected)return c("writeValue error: device not connected");var e=b.buffer||b,f=new DataView(e);m.writeCharacteristic(this._handle,f,function(){this.value=f,a()}.bind(this),d(c,"writeValue error"))}.bind(this))},s.prototype.startNotifications=function(){return new a(function(a,b){if(!this.service.device.gatt.connected)return b("startNotifications error: device not connected");m.enableNotify(this._handle,function(a){this.value=a,this.dispatchEvent({type:"characteristicvaluechanged",bubbles:!0})}.bind(this),function(){a(this)}.bind(this),d(b,"startNotifications error"))}.bind(this))},s.prototype.stopNotifications=function(){return new a(function(a,b){if(!this.service.device.gatt.connected)return b("stopNotifications error: device not connected");m.disableNotify(this._handle,function(){a(this)}.bind(this),d(b,"stopNotifications error"))}.bind(this))},s.prototype.addEventListener=f(["characteristicvaluechanged"]),s.prototype.removeEventListener=g,s.prototype.dispatchEvent=h;var t=function(a){this._handle=null,this.characteristic=null,this.uuid=null,this.value=null,e(this,a)};return t.prototype.readValue=function(){return new a(function(a,b){if(!this.characteristic.service.device.gatt.connected)return b("readValue error: device not connected");m.readDescriptor(this._handle,function(b){this.value=b,a(b)}.bind(this),d(b,"readValue error"))}.bind(this))},t.prototype.writeValue=function(b){return new a(function(a,c){if(!this.characteristic.service.device.gatt.connected)return c("writeValue error: device not connected");var e=b.buffer||b,f=new DataView(e);m.writeDescriptor(this._handle,f,function(){this.value=f,a()}.bind(this),d(c,"writeValue error"))}.bind(this))},{_addAdapter:function(a,b){n[a]=b,m=b},requestDevice:j,cancelRequest:k}}),/* @license
*

@@ -80,2 +80,2 @@ * BLE Abstraction Tool: noble adapter

*/
function(a,b){"function"==typeof define&&define.amd?define(["noble","bleat","bluetooth.helpers"],b):"object"==typeof exports?module.exports=function(a){return b(require("noble"),a,require("./bluetooth.helpers"))}:b(a.noble,a.bleat,a.bleatHelpers)}(this,function(a,b,c){"use strict";function d(a,b){return function(c){if(c)a(c);else if("function"==typeof b){var d=[].slice.call(arguments,1);b.apply(this,d)}}}function e(a){var b=new Uint8Array(a).buffer;return new DataView(b)}function f(a){var b=new Uint8Array(a.buffer);return new Buffer(b)}a&&b._addAdapter("noble",{deviceHandles:{},serviceHandles:{},characteristicHandles:{},descriptorHandles:{},charNotifies:{},foundFn:null,initialised:!1,init:function(b,d){if(this.initialised)return b();a.on("discover",function(a){if(this.foundFn){var b=a.address&&"unknown"!==a.address?a.address:a.id;this.deviceHandles[b]||(this.deviceHandles[b]=a);var d=[];a.advertisement.serviceUuids&&a.advertisement.serviceUuids.forEach(function(a){d.push(c.getCanonicalUUID(a))});var f={};if(a.advertisement.manufacturerData){var g=a.advertisement.manufacturerData.readUInt16LE(0);g=("0000"+g.toString(16)).slice(-4);var h=a.advertisement.manufacturerData.slice(2);f[g]=e(h)}var i={};a.advertisement.serviceData&&a.advertisement.serviceData.forEach(function(a){i[c.getCanonicalUUID(a.uuid)]=e(a.data)}),this.foundFn({_handle:b,id:b,name:a.advertisement.localName,uuids:d,adData:{manufacturerData:f,serviceData:i,txPower:a.advertisement.txPowerLevel,rssi:a.rssi}})}}.bind(this)),this.initialised=!0,b()},startScan:function(b,c,e,f){this.init(function(){this.deviceHandles={};var g=function(g){"poweredOn"===g?(0===b.length?this.foundFn=c:this.foundFn=function(a){b.forEach(function(b){if(a.uuids.indexOf(b)>=0)return void c(a)})},a.startScanning([],!1,d(f,e))):f("adapter not enabled")}.bind(this);"unknown"===a.state?a.once("stateChange",g.bind(this)):g(a.state)}.bind(this),f)},stopScan:function(b){this.foundFn=null,a.stopScanning()},connect:function(a,b,c,e){var f=this.deviceHandles[a];f.once("connect",b),f.once("disconnect",function(){this.serviceHandles={},this.characteristicHandles={},this.descriptorHandles={},this.charNotifies={},c()}.bind(this)),f.connect(d(e))},disconnect:function(a,b){this.deviceHandles[a].disconnect(d(b))},discoverServices:function(a,b,e,f){this.deviceHandles[a].discoverServices([],d(f,function(a){var d=[];a.forEach(function(a){var e=c.getCanonicalUUID(a.uuid);(0===b.length||b.indexOf(e)>=0)&&(this.serviceHandles[e]||(this.serviceHandles[e]=a),d.push({_handle:e,uuid:e,primary:!0}))},this),e(d)}.bind(this)))},discoverIncludedServices:function(a,b,e,f){this.serviceHandles[a].discoverIncludedServices([],d(f,function(a){var d=[];a.forEach(function(a){var e=c.getCanonicalUUID(a.uuid);(0===b.length||b.indexOf(e)>=0)&&(this.serviceHandles[e]||(this.serviceHandles[e]=a),d.push({_handle:e,uuid:e,primary:!1}))},this),e(d)}.bind(this)))},discoverCharacteristics:function(a,b,f,g){this.serviceHandles[a].discoverCharacteristics([],d(g,function(a){var d=[];a.forEach(function(a){var f=c.getCanonicalUUID(a.uuid);(0===b.length||b.indexOf(f)>=0)&&(this.characteristicHandles[f]||(this.characteristicHandles[f]=a),d.push({_handle:f,uuid:f,properties:{broadcast:a.properties.indexOf("broadcast")>=0,read:a.properties.indexOf("read")>=0,writeWithoutResponse:a.properties.indexOf("writeWithoutResponse")>=0,write:a.properties.indexOf("write")>=0,notify:a.properties.indexOf("notify")>=0,indicate:a.properties.indexOf("indicate")>=0,authenticatedSignedWrites:a.properties.indexOf("authenticatedSignedWrites")>=0,reliableWrite:a.properties.indexOf("reliableWrite")>=0,writableAuxiliaries:a.properties.indexOf("writableAuxiliaries")>=0}}),a.on("data",function(a,b){if(!0===b&&"function"==typeof this.charNotifies[f]){var c=e(a);this.charNotifies[f](c)}}.bind(this)))},this),f(d)}.bind(this)))},discoverDescriptors:function(a,b,e,f){var g=this.characteristicHandles[a];g.discoverDescriptors(d(f,function(a){var d=[];a.forEach(function(a){var e=c.getCanonicalUUID(a.uuid);if(0===b.length||b.indexOf(e)>=0){var f=g.uuid+"-"+a.uuid;this.descriptorHandles[f]||(this.descriptorHandles[f]=a),d.push({_handle:f,uuid:e})}},this),e(d)}.bind(this)))},readCharacteristic:function(a,b,c){this.characteristicHandles[a].read(d(c,function(a){var c=e(a);b(c)}))},writeCharacteristic:function(a,b,c,e){var g=f(b);this.characteristicHandles[a].write(g,!0,d(e,c))},enableNotify:function(a,b,c,e){if(this.charNotifies[a])return this.charNotifies[a]=b,c();this.characteristicHandles[a].once("notify",function(d){if(!0!==d)return e("notify failed to enable");this.charNotifies[a]=b,c()}.bind(this)),this.characteristicHandles[a].notify(!0,d(e))},disableNotify:function(a,b,c){if(!this.charNotifies[characteristic.uuid])return b();this.characteristicHandles[a].once("notify",function(d){if(!1!==d)return c("notify failed to disable");this.charNotifies[a]&&delete this.charNotifies[a],b()}.bind(this)),this.characteristicHandles[a].notify(!1,d(c))},readDescriptor:function(a,b,c){this.descriptorHandles[a].readValue(d(c,function(a){var c=e(a);b(c)}))},writeDescriptor:function(a,b,c,e){var g=f(b);this.descriptorHandles[a].writeValue(g,d(e,c))}})});
function(a,b){"function"==typeof define&&define.amd?define(["noble","bleat","bluetooth.helpers"],b):"object"==typeof exports?module.exports=function(a){return b(require("noble"),a,require("./bluetooth.helpers"))}:b(a.noble,a.bleat,a.bleatHelpers)}(this,function(a,b,c){"use strict";function d(a,b){return function(c){if(c)a(c);else if("function"==typeof b){var d=[].slice.call(arguments,1);b.apply(this,d)}}}function e(a){var b=new Uint8Array(a).buffer;return new DataView(b)}function f(a){var b=new Uint8Array(a.buffer);return new Buffer(b)}b._addAdapter&&a&&b._addAdapter("noble",{deviceHandles:{},serviceHandles:{},characteristicHandles:{},descriptorHandles:{},charNotifies:{},foundFn:null,initialised:!1,init:function(b,d){if(this.initialised)return b();a.on("discover",function(a){if(this.foundFn){var b=a.address&&"unknown"!==a.address?a.address:a.id;this.deviceHandles[b]||(this.deviceHandles[b]=a);var d=[];a.advertisement.serviceUuids&&a.advertisement.serviceUuids.forEach(function(a){d.push(c.getCanonicalUUID(a))});var f={};if(a.advertisement.manufacturerData){var g=a.advertisement.manufacturerData.readUInt16LE(0);g=("0000"+g.toString(16)).slice(-4);var h=a.advertisement.manufacturerData.slice(2);f[g]=e(h)}var i={};a.advertisement.serviceData&&a.advertisement.serviceData.forEach(function(a){i[c.getCanonicalUUID(a.uuid)]=e(a.data)}),this.foundFn({_handle:b,id:b,name:a.advertisement.localName,uuids:d,adData:{manufacturerData:f,serviceData:i,txPower:a.advertisement.txPowerLevel,rssi:a.rssi}})}}.bind(this)),this.initialised=!0,b()},startScan:function(b,c,e,f){this.init(function(){this.deviceHandles={};var g=function(g){"poweredOn"===g?(0===b.length?this.foundFn=c:this.foundFn=function(a){b.forEach(function(b){if(a.uuids.indexOf(b)>=0)return void c(a)})},a.startScanning([],!1,d(f,e))):f("adapter not enabled")}.bind(this);"unknown"===a.state?a.once("stateChange",g.bind(this)):g(a.state)}.bind(this),f)},stopScan:function(b){this.foundFn=null,a.stopScanning()},connect:function(a,b,c,e){var f=this.deviceHandles[a];f.once("connect",b),f.once("disconnect",function(){this.serviceHandles={},this.characteristicHandles={},this.descriptorHandles={},this.charNotifies={},c()}.bind(this)),f.connect(d(e))},disconnect:function(a,b){this.deviceHandles[a].disconnect(d(b))},discoverServices:function(a,b,e,f){this.deviceHandles[a].discoverServices([],d(f,function(a){var d=[];a.forEach(function(a){var e=c.getCanonicalUUID(a.uuid);(0===b.length||b.indexOf(e)>=0)&&(this.serviceHandles[e]||(this.serviceHandles[e]=a),d.push({_handle:e,uuid:e,primary:!0}))},this),e(d)}.bind(this)))},discoverIncludedServices:function(a,b,e,f){this.serviceHandles[a].discoverIncludedServices([],d(f,function(a){var d=[];a.forEach(function(a){var e=c.getCanonicalUUID(a.uuid);(0===b.length||b.indexOf(e)>=0)&&(this.serviceHandles[e]||(this.serviceHandles[e]=a),d.push({_handle:e,uuid:e,primary:!1}))},this),e(d)}.bind(this)))},discoverCharacteristics:function(a,b,f,g){this.serviceHandles[a].discoverCharacteristics([],d(g,function(a){var d=[];a.forEach(function(a){var f=c.getCanonicalUUID(a.uuid);(0===b.length||b.indexOf(f)>=0)&&(this.characteristicHandles[f]||(this.characteristicHandles[f]=a),d.push({_handle:f,uuid:f,properties:{broadcast:a.properties.indexOf("broadcast")>=0,read:a.properties.indexOf("read")>=0,writeWithoutResponse:a.properties.indexOf("writeWithoutResponse")>=0,write:a.properties.indexOf("write")>=0,notify:a.properties.indexOf("notify")>=0,indicate:a.properties.indexOf("indicate")>=0,authenticatedSignedWrites:a.properties.indexOf("authenticatedSignedWrites")>=0,reliableWrite:a.properties.indexOf("reliableWrite")>=0,writableAuxiliaries:a.properties.indexOf("writableAuxiliaries")>=0}}),a.on("data",function(a,b){if(!0===b&&"function"==typeof this.charNotifies[f]){var c=e(a);this.charNotifies[f](c)}}.bind(this)))},this),f(d)}.bind(this)))},discoverDescriptors:function(a,b,e,f){var g=this.characteristicHandles[a];g.discoverDescriptors(d(f,function(a){var d=[];a.forEach(function(a){var e=c.getCanonicalUUID(a.uuid);if(0===b.length||b.indexOf(e)>=0){var f=g.uuid+"-"+a.uuid;this.descriptorHandles[f]||(this.descriptorHandles[f]=a),d.push({_handle:f,uuid:e})}},this),e(d)}.bind(this)))},readCharacteristic:function(a,b,c){this.characteristicHandles[a].read(d(c,function(a){var c=e(a);b(c)}))},writeCharacteristic:function(a,b,c,e){var g=f(b);this.characteristicHandles[a].write(g,!0,d(e,c))},enableNotify:function(a,b,c,e){if(this.charNotifies[a])return this.charNotifies[a]=b,c();this.characteristicHandles[a].once("notify",function(d){if(!0!==d)return e("notify failed to enable");this.charNotifies[a]=b,c()}.bind(this)),this.characteristicHandles[a].notify(!0,d(e))},disableNotify:function(a,b,c){if(!this.charNotifies[characteristic.uuid])return b();this.characteristicHandles[a].once("notify",function(d){if(!1!==d)return c("notify failed to disable");this.charNotifies[a]&&delete this.charNotifies[a],b()}.bind(this)),this.characteristicHandles[a].notify(!1,d(c))},readDescriptor:function(a,b,c){this.descriptorHandles[a].readValue(d(c,function(a){var c=e(a);b(c)}))},writeDescriptor:function(a,b,c,e){var g=f(b);this.descriptorHandles[a].writeValue(g,d(e,c))}})});

@@ -26,24 +26,26 @@ var bluetooth = require('../index').webbluetooth;

.then(services => {
return services.reduce((promise, service) => {
return promise
.then(() => service.getCharacteristics())
var sPromises = services.map(service => {
return service.getCharacteristics()
.then(characteristics => {
console.log("\nservice: " + service.uuid);
return characteristics.reduce((promise, characteristic) => {
return promise
.then(() => characteristic.getDescriptors())
var cPromises = characteristics.map(characteristic => {
return characteristic.getDescriptors()
.then(descriptors => {
console.log("\t└characteristic: " + characteristic.uuid);
descriptors.forEach(descriptor => {
console.log("\t\t└descriptor: " + descriptor.uuid);
});
descriptors = descriptors.map(descriptor => `\t\t└descriptor: ${descriptor.uuid}`);
descriptors.unshift(`\t└characteristic: ${characteristic.uuid}`);
return descriptors.join("\n");
});
}, Promise.resolve());
});
return Promise.all(cPromises)
.then(descriptors => {
descriptors.unshift(`service: ${service.uuid}`);
return descriptors.join("\n");
});
});
}, Promise.resolve());
});
return Promise.all(sPromises)
.then(services => {
console.log(services.join("\n"));
});
});

@@ -50,0 +52,0 @@ }

{
"name": "bleat",
"version": "0.1.3",
"version": "0.1.4",
"description": "Abstraction library following Web Bluetooth specification for hiding differences in JavaScript BLE APIs",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/thegecko/bleat",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc