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.0.5 to 0.0.6

39

dist/bleat.chromeos.js
/* @license
*
* BLE Abstraction Tool: chromeos adapter
* Version: 0.0.1
* Version: 0.0.2
*

@@ -44,18 +44,19 @@ * The MIT License (MIT)

function checkForError(errorFn, continueFn) {
return function() {
if (chrome.runtime.lastError) {
errorFn(chrome.runtime.lastError.message);
return;
}
if (typeof continueFn === "function") {
var args = [].slice.call(arguments);
continueFn.apply(this, args);
}
};
}
// https://developer.chrome.com/apps/bluetoothLowEnergy
bleat.addAdapter("chromeos", (function() {
function checkForError(errorFn, continueFn) {
return function() {
if (chrome.runtime.lastError) {
errorFn(chrome.runtime.lastError.message);
return;
}
if (typeof continueFn === "function") {
var args = [].slice.call(arguments);
continueFn.apply(this, args);
}
};
}
if (root.chrome && root.chrome.bluetooth && root.chrome.bluetoothLowEnergy) {
return {
bleat.addAdapter("chromeos", {
charNotifies: {},

@@ -65,6 +66,2 @@ deviceDisconnects: {},

init: function(readyFn, errorFn) {
if (!root.chrome || !root.chrome.bluetooth || !root.chrome.bluetoothLowEnergy) {
errorFn("chrome ble not found");
return;
}
chrome.bluetooth.getAdapterState(checkForError(errorFn, function(adapterInfo) {

@@ -174,4 +171,4 @@ chrome.bluetooth.onDeviceAdded.addListener(function(deviceInfo) {

}
};
})());
});
}
}));
/* @license
*
* BLE Abstraction Tool: evothings adapter
* Version: 0.0.1
* Version: 0.0.2
*

@@ -46,64 +46,65 @@ * The MIT License (MIT)

// https://github.com/evothings/cordova-ble/blob/master/ble.js
bleat.addAdapter("evothings", (function() {
function arrayToUUID(array, offset) {
var uuid = "";
var pointer = 0;
[4, 2, 2, 2, 6].forEach(function(length) {
uuid += '-';
for (var i = 0; i < length; i++, pointer++) {
uuid += evothings.util.toHexString(array[offset + pointer], 1);
}
});
return uuid.substr(1);
}
function arrayToUUID(array, offset) {
var uuid = "";
var pointer = 0;
[4, 2, 2, 2, 6].forEach(function(length) {
uuid += '-';
for (var i = 0; i < length; i++, pointer++) {
uuid += evothings.util.toHexString(array[offset + pointer], 1);
}
});
return uuid.substr(1);
}
function parseAdvert(deviceInfo) {
var advert = {
name: deviceInfo.name,
serviceUUIDs: []
};
function parseAdvert(deviceInfo) {
var advert = {
name: deviceInfo.name,
serviceUUIDs: []
};
if (deviceInfo.advertisementData) {
if (deviceInfo.advertisementData.kCBAdvDataLocalName) advert.name = deviceInfo.advertisementData.kCBAdvDataLocalName;
if (deviceInfo.advertisementData.kCBAdvDataServiceUUIDs) {
deviceInfo.advertisementData.kCBAdvDataServiceUUIDs.forEach(function(serviceUUID) {
if (serviceUUID.length > 8) advert.serviceUUIDs.push(serviceUUID.toLowerCase());
else advert.serviceUUIDs.push(("0000000" + serviceUUID.toLowerCase()).slice(-8) + BLUETOOTH_BASE_UUID);
});
}
} else if (deviceInfo.scanRecord) {
if (deviceInfo.advertisementData) {
if (deviceInfo.advertisementData.kCBAdvDataLocalName) advert.name = deviceInfo.advertisementData.kCBAdvDataLocalName;
if (deviceInfo.advertisementData.kCBAdvDataServiceUUIDs) {
deviceInfo.advertisementData.kCBAdvDataServiceUUIDs.forEach(function(serviceUUID) {
if (serviceUUID.length > 8) advert.serviceUUIDs.push(serviceUUID.toLowerCase());
else advert.serviceUUIDs.push(("0000000" + serviceUUID.toLowerCase()).slice(-8) + BLUETOOTH_BASE_UUID);
});
}
} else if (deviceInfo.scanRecord) {
var byteArray = evothings.util.base64DecToArr(device.scanRecord);
var pos = 0;
while (pos < byteArray.length) {
var byteArray = evothings.util.base64DecToArr(device.scanRecord);
var pos = 0;
while (pos < byteArray.length) {
var length = byteArray[pos++];
if (length === 0) break;
length -= 1;
var type = byteArray[pos++];
var i;
var length = byteArray[pos++];
if (length === 0) break;
length -= 1;
var type = byteArray[pos++];
var i;
if (type == 0x02 || type == 0x03) { // 16-bit Service Class UUIDs
for (i = 0; i < length; i += 2) {
advert.serviceUUIDs.push("0000" + evothings.util.toHexString(evothings.util.littleEndianToUint16(byteArray, pos + i), 2) + BLUETOOTH_BASE_UUID);
}
} else if (type == 0x04 || type == 0x05) { // 32-bit Service Class UUIDs
for (i = 0; i < length; i += 4) {
advert.serviceUUIDs.push(evothings.util.toHexString(evothings.util.littleEndianToUint32(byteArray, pos + i), 4) + BLUETOOTH_BASE_UUID);
}
} else if (type == 0x06 || type == 0x07) { // 128-bit Service Class UUIDs
for (i = 0; i < length; i += 4) {
advert.serviceUUIDs.push(arrayToUUID(byteArray, pos + i));
}
} else if (type == 0x08 || type == 0x09) { // Local Name
advert.name = evothings.ble.fromUtf8(new Uint8Array(byteArray.buffer, pos, length));
if (type == 0x02 || type == 0x03) { // 16-bit Service Class UUIDs
for (i = 0; i < length; i += 2) {
advert.serviceUUIDs.push("0000" + evothings.util.toHexString(evothings.util.littleEndianToUint16(byteArray, pos + i), 2) + BLUETOOTH_BASE_UUID);
}
pos += length;
} else if (type == 0x04 || type == 0x05) { // 32-bit Service Class UUIDs
for (i = 0; i < length; i += 4) {
advert.serviceUUIDs.push(evothings.util.toHexString(evothings.util.littleEndianToUint32(byteArray, pos + i), 4) + BLUETOOTH_BASE_UUID);
}
} else if (type == 0x06 || type == 0x07) { // 128-bit Service Class UUIDs
for (i = 0; i < length; i += 4) {
advert.serviceUUIDs.push(arrayToUUID(byteArray, pos + i));
}
} else if (type == 0x08 || type == 0x09) { // Local Name
advert.name = evothings.ble.fromUtf8(new Uint8Array(byteArray.buffer, pos, length));
}
pos += length;
}
return advert;
}
return advert;
}
return {
// https://github.com/evothings/cordova-ble/blob/master/ble.js
if (root.evothings || root.cordova) {
bleat.addAdapter("evothings", {
deviceHandles: {},

@@ -113,6 +114,2 @@ characteristicHandles: {},

init: function(readyFn, errorFn) {
if (!root.evothings && !root.cordova) {
errorFn("evothings not found");
return;
}
if (root.evothings && evothings.ble) readyFn();

@@ -190,4 +187,4 @@ else document.addEventListener("deviceready", readyFn);

}
};
})());
});
}
}));
/* @license
*
* BLE Abstraction Tool
* Version: 0.0.5
* Version: 0.0.6
*

@@ -6,0 +6,0 @@ * The MIT License (MIT)

/* @license
*
* BLE Abstraction Tool
* Version: 0.0.5
* Version: 0.0.6
*

@@ -31,3 +31,3 @@ * The MIT License (MIT)

* BLE Abstraction Tool: chromeos adapter
* Version: 0.0.1
* Version: 0.0.2
*

@@ -56,6 +56,6 @@ * The MIT License (MIT)

*/
function(a,b){"function"==typeof define&&define.amd?define([a,"bleat"],b):"object"==typeof exports?module.exports=b(a,require("bleat")):b(a,a.bleat)}(this,function(a,b){"use strict";b.addAdapter("chromeos",function(){function c(a,b){return function(){if(chrome.runtime.lastError)return void a(chrome.runtime.lastError.message);if("function"==typeof b){var c=[].slice.call(arguments);b.apply(this,c)}}}return{charNotifies:{},deviceDisconnects:{},foundFn:null,init:function(d,e){return a.chrome&&a.chrome.bluetooth&&a.chrome.bluetoothLowEnergy?void chrome.bluetooth.getAdapterState(c(e,function(a){chrome.bluetooth.onDeviceAdded.addListener(function(a){if(this.foundFn){var c=new b.Device(a.address,a.name,a.uuids||[]);this.foundFn(c)}}),chrome.bluetoothLowEnergy.onCharacteristicValueChanged.addListener(function(a){"function"==typeof this.charNotifies[a.instanceId]&&(this.charNotifies[a.instanceId](a.value),delete this.charNotifies[a.instanceId])}),chrome.bluetooth.onDeviceRemoved.addListener(this.checkDisconnect),chrome.bluetooth.onDeviceChanged.addListener(function(a){a.connected===!1&&checkDisconnect(a)}),a.available?d():e("adapter not enabled")})):void e("chrome ble not found")},checkDisconnect:function(a){"function"==typeof this.deviceDisconnects[a.address]&&(this.deviceDisconnects[a.address](),delete this.deviceDisconnects[a.address])},scan:function(a,d){chrome.bluetooth.getDevices(c(d,function(c){c.forEach(function(c){var d=new b.Device(c.address,c.name,c.uuids||[]);a(d)})})),this.foundFn=a,chrome.bluetooth.startDiscovery(c(d))},stop:function(a){this.foundFn=null,chrome.bluetooth.stopDiscovery(c(a))},connect:function(a,d,e,f){chrome.bluetoothLowEnergy.connect(a.address,null,c(f,function(){this.deviceDisconnects[a.address]=function(){a.connected=!1,a.services={},e()},a.connected=!0,chrome.bluetoothLowEnergy.getServices(a.address,c(f,function(e){e.forEach(function(d){var e=new b.Service(d.uuid,d.instanceId,d.isPrimary);a.services[e.uuid]=e,chrome.bluetoothLowEnergy.getCharacteristics(e.handle,c(f,function(a){a.forEach(function(a){var d=new b.Characteristic(a.uuid,a.instanceId,a.properties);e.characteristics[d.uuid]=d,chrome.bluetoothLowEnergy.getDescriptors(d.handle,c(f,function(a){a.forEach(function(a){var c=new b.Descriptor(a.uuid,a.instanceId);d.descriptors[c.uuid]=c})}))})}))}),setTimeout(d,0)}))}))},disconnect:function(a,b){chrome.bluetoothLowEnergy.disconnect(a.address,c(b))},readCharacteristic:function(a,b,d){chrome.bluetoothLowEnergy.readCharacteristicValue(a.handle,c(d,function(a){b(a.value)}))},writeCharacteristic:function(a,b,d,e){chrome.bluetoothLowEnergy.writeCharacteristicValue(a.handle,b.buffer,c(e,d))},enableNotify:function(a,b,d){chrome.bluetoothLowEnergy.startCharacteristicNotifications(a.handle,null,c(d,function(){this.charNotifies[a.handle]=b}))},disableNotify:function(a,b,d){chrome.bluetoothLowEnergy.stopCharacteristicNotifications(a.handle,c(d,function(){this.charNotifies[a.handle]&&delete this.charNotifies[a.handle],b()}))},readDescriptor:function(a,b,d){chrome.bluetoothLowEnergy.readDescriptorValue(a.handle,c(d,function(a){b(a.value)}))},writeDescriptor:function(a,b,d,e){chrome.bluetoothLowEnergy.writeDescriptorValue(a.handle,b.buffer,c(e,d))}}}())}),/* @license
function(a,b){"function"==typeof define&&define.amd?define([a,"bleat"],b):"object"==typeof exports?module.exports=b(a,require("bleat")):b(a,a.bleat)}(this,function(a,b){"use strict";function c(a,b){return function(){if(chrome.runtime.lastError)return void a(chrome.runtime.lastError.message);if("function"==typeof b){var c=[].slice.call(arguments);b.apply(this,c)}}}a.chrome&&a.chrome.bluetooth&&a.chrome.bluetoothLowEnergy&&b.addAdapter("chromeos",{charNotifies:{},deviceDisconnects:{},foundFn:null,init:function(a,d){chrome.bluetooth.getAdapterState(c(d,function(c){chrome.bluetooth.onDeviceAdded.addListener(function(a){if(this.foundFn){var c=new b.Device(a.address,a.name,a.uuids||[]);this.foundFn(c)}}),chrome.bluetoothLowEnergy.onCharacteristicValueChanged.addListener(function(a){"function"==typeof this.charNotifies[a.instanceId]&&(this.charNotifies[a.instanceId](a.value),delete this.charNotifies[a.instanceId])}),chrome.bluetooth.onDeviceRemoved.addListener(this.checkDisconnect),chrome.bluetooth.onDeviceChanged.addListener(function(a){a.connected===!1&&checkDisconnect(a)}),c.available?a():d("adapter not enabled")}))},checkDisconnect:function(a){"function"==typeof this.deviceDisconnects[a.address]&&(this.deviceDisconnects[a.address](),delete this.deviceDisconnects[a.address])},scan:function(a,d){chrome.bluetooth.getDevices(c(d,function(c){c.forEach(function(c){var d=new b.Device(c.address,c.name,c.uuids||[]);a(d)})})),this.foundFn=a,chrome.bluetooth.startDiscovery(c(d))},stop:function(a){this.foundFn=null,chrome.bluetooth.stopDiscovery(c(a))},connect:function(a,d,e,f){chrome.bluetoothLowEnergy.connect(a.address,null,c(f,function(){this.deviceDisconnects[a.address]=function(){a.connected=!1,a.services={},e()},a.connected=!0,chrome.bluetoothLowEnergy.getServices(a.address,c(f,function(e){e.forEach(function(d){var e=new b.Service(d.uuid,d.instanceId,d.isPrimary);a.services[e.uuid]=e,chrome.bluetoothLowEnergy.getCharacteristics(e.handle,c(f,function(a){a.forEach(function(a){var d=new b.Characteristic(a.uuid,a.instanceId,a.properties);e.characteristics[d.uuid]=d,chrome.bluetoothLowEnergy.getDescriptors(d.handle,c(f,function(a){a.forEach(function(a){var c=new b.Descriptor(a.uuid,a.instanceId);d.descriptors[c.uuid]=c})}))})}))}),setTimeout(d,0)}))}))},disconnect:function(a,b){chrome.bluetoothLowEnergy.disconnect(a.address,c(b))},readCharacteristic:function(a,b,d){chrome.bluetoothLowEnergy.readCharacteristicValue(a.handle,c(d,function(a){b(a.value)}))},writeCharacteristic:function(a,b,d,e){chrome.bluetoothLowEnergy.writeCharacteristicValue(a.handle,b.buffer,c(e,d))},enableNotify:function(a,b,d){chrome.bluetoothLowEnergy.startCharacteristicNotifications(a.handle,null,c(d,function(){this.charNotifies[a.handle]=b}))},disableNotify:function(a,b,d){chrome.bluetoothLowEnergy.stopCharacteristicNotifications(a.handle,c(d,function(){this.charNotifies[a.handle]&&delete this.charNotifies[a.handle],b()}))},readDescriptor:function(a,b,d){chrome.bluetoothLowEnergy.readDescriptorValue(a.handle,c(d,function(a){b(a.value)}))},writeDescriptor:function(a,b,d,e){chrome.bluetoothLowEnergy.writeDescriptorValue(a.handle,b.buffer,c(e,d))}})}),/* @license
*
* BLE Abstraction Tool: evothings adapter
* Version: 0.0.1
* Version: 0.0.2
*

@@ -84,2 +84,2 @@ * The MIT License (MIT)

*/
function(a,b){"function"==typeof define&&define.amd?define([a,"bleat"],b):"object"==typeof exports?module.exports=b(a,require("bleat")):b(a,a.bleat)}(this,function(a,b){"use strict";var c="-0000-1000-8000-00805f9b34fb";b.addAdapter("evothings",function(){function d(a,b){var c="",d=0;return[4,2,2,2,6].forEach(function(e){c+="-";for(var f=0;e>f;f++,d++)c+=evothings.util.toHexString(a[b+d],1)}),c.substr(1)}function e(a){var b={name:a.name,serviceUUIDs:[]};if(a.advertisementData)a.advertisementData.kCBAdvDataLocalName&&(b.name=a.advertisementData.kCBAdvDataLocalName),a.advertisementData.kCBAdvDataServiceUUIDs&&a.advertisementData.kCBAdvDataServiceUUIDs.forEach(function(a){b.serviceUUIDs.push(a.length>8?a.toLowerCase():("0000000"+a.toLowerCase()).slice(-8)+c)});else if(a.scanRecord)for(var e=evothings.util.base64DecToArr(device.scanRecord),f=0;f<e.length;){var g=e[f++];if(0===g)break;g-=1;var h,i=e[f++];if(2==i||3==i)for(h=0;g>h;h+=2)b.serviceUUIDs.push("0000"+evothings.util.toHexString(evothings.util.littleEndianToUint16(e,f+h),2)+c);else if(4==i||5==i)for(h=0;g>h;h+=4)b.serviceUUIDs.push(evothings.util.toHexString(evothings.util.littleEndianToUint32(e,f+h),4)+c);else if(6==i||7==i)for(h=0;g>h;h+=4)b.serviceUUIDs.push(d(e,f+h));else(8==i||9==i)&&(b.name=evothings.ble.fromUtf8(new Uint8Array(e.buffer,f,g)));f+=g}return b}return{deviceHandles:{},characteristicHandles:{},descriptorHandles:{},init:function(b,c){return a.evothings||a.cordova?void(a.evothings&&evothings.ble?b():document.addEventListener("deviceready",b)):void c("evothings not found")},scan:function(a,c){evothings.ble.startScan(function(c){var d=e(c),f=new b.Device(c.address,d.name,d.serviceUUIDs);a(f)},c)},stop:function(a){evothings.ble.stopScan()},connect:function(a,c,d,e){evothings.ble.connect(a.address,function(f){0===f.state?(a.connected=!1,a.services={},this.deviceHandles[a.address]&&(evothings.ble.close(this.deviceHandles[a.address]),delete this.deviceHandles[a.address]),d()):2===f.state&&(a.connected=!0,this.deviceHandles[a.address]=f.deviceHandle,evothings.ble.readAllServiceData(f.deviceHandle,function(d){d.forEach(function(c){var d=new b.Service(c.uuid,c.handle,0===c.type);a.services[d.uuid]=d,c.characteristics.forEach(function(a){var c=[],e=new b.Characteristic(a.uuid,a.handle,c);d.characteristics[e.uuid]=e,this.characteristicHandles[a.handle]=f.deviceHandle,a.descriptors.forEach(function(a){var c=new b.Descriptor(a.uuid,a.handle);e.descriptors[c.uuid]=c,this.descriptorHandles[a.handle]=f.deviceHandle},this)},this)},this),c()}.bind(this),e))}.bind(this),e)},disconnect:function(a,b){this.deviceHandles[a.address]&&evothings.ble.close(this.deviceHandles[a.address])},readCharacteristic:function(a,b,c){evothings.ble.readCharacteristic(this.characteristicHandles[a.handle],a.handle,b,c)},writeCharacteristic:function(a,b,c,d){evothings.ble.writeCharacteristic(this.characteristicHandles[a.handle],a.handle,b,c,d)},enableNotify:function(a,b,c){evothings.ble.enableNotification(this.characteristicHandles[a.handle],a.handle,b,c)},disableNotify:function(a,b,c){evothings.ble.disableNotification(this.characteristicHandles[a.handle],a.handle,b,c)},readDescriptor:function(a,b,c){evothings.ble.readDescriptor(this.descriptorHandles[a.handle],a.handle,b,c)},writeDescriptor:function(a,b,c,d){evothings.ble.writeDescriptor(this.descriptorHandles[a.handle],a.handle,b,c,d)}}}())});
function(a,b){"function"==typeof define&&define.amd?define([a,"bleat"],b):"object"==typeof exports?module.exports=b(a,require("bleat")):b(a,a.bleat)}(this,function(a,b){"use strict";function c(a,b){var c="",d=0;return[4,2,2,2,6].forEach(function(e){c+="-";for(var f=0;e>f;f++,d++)c+=evothings.util.toHexString(a[b+d],1)}),c.substr(1)}function d(a){var b={name:a.name,serviceUUIDs:[]};if(a.advertisementData)a.advertisementData.kCBAdvDataLocalName&&(b.name=a.advertisementData.kCBAdvDataLocalName),a.advertisementData.kCBAdvDataServiceUUIDs&&a.advertisementData.kCBAdvDataServiceUUIDs.forEach(function(a){b.serviceUUIDs.push(a.length>8?a.toLowerCase():("0000000"+a.toLowerCase()).slice(-8)+e)});else if(a.scanRecord)for(var d=evothings.util.base64DecToArr(device.scanRecord),f=0;f<d.length;){var g=d[f++];if(0===g)break;g-=1;var h,i=d[f++];if(2==i||3==i)for(h=0;g>h;h+=2)b.serviceUUIDs.push("0000"+evothings.util.toHexString(evothings.util.littleEndianToUint16(d,f+h),2)+e);else if(4==i||5==i)for(h=0;g>h;h+=4)b.serviceUUIDs.push(evothings.util.toHexString(evothings.util.littleEndianToUint32(d,f+h),4)+e);else if(6==i||7==i)for(h=0;g>h;h+=4)b.serviceUUIDs.push(c(d,f+h));else(8==i||9==i)&&(b.name=evothings.ble.fromUtf8(new Uint8Array(d.buffer,f,g)));f+=g}return b}var e="-0000-1000-8000-00805f9b34fb";(a.evothings||a.cordova)&&b.addAdapter("evothings",{deviceHandles:{},characteristicHandles:{},descriptorHandles:{},init:function(b,c){a.evothings&&evothings.ble?b():document.addEventListener("deviceready",b)},scan:function(a,c){evothings.ble.startScan(function(c){var e=d(c),f=new b.Device(c.address,e.name,e.serviceUUIDs);a(f)},c)},stop:function(a){evothings.ble.stopScan()},connect:function(a,c,d,e){evothings.ble.connect(a.address,function(f){0===f.state?(a.connected=!1,a.services={},this.deviceHandles[a.address]&&(evothings.ble.close(this.deviceHandles[a.address]),delete this.deviceHandles[a.address]),d()):2===f.state&&(a.connected=!0,this.deviceHandles[a.address]=f.deviceHandle,evothings.ble.readAllServiceData(f.deviceHandle,function(d){d.forEach(function(c){var d=new b.Service(c.uuid,c.handle,0===c.type);a.services[d.uuid]=d,c.characteristics.forEach(function(a){var c=[],e=new b.Characteristic(a.uuid,a.handle,c);d.characteristics[e.uuid]=e,this.characteristicHandles[a.handle]=f.deviceHandle,a.descriptors.forEach(function(a){var c=new b.Descriptor(a.uuid,a.handle);e.descriptors[c.uuid]=c,this.descriptorHandles[a.handle]=f.deviceHandle},this)},this)},this),c()}.bind(this),e))}.bind(this),e)},disconnect:function(a,b){this.deviceHandles[a.address]&&evothings.ble.close(this.deviceHandles[a.address])},readCharacteristic:function(a,b,c){evothings.ble.readCharacteristic(this.characteristicHandles[a.handle],a.handle,b,c)},writeCharacteristic:function(a,b,c,d){evothings.ble.writeCharacteristic(this.characteristicHandles[a.handle],a.handle,b,c,d)},enableNotify:function(a,b,c){evothings.ble.enableNotification(this.characteristicHandles[a.handle],a.handle,b,c)},disableNotify:function(a,b,c){evothings.ble.disableNotification(this.characteristicHandles[a.handle],a.handle,b,c)},readDescriptor:function(a,b,c){evothings.ble.readDescriptor(this.descriptorHandles[a.handle],a.handle,b,c)},writeDescriptor:function(a,b,c,d){evothings.ble.writeDescriptor(this.descriptorHandles[a.handle],a.handle,b,c,d)}})});
{
"name": "bleat",
"version": "0.0.5",
"version": "0.0.6",
"description": "Abstraction library for hiding differences in JavaScript BLE APIs",

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

# bleat
[![Circle CI](https://circleci.com/gh/thegecko/bleat.svg?style=shield)](https://circleci.com/gh/thegecko/bleat)
[![npm](https://img.shields.io/npm/v/bleat.svg)](https://www.npmjs.com/package/bleat)
[![Circle CI](https://img.shields.io/circleci/project/thegecko/bleat.svg)](https://circleci.com/gh/thegecko/bleat)
[![Bower](https://img.shields.io/bower/v/bleat.svg)](http://bower.io/search/?q=bleat)
[![npm](https://img.shields.io/npm/dm/bleat.svg)](https://www.npmjs.com/package/bleat)
[![Licence MIT](https://img.shields.io/badge/licence-MIT-blue.svg)](http://opensource.org/licenses/MIT)
Abstraction library for hiding differences in JavaScript BLE APIs
Bleat (Blutooth Low Energy Abstraction Tool) provides a simplified BLE layer which uses adapters to abstract the usage of BLE in JavaScript on different platforms.
## Roadmap
#### Basic BLE layer
* ~~Central Mode~~
* ~~Device Scan~~
* ~~Advertised Service UUIDs~~
* ~~Connect/Disconnect~~
* ~~List Services/Characteristics/Descriptors~~
* ~~Read/Write/Notify Characteristics~~
* ~~Read/Write Descriptors~~
* Peripheral Mode
* Advertising
#### Adapters
* Central Mode
* ~~Evothings/Cordova/PhoneGap~~ https://github.com/evothings/cordova-ble/blob/master/ble.js
* ~~ChromeOS~~ https://developer.chrome.com/apps/bluetoothLowEnergy
* noble https://github.com/sandeepmistry/noble
* Web Bluetooth https://www.w3.org/community/web-bluetooth
* Peripheral Mode
* Tessel
* Espruino
## Installation
```
npm install bleat
-or-
bower install bleat
```
## Usage
The main `bleat.js` file offers the BLE layer while each `bleat.<platform>.js` file represents an adapter.
The `bleat.min.js` file is a minified version of the BLE layer and all adapters.
Files follow the UMD (https://github.com/umdjs/umd), so should work with AMD (requirejs), CommonJS (node) and plain JavaScript projects.
Include (or require) the `bleat.js` file before the adapter you wish to use or include the minified file offering all adapters.
e.g.
```
<script src="path/to/bleat.js"></script>
<script src="path/to/bleat.<adapter>.js"></script>
-or-
<script src="path/to/bleat.min.js"></script>
```
## API
### bleat
#### bleat.init
Initialise bleat.
```
void bleat.init([readyFn], [errorFn], [adapterName]);
```
function readyFn(): callback function once init has completed
function errorFn(message): callback function for all errors while bleating
string adapterName: when multiple adapters available, specify which to use
#### bleat.startScan
Start scanning for devices.
```
void bleat.startScan(foundFn);
```
function foundFn(device): callback function for each device discovered.
#### bleat.stopScan
Stop scanning for devices.
```
void bleat.stopScan();
```
### device
string device.address: uuid of device
string device.name: name of device
bool device.connected: whether device is connected
string array device.serviceUUIDs: array of advertised services
object services: map of device services keyed on service uuid (available once connected)
#### device.hasService
Returns whether a device has the specified service.
```
bool device.hasService(serviceUUID);
```
string serviceUUID: service to search for
#### device.connect
Connect to the device.
```
void device.connect(connectFn, disconnectFn);
```
function connectFn(): callback once connected
function disconnectFn(): callback when disconnected
#### device.disconnect
Disconnect from device.
```
void device.disconnect();
```
### Service
string uuid: uuid of service
bool primary: whether service is primary or not
object characteristics: map of service characteristics keyed on characteristic uuid
### Characteristic
string uuid: uuid of characteristic
string array properties: characteristic properties
object descriptors: map of characteristic descriptors keyed on descriptor uuid
#### characteristic.read
Read value of characteristic.
```
void characteristic.read(completeFn);
```
function completeFn(ArrayBuffer): callback function containing value
#### characteristic.write
Write value to characteristic.
```
void characteristic.write(bufferView, completeFn);
```
DataView bufferView: value to write
function completeFn(): callback function once completed
#### characteristic.enableNotify
Enable notifications when characteristic value changes.
```
void characteristic.enableNotify(notifyFn);
```
function notifyFn(ArrayBuffer): callback function containing value when changes
#### characteristic.disableNotify
Disable characteristic notifications.
```
void characteristic.disableNotify(completeFn);
```
function completeFn(): callback function once completed
### Descriptor
string uuid: uuid of descriptor
#### descriptor.read
Read value of descriptor.
```
void descriptor.read(completeFn);
```
function completeFn(ArrayBuffer): callback function containing value
#### descriptor.write
Write value to descriptor.
```
void descriptor.write(bufferView, completeFn);
```
DataView bufferView: value to write
function completeFn(): callback function once completed
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