Socket
Socket
Sign inDemoInstall

webbluetooth

Package Overview
Dependencies
93
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.2.0 to 3.0.2

.github/dependabot.yml

33

dist/bluetooth.d.ts
/// <reference types="web-bluetooth" />
import { TypedDispatcher } from './dispatcher';
import { BluetoothDevice, BluetoothDeviceEvents } from './device';
import { W3CBluetooth } from './interfaces';
import { BluetoothDeviceEvents } from './device';
import { EventDispatcher } from './events';
/**

@@ -18,2 +17,6 @@ * Bluetooth Options interface

/**
* Optional flag to automatically allow all devices
*/
allowAllDevices?: boolean;
/**
* An optional referring device

@@ -32,13 +35,8 @@ */

}
declare const Bluetooth_base: new () => TypedDispatcher<BluetoothEvents>;
/**
* Bluetooth class
*/
export declare class Bluetooth extends Bluetooth_base implements W3CBluetooth {
export declare class BluetoothImpl extends EventDispatcher<BluetoothEvents> implements Bluetooth {
private options;
/**
* Bluetooth Availability Changed event
* @event
*/
static EVENT_AVAILABILITY: string;
/**
* Referring device for the bluetooth instance

@@ -50,2 +48,8 @@ */

private scanner;
private allowedDevices;
/**
* Bluetooth constructor
* @param options Bluetooth initialisation options
*/
constructor(options?: BluetoothOptions);
private _oncharacteristicvaluechanged;

@@ -65,8 +69,4 @@ set oncharacteristicvaluechanged(fn: (ev: Event) => void);

set onavailabilitychanged(fn: (ev: Event) => void);
/**
* Bluetooth constructor
* @param options Bluetooth initialisation options
*/
constructor(options?: BluetoothOptions);
private filterDevice;
private forgetDevice;
/**

@@ -90,3 +90,3 @@ * Gets the availability of a bluetooth adapter

*/
cancelRequest(): Promise<void>;
cancelRequest(): void;
/**

@@ -98,2 +98,1 @@ * @hidden

}
export {};

@@ -41,44 +41,43 @@ "use strict";

})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Bluetooth = void 0;
var dispatcher_1 = require("./dispatcher");
exports.BluetoothImpl = void 0;
var adapters_1 = require("./adapters");
var device_1 = require("./device");
var helpers_1 = require("./helpers");
var adapter_1 = require("./adapter");
var uuid_1 = require("./uuid");
var events_1 = require("./events");

@@ -88,4 +87,4 @@ /**

*/
var Bluetooth = /** @class */ (function (_super) {
__extends(Bluetooth, _super);
var BluetoothImpl = /** @class */ (function (_super) {
__extends(BluetoothImpl, _super);
/**

@@ -95,13 +94,16 @@ * Bluetooth constructor

*/
function Bluetooth(options) {
function BluetoothImpl(options) {
if (options === void 0) { options = {}; }
var _this = _super.call(this) || this;
_this.options = options;
_this.deviceFound = undefined;
_this.scanTime = 10.24 * 1000;
_this.scanner = undefined;
options = options || {};
_this.allowedDevices = new Set();
_this.referringDevice = options.referringDevice;
_this.deviceFound = options.deviceFound;
if (options.scanTime)
if (options.scanTime) {
_this.scanTime = options.scanTime * 1000;
adapter_1.adapter.on(adapter_1.NobleAdapter.EVENT_ENABLED, function (_value) {
}
adapters_1.adapter.on(adapters_1.EVENT_ENABLED, function (_value) {
_this.dispatchEvent(new events_1.DOMEvent(_this, 'availabilitychanged'));

@@ -111,9 +113,12 @@ });

}
Object.defineProperty(Bluetooth.prototype, "oncharacteristicvaluechanged", {
Object.defineProperty(BluetoothImpl.prototype, "oncharacteristicvaluechanged", {
set: function (fn) {
if (this._oncharacteristicvaluechanged) {
this.removeEventListener('characteristicvaluechanged', this._oncharacteristicvaluechanged);
this._oncharacteristicvaluechanged = undefined;
}
this._oncharacteristicvaluechanged = fn;
this.addEventListener('characteristicvaluechanged', this._oncharacteristicvaluechanged);
if (fn) {
this._oncharacteristicvaluechanged = fn;
this.addEventListener('characteristicvaluechanged', this._oncharacteristicvaluechanged);
}
},

@@ -123,9 +128,12 @@ enumerable: false,

});
Object.defineProperty(Bluetooth.prototype, "onserviceadded", {
Object.defineProperty(BluetoothImpl.prototype, "onserviceadded", {
set: function (fn) {
if (this._onserviceadded) {
this.removeEventListener('serviceadded', this._onserviceadded);
this._onserviceadded = undefined;
}
this._onserviceadded = fn;
this.addEventListener('serviceadded', this._onserviceadded);
if (fn) {
this._onserviceadded = fn;
this.addEventListener('serviceadded', this._onserviceadded);
}
},

@@ -135,9 +143,12 @@ enumerable: false,

});
Object.defineProperty(Bluetooth.prototype, "onservicechanged", {
Object.defineProperty(BluetoothImpl.prototype, "onservicechanged", {
set: function (fn) {
if (this._onservicechanged) {
this.removeEventListener('servicechanged', this._onservicechanged);
this._onservicechanged = undefined;
}
this._onservicechanged = fn;
this.addEventListener('servicechanged', this._onservicechanged);
if (fn) {
this._onservicechanged = fn;
this.addEventListener('servicechanged', this._onservicechanged);
}
},

@@ -147,9 +158,12 @@ enumerable: false,

});
Object.defineProperty(Bluetooth.prototype, "onserviceremoved", {
Object.defineProperty(BluetoothImpl.prototype, "onserviceremoved", {
set: function (fn) {
if (this._onserviceremoved) {
this.removeEventListener('serviceremoved', this._onserviceremoved);
this._onserviceremoved = undefined;
}
this._onserviceremoved = fn;
this.addEventListener('serviceremoved', this._onserviceremoved);
if (fn) {
this._onserviceremoved = fn;
this.addEventListener('serviceremoved', this._onserviceremoved);
}
},

@@ -159,9 +173,12 @@ enumerable: false,

});
Object.defineProperty(Bluetooth.prototype, "ongattserverdisconnected", {
Object.defineProperty(BluetoothImpl.prototype, "ongattserverdisconnected", {
set: function (fn) {
if (this._ongattserverdisconnected) {
this.removeEventListener('gattserverdisconnected', this._ongattserverdisconnected);
this._ongattserverdisconnected = undefined;
}
this._ongattserverdisconnected = fn;
this.addEventListener('gattserverdisconnected', this._ongattserverdisconnected);
if (fn) {
this._ongattserverdisconnected = fn;
this.addEventListener('gattserverdisconnected', this._ongattserverdisconnected);
}
},

@@ -171,9 +188,12 @@ enumerable: false,

});
Object.defineProperty(Bluetooth.prototype, "onadvertisementreceived", {
Object.defineProperty(BluetoothImpl.prototype, "onadvertisementreceived", {
set: function (fn) {
if (this._onadvertisementreceived) {
this.removeEventListener('advertisementreceived', this._onadvertisementreceived);
this._onadvertisementreceived = undefined;
}
this._onadvertisementreceived = fn;
this.addEventListener('advertisementreceived', this._onadvertisementreceived);
if (fn) {
this._onadvertisementreceived = fn;
this.addEventListener('advertisementreceived', this._onadvertisementreceived);
}
},

@@ -183,9 +203,12 @@ enumerable: false,

});
Object.defineProperty(Bluetooth.prototype, "onavailabilitychanged", {
Object.defineProperty(BluetoothImpl.prototype, "onavailabilitychanged", {
set: function (fn) {
if (this._onavailabilitychanged) {
this.removeEventListener('availabilitychanged', this._onavailabilitychanged);
this._onavailabilitychanged = undefined;
}
this._onavailabilitychanged = fn;
this.addEventListener('availabilitychanged', this._onavailabilitychanged);
if (fn) {
this._onavailabilitychanged = fn;
this.addEventListener('availabilitychanged', this._onavailabilitychanged);
}
},

@@ -195,5 +218,6 @@ enumerable: false,

});
Bluetooth.prototype.filterDevice = function (filters, deviceInfo, validServices) {
BluetoothImpl.prototype.filterDevice = function (filters, deviceInfo, validServices) {
var valid = false;
filters.forEach(function (filter) {
var e_1, _a, e_2, _b;
// Name

@@ -211,3 +235,3 @@ if (filter.name && filter.name !== deviceInfo.name)

if (filter.services) {
var serviceUUIDs = filter.services.map(helpers_1.getServiceUUID);
var serviceUUIDs = filter.services.map(uuid_1.BluetoothUUID.getService);
var servicesValid = serviceUUIDs.every(function (serviceUUID) {

@@ -220,8 +244,51 @@ return (deviceInfo._serviceUUIDs.indexOf(serviceUUID) > -1);

}
// Service Data
if (filter.serviceData) {
if (!deviceInfo._adData.serviceData)
return;
var services = __spreadArray([], __read(deviceInfo._adData.serviceData.keys()), false);
try {
for (var _c = __values(filter.serviceData), _d = _c.next(); !_d.done; _d = _c.next()) {
var entry = _d.value;
if (!services.includes(entry.service))
return;
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
}
finally { if (e_1) throw e_1.error; }
}
}
// Manufacturer Data
if (filter.manufacturerData) {
if (!deviceInfo._adData.manufacturerData)
return;
var manufacturers = __spreadArray([], __read(deviceInfo._adData.manufacturerData.keys()), false);
try {
for (var _e = __values(filter.manufacturerData), _f = _e.next(); !_f.done; _f = _e.next()) {
var entry = _f.value;
if (!manufacturers.includes(entry.companyIdentifier))
return;
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
}
finally { if (e_2) throw e_2.error; }
}
}
valid = true;
});
if (!valid)
return false;
return undefined;
return deviceInfo;
};
BluetoothImpl.prototype.forgetDevice = function (uuid) {
this.allowedDevices.delete(uuid);
};
/**

@@ -231,4 +298,4 @@ * Gets the availability of a bluetooth adapter

*/
Bluetooth.prototype.getAvailability = function () {
return adapter_1.adapter.getEnabled();
BluetoothImpl.prototype.getAvailability = function () {
return adapters_1.adapter.getEnabled();
};

@@ -240,3 +307,3 @@ /**

*/
Bluetooth.prototype.requestDevice = function (options) {
BluetoothImpl.prototype.requestDevice = function (options) {
var _this = this;

@@ -275,3 +342,3 @@ if (options === void 0) { options = { filters: [] }; }

if (filter.services)
searchUUIDs = searchUUIDs.concat(filter.services.map(helpers_1.getServiceUUID));
searchUUIDs = searchUUIDs.concat(filter.services.map(uuid_1.BluetoothUUID.getService));
// Unique-ify

@@ -286,70 +353,46 @@ searchUUIDs = searchUUIDs.filter(function (item, index, array) {

}
// eslint-disable-next-line no-async-promise-executor
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
var found;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
found = false;
return [4 /*yield*/, adapter_1.adapter.startScan(searchUUIDs, function (deviceInfo) {
var validServices = [];
var complete = function (bluetoothDevice) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.cancelRequest()];
case 1:
_a.sent();
resolve(bluetoothDevice);
return [2 /*return*/];
}
});
}); };
// filter devices if filters specified
if (isFiltered(options)) {
deviceInfo = _this.filterDevice(options.filters, deviceInfo, validServices);
}
if (deviceInfo) {
found = true;
// Add additional services
if (options.optionalServices) {
validServices = validServices.concat(options.optionalServices.map(helpers_1.getServiceUUID));
}
// Set unique list of allowed services
var allowedServices = validServices.filter(function (item, index, array) {
return array.indexOf(item) === index;
});
Object.assign(deviceInfo, {
_bluetooth: _this,
_allowedServices: allowedServices
});
var bluetoothDevice_1 = new device_1.BluetoothDevice(deviceInfo);
var selectFn = function () {
complete.call(_this, bluetoothDevice_1);
};
if (!_this.deviceFound || _this.deviceFound(bluetoothDevice_1, selectFn.bind(_this)) === true) {
// If no deviceFound function, or deviceFound returns true, resolve with this device immediately
complete.call(_this, bluetoothDevice_1);
}
}
})];
case 1:
_a.sent();
this.scanner = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.cancelRequest()];
case 1:
_a.sent();
if (!found) {
reject('requestDevice error: no devices found');
}
return [2 /*return*/];
}
});
}); }, this.scanTime);
return [2 /*return*/];
return new Promise(function (resolve, reject) {
var found = false;
_this.scanner = setTimeout(function () {
_this.cancelRequest();
if (!found) {
reject('requestDevice error: no devices found');
}
}, _this.scanTime);
adapters_1.adapter.startScan(searchUUIDs, function (deviceInfo) {
var validServices = [];
var complete = function (bluetoothDevice) {
_this.allowedDevices.add(bluetoothDevice.id);
_this.cancelRequest();
resolve(bluetoothDevice);
};
// filter devices if filters specified
if (isFiltered(options)) {
deviceInfo = _this.filterDevice(options.filters, deviceInfo, validServices);
}
if (deviceInfo) {
found = true;
// Add additional services
if (options.optionalServices) {
validServices = validServices.concat(options.optionalServices.map(uuid_1.BluetoothUUID.getService));
}
// Set unique list of allowed services
var allowedServices = validServices.filter(function (item, index, array) {
return array.indexOf(item) === index;
});
Object.assign(deviceInfo, {
_bluetooth: _this,
_allowedServices: allowedServices
});
var bluetoothDevice_1 = new device_1.BluetoothDeviceImpl(deviceInfo, function () { return _this.forgetDevice(deviceInfo.id); });
var selectFn = function () {
complete.call(_this, bluetoothDevice_1);
};
if (!_this.deviceFound || _this.deviceFound(bluetoothDevice_1, selectFn.bind(_this)) === true) {
// If no deviceFound function, or deviceFound returns true, resolve with this device immediately
complete.call(_this, bluetoothDevice_1);
}
}
});
}); });
});
};

@@ -359,3 +402,3 @@ /**

*/
Bluetooth.prototype.getDevices = function () {
BluetoothImpl.prototype.getDevices = function () {
var _this = this;

@@ -367,21 +410,17 @@ if (this.scanner !== undefined) {

var devices = [];
adapter_1.adapter.startScan([], function (deviceInfo) {
Object.assign(deviceInfo, {
_bluetooth: _this,
_allowedServices: []
});
var bluetoothDevice = new device_1.BluetoothDevice(deviceInfo);
devices.push(bluetoothDevice);
_this.scanner = setTimeout(function () {
_this.cancelRequest();
resolve(devices);
}, _this.scanTime);
adapters_1.adapter.startScan([], function (deviceInfo) {
var _a;
if (((_a = _this.options) === null || _a === void 0 ? void 0 : _a.allowAllDevices) || _this.allowedDevices.has(deviceInfo.id)) {
Object.assign(deviceInfo, {
_bluetooth: _this,
_allowedServices: []
});
var bluetoothDevice = new device_1.BluetoothDeviceImpl(deviceInfo, function () { return _this.forgetDevice(deviceInfo.id); });
devices.push(bluetoothDevice);
}
});
_this.scanner = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.cancelRequest()];
case 1:
_a.sent();
resolve(devices);
return [2 /*return*/];
}
});
}); }, _this.scanTime);
});

@@ -392,13 +431,8 @@ };

*/
Bluetooth.prototype.cancelRequest = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
if (this.scanner) {
clearTimeout(this.scanner);
this.scanner = undefined;
adapter_1.adapter.stopScan();
}
return [2 /*return*/];
});
});
BluetoothImpl.prototype.cancelRequest = function () {
if (this.scanner) {
clearTimeout(this.scanner);
this.scanner = undefined;
adapters_1.adapter.stopScan();
}
};

@@ -409,13 +443,8 @@ /**

*/
Bluetooth.prototype.requestLEScan = function (_options) {
BluetoothImpl.prototype.requestLEScan = function (_options) {
throw new Error('requestLEScan error: method not implemented.');
};
/**
* Bluetooth Availability Changed event
* @event
*/
Bluetooth.EVENT_AVAILABILITY = 'availabilitychanged';
return Bluetooth;
}(dispatcher_1.EventDispatcher));
exports.Bluetooth = Bluetooth;
return BluetoothImpl;
}(events_1.EventDispatcher));
exports.BluetoothImpl = BluetoothImpl;
//# sourceMappingURL=bluetooth.js.map
/// <reference types="web-bluetooth" />
import { TypedDispatcher } from './dispatcher';
import { BluetoothRemoteGATTService } from './service';
import { BluetoothRemoteGATTDescriptor } from './descriptor';
import { W3CBluetoothRemoteGATTCharacteristic } from './interfaces';
import { BluetoothRemoteGATTServiceImpl } from './service';
import { EventDispatcher } from './events';
/**
* @hidden
*/
export interface BluetoothRemoteGATTCharacteristicEvents {
export interface CharacteristicEvents {
/**

@@ -15,15 +13,14 @@ * Characteristic value changed event

}
declare const BluetoothRemoteGATTCharacteristic_base: new () => TypedDispatcher<BluetoothRemoteGATTCharacteristicEvents>;
/**
* Bluetooth Remote GATT Characteristic class
*/
export declare class BluetoothRemoteGATTCharacteristic extends BluetoothRemoteGATTCharacteristic_base implements W3CBluetoothRemoteGATTCharacteristic {
export declare class BluetoothRemoteGATTCharacteristicImpl extends EventDispatcher<CharacteristicEvents> implements BluetoothRemoteGATTCharacteristic {
/**
* The service the characteristic is related to
*/
readonly service: BluetoothRemoteGATTService;
readonly service: BluetoothRemoteGATTServiceImpl;
/**
* The unique identifier of the characteristic
*/
readonly uuid: any;
readonly uuid: string | undefined;
/**

@@ -46,3 +43,3 @@ * The properties of the characteristic

*/
constructor(init: Partial<BluetoothRemoteGATTCharacteristic>);
constructor(init: Partial<BluetoothRemoteGATTCharacteristicImpl>);
private setValue;

@@ -85,3 +82,3 @@ /**

*/
startNotifications(): Promise<W3CBluetoothRemoteGATTCharacteristic>;
startNotifications(): Promise<BluetoothRemoteGATTCharacteristic>;
/**

@@ -93,2 +90,1 @@ * Stop notifications of changes for the characteristic

}
export {};

@@ -56,3 +56,3 @@ "use strict";

if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;

@@ -79,7 +79,6 @@ if (y = 0, t) op = [op[0] & 2, t.value];

Object.defineProperty(exports, "__esModule", { value: true });
exports.BluetoothRemoteGATTCharacteristic = void 0;
var dispatcher_1 = require("./dispatcher");
exports.BluetoothRemoteGATTCharacteristicImpl = void 0;
var adapters_1 = require("./adapters");
var descriptor_1 = require("./descriptor");
var helpers_1 = require("./helpers");
var adapter_1 = require("./adapter");
var uuid_1 = require("./uuid");
var events_1 = require("./events");

@@ -90,4 +89,4 @@ var isView = function (source) { return source.buffer !== undefined; };

*/
var BluetoothRemoteGATTCharacteristic = /** @class */ (function (_super) {
__extends(BluetoothRemoteGATTCharacteristic, _super);
var BluetoothRemoteGATTCharacteristicImpl = /** @class */ (function (_super) {
__extends(BluetoothRemoteGATTCharacteristicImpl, _super);
/**

@@ -97,3 +96,3 @@ * Characteristic constructor

*/
function BluetoothRemoteGATTCharacteristic(init) {
function BluetoothRemoteGATTCharacteristicImpl(init) {
var _this = _super.call(this) || this;

@@ -118,3 +117,3 @@ /**

}
Object.defineProperty(BluetoothRemoteGATTCharacteristic.prototype, "value", {
Object.defineProperty(BluetoothRemoteGATTCharacteristicImpl.prototype, "value", {
/**

@@ -129,9 +128,12 @@ * The value of the characteristic

});
Object.defineProperty(BluetoothRemoteGATTCharacteristic.prototype, "oncharacteristicvaluechanged", {
Object.defineProperty(BluetoothRemoteGATTCharacteristicImpl.prototype, "oncharacteristicvaluechanged", {
set: function (fn) {
if (this._oncharacteristicvaluechanged) {
this.removeEventListener('characteristicvaluechanged', this._oncharacteristicvaluechanged);
this._oncharacteristicvaluechanged = undefined;
}
this._oncharacteristicvaluechanged = fn;
this.addEventListener('characteristicvaluechanged', this._oncharacteristicvaluechanged);
if (fn) {
this._oncharacteristicvaluechanged = fn;
this.addEventListener('characteristicvaluechanged', this._oncharacteristicvaluechanged);
}
},

@@ -141,3 +143,3 @@ enumerable: false,

});
BluetoothRemoteGATTCharacteristic.prototype.setValue = function (value, emit) {
BluetoothRemoteGATTCharacteristicImpl.prototype.setValue = function (value, emit) {
this._value = value;

@@ -156,3 +158,3 @@ if (emit) {

*/
BluetoothRemoteGATTCharacteristic.prototype.getDescriptor = function (descriptor) {
BluetoothRemoteGATTCharacteristicImpl.prototype.getDescriptor = function (descriptor) {
return __awaiter(this, void 0, void 0, function () {

@@ -185,3 +187,3 @@ var descriptors;

*/
BluetoothRemoteGATTCharacteristic.prototype.getDescriptors = function (descriptor) {
BluetoothRemoteGATTCharacteristicImpl.prototype.getDescriptors = function (descriptor) {
return __awaiter(this, void 0, void 0, function () {

@@ -197,3 +199,3 @@ var descriptors, filtered;

if (!!this.descriptors) return [3 /*break*/, 2];
return [4 /*yield*/, adapter_1.adapter.discoverDescriptors(this.handle)];
return [4 /*yield*/, adapters_1.adapter.discoverDescriptors(this.handle)];
case 1:

@@ -205,3 +207,3 @@ descriptors = _a.sent();

});
return new descriptor_1.BluetoothRemoteGATTDescriptor(descriptorInfo);
return new descriptor_1.BluetoothRemoteGATTDescriptorImpl(descriptorInfo);
});

@@ -213,3 +215,3 @@ _a.label = 2;

}
filtered = this.descriptors.filter(function (descriptorObject) { return descriptorObject.uuid === helpers_1.getDescriptorUUID(descriptor); });
filtered = this.descriptors.filter(function (descriptorObject) { return descriptorObject.uuid === uuid_1.BluetoothUUID.getDescriptor(descriptor); });
if (filtered.length !== 1) {

@@ -227,3 +229,3 @@ throw new Error('getDescriptors error: descriptor not found');

*/
BluetoothRemoteGATTCharacteristic.prototype.readValue = function () {
BluetoothRemoteGATTCharacteristicImpl.prototype.readValue = function () {
return __awaiter(this, void 0, void 0, function () {

@@ -237,3 +239,3 @@ var dataView;

}
return [4 /*yield*/, adapter_1.adapter.readCharacteristic(this.handle)];
return [4 /*yield*/, adapters_1.adapter.readCharacteristic(this.handle)];
case 1:

@@ -251,3 +253,3 @@ dataView = _a.sent();

*/
BluetoothRemoteGATTCharacteristic.prototype.writeValue = function (value) {
BluetoothRemoteGATTCharacteristicImpl.prototype.writeValue = function (value) {
return __awaiter(this, void 0, void 0, function () {

@@ -263,3 +265,3 @@ var arrayBuffer, dataView;

dataView = new DataView(arrayBuffer);
return [4 /*yield*/, adapter_1.adapter.writeCharacteristic(this.handle, dataView)];
return [4 /*yield*/, adapters_1.adapter.writeCharacteristic(this.handle, dataView)];
case 1:

@@ -277,3 +279,3 @@ _a.sent();

*/
BluetoothRemoteGATTCharacteristic.prototype.writeValueWithResponse = function (value) {
BluetoothRemoteGATTCharacteristicImpl.prototype.writeValueWithResponse = function (value) {
return __awaiter(this, void 0, void 0, function () {

@@ -289,3 +291,3 @@ var arrayBuffer, dataView;

dataView = new DataView(arrayBuffer);
return [4 /*yield*/, adapter_1.adapter.writeCharacteristic(this.handle, dataView, false)];
return [4 /*yield*/, adapters_1.adapter.writeCharacteristic(this.handle, dataView, false)];
case 1:

@@ -303,3 +305,3 @@ _a.sent();

*/
BluetoothRemoteGATTCharacteristic.prototype.writeValueWithoutResponse = function (value) {
BluetoothRemoteGATTCharacteristicImpl.prototype.writeValueWithoutResponse = function (value) {
return __awaiter(this, void 0, void 0, function () {

@@ -315,3 +317,3 @@ var arrayBuffer, dataView;

dataView = new DataView(arrayBuffer);
return [4 /*yield*/, adapter_1.adapter.writeCharacteristic(this.handle, dataView, true)];
return [4 /*yield*/, adapters_1.adapter.writeCharacteristic(this.handle, dataView, true)];
case 1:

@@ -329,3 +331,3 @@ _a.sent();

*/
BluetoothRemoteGATTCharacteristic.prototype.startNotifications = function () {
BluetoothRemoteGATTCharacteristicImpl.prototype.startNotifications = function () {
return __awaiter(this, void 0, void 0, function () {

@@ -339,3 +341,3 @@ var _this = this;

}
return [4 /*yield*/, adapter_1.adapter.enableNotify(this.handle, function (dataView) {
return [4 /*yield*/, adapters_1.adapter.enableNotify(this.handle, function (dataView) {
_this.setValue(dataView, true);

@@ -354,3 +356,3 @@ })];

*/
BluetoothRemoteGATTCharacteristic.prototype.stopNotifications = function () {
BluetoothRemoteGATTCharacteristicImpl.prototype.stopNotifications = function () {
return __awaiter(this, void 0, void 0, function () {

@@ -363,3 +365,3 @@ return __generator(this, function (_a) {

}
return [4 /*yield*/, adapter_1.adapter.disableNotify(this.handle)];
return [4 /*yield*/, adapters_1.adapter.disableNotify(this.handle)];
case 1:

@@ -372,5 +374,5 @@ _a.sent();

};
return BluetoothRemoteGATTCharacteristic;
}(dispatcher_1.EventDispatcher));
exports.BluetoothRemoteGATTCharacteristic = BluetoothRemoteGATTCharacteristic;
return BluetoothRemoteGATTCharacteristicImpl;
}(events_1.EventDispatcher));
exports.BluetoothRemoteGATTCharacteristicImpl = BluetoothRemoteGATTCharacteristicImpl;
//# sourceMappingURL=characteristic.js.map
/// <reference types="web-bluetooth" />
import { W3CBluetoothRemoteGATTDescriptor } from './interfaces';
/**
* Bluetooth Remote GATT Descriptor class
*/
export declare class BluetoothRemoteGATTDescriptor implements W3CBluetoothRemoteGATTDescriptor {
export declare class BluetoothRemoteGATTDescriptorImpl implements BluetoothRemoteGATTDescriptor {
/**

@@ -8,0 +7,0 @@ * The characteristic the descriptor is related to

@@ -41,3 +41,3 @@ "use strict";

if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;

@@ -64,8 +64,8 @@ if (y = 0, t) op = [op[0] & 2, t.value];

Object.defineProperty(exports, "__esModule", { value: true });
exports.BluetoothRemoteGATTDescriptor = void 0;
var adapter_1 = require("./adapter");
exports.BluetoothRemoteGATTDescriptorImpl = void 0;
var adapters_1 = require("./adapters");
/**
* Bluetooth Remote GATT Descriptor class
*/
var BluetoothRemoteGATTDescriptor = /** @class */ (function () {
var BluetoothRemoteGATTDescriptorImpl = /** @class */ (function () {
/**

@@ -75,3 +75,3 @@ * Descriptor constructor

*/
function BluetoothRemoteGATTDescriptor(init) {
function BluetoothRemoteGATTDescriptorImpl(init) {
/**

@@ -90,5 +90,5 @@ * The characteristic the descriptor is related to

this._value = init.value;
this.handle = this.characteristic.uuid + "-" + this.uuid;
this.handle = "".concat(this.characteristic.uuid, "-").concat(this.uuid);
}
Object.defineProperty(BluetoothRemoteGATTDescriptor.prototype, "value", {
Object.defineProperty(BluetoothRemoteGATTDescriptorImpl.prototype, "value", {
/**

@@ -107,3 +107,3 @@ * The value of the descriptor

*/
BluetoothRemoteGATTDescriptor.prototype.readValue = function () {
BluetoothRemoteGATTDescriptorImpl.prototype.readValue = function () {
return __awaiter(this, void 0, void 0, function () {

@@ -117,3 +117,3 @@ var dataView;

}
return [4 /*yield*/, adapter_1.adapter.readDescriptor(this.handle)];
return [4 /*yield*/, adapters_1.adapter.readDescriptor(this.handle)];
case 1:

@@ -131,3 +131,3 @@ dataView = _a.sent();

*/
BluetoothRemoteGATTDescriptor.prototype.writeValue = function (value) {
BluetoothRemoteGATTDescriptorImpl.prototype.writeValue = function (value) {
return __awaiter(this, void 0, void 0, function () {

@@ -144,3 +144,3 @@ var isView, arrayBuffer, dataView;

dataView = new DataView(arrayBuffer);
return [4 /*yield*/, adapter_1.adapter.writeDescriptor(this.handle, dataView)];
return [4 /*yield*/, adapters_1.adapter.writeDescriptor(this.handle, dataView)];
case 1:

@@ -154,5 +154,5 @@ _a.sent();

};
return BluetoothRemoteGATTDescriptor;
return BluetoothRemoteGATTDescriptorImpl;
}());
exports.BluetoothRemoteGATTDescriptor = BluetoothRemoteGATTDescriptor;
exports.BluetoothRemoteGATTDescriptorImpl = BluetoothRemoteGATTDescriptorImpl;
//# sourceMappingURL=descriptor.js.map

@@ -1,10 +0,8 @@

import { TypedDispatcher } from './dispatcher';
import { Bluetooth } from './bluetooth';
import { BluetoothRemoteGATTServer } from './server';
import { BluetoothRemoteGATTServiceEvents } from './service';
import { W3CBluetoothDevice } from './interfaces';
/// <reference types="web-bluetooth" />
import { ServiceEvents } from './service';
import { EventDispatcher } from './events';
/**
* @hidden
*/
export interface BluetoothDeviceEvents extends BluetoothRemoteGATTServiceEvents {
export interface BluetoothDeviceEvents extends ServiceEvents {
/**

@@ -19,7 +17,7 @@ * GATT server disconnected event

}
declare const BluetoothDevice_base: new () => TypedDispatcher<BluetoothDeviceEvents>;
/**
* Bluetooth Device class
*/
export declare class BluetoothDevice extends BluetoothDevice_base implements W3CBluetoothDevice {
export declare class BluetoothDeviceImpl extends EventDispatcher<BluetoothDeviceEvents> implements BluetoothDevice {
private forgetFn;
/**

@@ -44,7 +42,7 @@ * The unique identifier of the device

*/
readonly adData: {
readonly _adData: {
rssi?: number;
txPower?: number;
serviceData?: Map<string, DataView>;
manufacturerData?: Map<string, DataView>;
serviceData?: BluetoothServiceData;
manufacturerData?: BluetoothManufacturerData;
};

@@ -79,3 +77,3 @@ /**

*/
constructor(init: Partial<BluetoothDevice>);
constructor(init: Partial<BluetoothDeviceImpl>, forgetFn: () => void);
/**

@@ -90,6 +88,5 @@ * Starts watching adverts from this device (not implemented)

/**
* Forget this device (not implemented)
* Forget this device
*/
forget(): Promise<void>;
}
export {};

@@ -41,11 +41,47 @@ "use strict";

})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BluetoothDevice = void 0;
var dispatcher_1 = require("./dispatcher");
exports.BluetoothDeviceImpl = void 0;
var server_1 = require("./server");
var events_1 = require("./events");
/**
* Bluetooth Device class
*/
var BluetoothDevice = /** @class */ (function (_super) {
__extends(BluetoothDevice, _super);
var BluetoothDeviceImpl = /** @class */ (function (_super) {
__extends(BluetoothDeviceImpl, _super);
/**

@@ -55,4 +91,5 @@ * Device constructor

*/
function BluetoothDevice(init) {
function BluetoothDeviceImpl(init, forgetFn) {
var _this = _super.call(this) || this;
_this.forgetFn = forgetFn;
/**

@@ -89,4 +126,3 @@ * The unique identifier of the device

_this.gatt = init.gatt;
_this.watchAdvertisements = init.watchAdvertisements;
_this.adData = init.adData;
_this._adData = init._adData;
_this._bluetooth = init._bluetooth;

@@ -96,14 +132,17 @@ _this._allowedServices = init._allowedServices;

if (!_this.name)
_this.name = "Unknown or Unsupported Device (" + _this.id + ")";
_this.name = "Unknown or Unsupported Device (".concat(_this.id, ")");
if (!_this.gatt)
_this.gatt = new server_1.BluetoothRemoteGATTServer(_this);
_this.gatt = new server_1.BluetoothRemoteGATTServerImpl(_this);
return _this;
}
Object.defineProperty(BluetoothDevice.prototype, "oncharacteristicvaluechanged", {
Object.defineProperty(BluetoothDeviceImpl.prototype, "oncharacteristicvaluechanged", {
set: function (fn) {
if (this._oncharacteristicvaluechanged) {
this.removeEventListener('characteristicvaluechanged', this._oncharacteristicvaluechanged);
this._oncharacteristicvaluechanged = undefined;
}
this._oncharacteristicvaluechanged = fn;
this.addEventListener('characteristicvaluechanged', this._oncharacteristicvaluechanged);
if (fn) {
this._oncharacteristicvaluechanged = fn;
this.addEventListener('characteristicvaluechanged', this._oncharacteristicvaluechanged);
}
},

@@ -113,9 +152,12 @@ enumerable: false,

});
Object.defineProperty(BluetoothDevice.prototype, "onserviceadded", {
Object.defineProperty(BluetoothDeviceImpl.prototype, "onserviceadded", {
set: function (fn) {
if (this._onserviceadded) {
this.removeEventListener('serviceadded', this._onserviceadded);
this._onserviceadded = undefined;
}
this._onserviceadded = fn;
this.addEventListener('serviceadded', this._onserviceadded);
if (fn) {
this._onserviceadded = fn;
this.addEventListener('serviceadded', this._onserviceadded);
}
},

@@ -125,9 +167,12 @@ enumerable: false,

});
Object.defineProperty(BluetoothDevice.prototype, "onservicechanged", {
Object.defineProperty(BluetoothDeviceImpl.prototype, "onservicechanged", {
set: function (fn) {
if (this._onservicechanged) {
this.removeEventListener('servicechanged', this._onservicechanged);
this._onservicechanged = undefined;
}
this._onservicechanged = fn;
this.addEventListener('servicechanged', this._onservicechanged);
if (fn) {
this._onservicechanged = fn;
this.addEventListener('servicechanged', this._onservicechanged);
}
},

@@ -137,9 +182,12 @@ enumerable: false,

});
Object.defineProperty(BluetoothDevice.prototype, "onserviceremoved", {
Object.defineProperty(BluetoothDeviceImpl.prototype, "onserviceremoved", {
set: function (fn) {
if (this._onserviceremoved) {
this.removeEventListener('serviceremoved', this._onserviceremoved);
this._onserviceremoved = undefined;
}
this._onserviceremoved = fn;
this.addEventListener('serviceremoved', this._onserviceremoved);
if (fn) {
this._onserviceremoved = fn;
this.addEventListener('serviceremoved', this._onserviceremoved);
}
},

@@ -149,9 +197,12 @@ enumerable: false,

});
Object.defineProperty(BluetoothDevice.prototype, "ongattserverdisconnected", {
Object.defineProperty(BluetoothDeviceImpl.prototype, "ongattserverdisconnected", {
set: function (fn) {
if (this._ongattserverdisconnected) {
this.removeEventListener('gattserverdisconnected', this._ongattserverdisconnected);
this._ongattserverdisconnected = undefined;
}
this._ongattserverdisconnected = fn;
this.addEventListener('gattserverdisconnected', this._ongattserverdisconnected);
if (fn) {
this._ongattserverdisconnected = fn;
this.addEventListener('gattserverdisconnected', this._ongattserverdisconnected);
}
},

@@ -161,9 +212,12 @@ enumerable: false,

});
Object.defineProperty(BluetoothDevice.prototype, "onadvertisementreceived", {
Object.defineProperty(BluetoothDeviceImpl.prototype, "onadvertisementreceived", {
set: function (fn) {
if (this._onadvertisementreceived) {
this.removeEventListener('advertisementreceived', this._onadvertisementreceived);
this._onadvertisementreceived = undefined;
}
this._onadvertisementreceived = fn;
this.addEventListener('advertisementreceived', this._onadvertisementreceived);
if (fn) {
this._onadvertisementreceived = fn;
this.addEventListener('advertisementreceived', this._onadvertisementreceived);
}
},

@@ -176,3 +230,3 @@ enumerable: false,

*/
BluetoothDevice.prototype.watchAdvertisements = function () {
BluetoothDeviceImpl.prototype.watchAdvertisements = function () {
throw new Error('watchAdvertisements error: method not implemented');

@@ -183,14 +237,19 @@ };

*/
BluetoothDevice.prototype.unwatchAdvertisements = function () {
BluetoothDeviceImpl.prototype.unwatchAdvertisements = function () {
throw new Error('unwatchAdvertisements error: method not implemented');
};
/**
* Forget this device (not implemented)
* Forget this device
*/
BluetoothDevice.prototype.forget = function () {
throw new Error('forget error: method not implemented');
BluetoothDeviceImpl.prototype.forget = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
this.forgetFn();
return [2 /*return*/];
});
});
};
return BluetoothDevice;
}(dispatcher_1.EventDispatcher));
exports.BluetoothDevice = BluetoothDevice;
return BluetoothDeviceImpl;
}(events_1.EventDispatcher));
exports.BluetoothDeviceImpl = BluetoothDeviceImpl;
//# sourceMappingURL=device.js.map

@@ -0,4 +1,18 @@

/// <reference types="node" />
import { EventEmitter } from 'events';
/**
* @hidden
*/
export declare class EventDispatcher<T> {
protected emitter: EventEmitter;
private isEventListenerObject;
addEventListener<K extends keyof T>(type: K, listener: (this: this, ev: T[K]) => void): void;
addEventListener<K extends keyof T>(type: K, listener: EventListener): void;
removeEventListener<K extends keyof T>(type: K, callback: (this: this, ev: T[K]) => void): void;
removeEventListener<K extends keyof T>(type: K, callback: EventListener): void;
dispatchEvent(event: Event): boolean;
}
/**
* @hidden
*/
export declare class DOMEvent implements Event {

@@ -5,0 +19,0 @@ /**

@@ -27,6 +27,34 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.DOMEvent = void 0;
exports.DOMEvent = exports.EventDispatcher = void 0;
var events_1 = require("events");
/**
* @hidden
*/
var EventDispatcher = /** @class */ (function () {
function EventDispatcher() {
this.emitter = new events_1.EventEmitter();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.isEventListenerObject = function (listener) { return listener.handleEvent !== undefined; };
}
EventDispatcher.prototype.addEventListener = function (type, listener) {
if (listener) {
var handler = this.isEventListenerObject(listener) ? listener.handleEvent : listener;
this.emitter.addListener(type, handler);
}
};
EventDispatcher.prototype.removeEventListener = function (type, callback) {
if (callback) {
var handler = this.isEventListenerObject(callback) ? callback.handleEvent : callback;
this.emitter.removeListener(type, handler);
}
};
EventDispatcher.prototype.dispatchEvent = function (event) {
return this.emitter.emit(event.type, event);
};
return EventDispatcher;
}());
exports.EventDispatcher = EventDispatcher;
/**
* @hidden
*/
var DOMEvent = /** @class */ (function () {

@@ -33,0 +61,0 @@ function DOMEvent(target, type) {

@@ -1,13 +0,13 @@

import { Bluetooth, BluetoothOptions } from './bluetooth';
import { BluetoothImpl, BluetoothOptions } from './bluetooth';
/**
* Default bluetooth instance synonymous with `navigator.bluetooth`
*/
export declare const bluetooth: Bluetooth;
export declare const bluetooth: BluetoothImpl;
/**
* Bluetooth class for creating new instances
*/
export { Bluetooth, BluetoothOptions };
export { BluetoothImpl as Bluetooth, BluetoothOptions };
/**
* Helper methods and enums
*/
export * from './helpers';
export * from './uuid';

@@ -28,3 +28,7 @@ "use strict";

if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -40,11 +44,11 @@ if (k2 === undefined) k2 = k;

var bluetooth_1 = require("./bluetooth");
Object.defineProperty(exports, "Bluetooth", { enumerable: true, get: function () { return bluetooth_1.Bluetooth; } });
Object.defineProperty(exports, "Bluetooth", { enumerable: true, get: function () { return bluetooth_1.BluetoothImpl; } });
/**
* Default bluetooth instance synonymous with `navigator.bluetooth`
*/
exports.bluetooth = new bluetooth_1.Bluetooth();
exports.bluetooth = new bluetooth_1.BluetoothImpl();
/**
* Helper methods and enums
*/
__exportStar(require("./helpers"), exports);
__exportStar(require("./uuid"), exports);
//# sourceMappingURL=index.js.map
/// <reference types="web-bluetooth" />
import { BluetoothDevice } from './device';
import { W3CBluetoothRemoteGATTServer } from './interfaces';
import { BluetoothRemoteGATTService } from './service';
import { BluetoothDeviceImpl } from './device';
/**
* Bluetooth Remote GATT Server class
*/
export declare class BluetoothRemoteGATTServer implements W3CBluetoothRemoteGATTServer {
export declare class BluetoothRemoteGATTServerImpl implements BluetoothRemoteGATTServer {
/**
* The device the gatt server is related to
*/
readonly device: BluetoothDevice;
readonly device: BluetoothDeviceImpl;
private _connected;

@@ -24,3 +22,3 @@ /**

*/
constructor(device: BluetoothDevice);
constructor(device: BluetoothDeviceImpl);
/**

@@ -27,0 +25,0 @@ * Connect the gatt server

@@ -41,3 +41,3 @@ "use strict";

if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;

@@ -64,5 +64,5 @@ if (y = 0, t) op = [op[0] & 2, t.value];

Object.defineProperty(exports, "__esModule", { value: true });
exports.BluetoothRemoteGATTServer = void 0;
var helpers_1 = require("./helpers");
var adapter_1 = require("./adapter");
exports.BluetoothRemoteGATTServerImpl = void 0;
var uuid_1 = require("./uuid");
var adapters_1 = require("./adapters");
var service_1 = require("./service");

@@ -73,3 +73,3 @@ var events_1 = require("./events");

*/
var BluetoothRemoteGATTServer = /** @class */ (function () {
var BluetoothRemoteGATTServerImpl = /** @class */ (function () {
/**

@@ -79,3 +79,3 @@ * Server constructor

*/
function BluetoothRemoteGATTServer(device) {
function BluetoothRemoteGATTServerImpl(device) {
/**

@@ -91,3 +91,3 @@ * The device the gatt server is related to

}
Object.defineProperty(BluetoothRemoteGATTServer.prototype, "connected", {
Object.defineProperty(BluetoothRemoteGATTServerImpl.prototype, "connected", {
/**

@@ -106,3 +106,3 @@ * Whether the gatt server is connected

*/
BluetoothRemoteGATTServer.prototype.connect = function () {
BluetoothRemoteGATTServerImpl.prototype.connect = function () {
return __awaiter(this, void 0, void 0, function () {

@@ -116,3 +116,3 @@ var _this = this;

}
return [4 /*yield*/, adapter_1.adapter.connect(this.handle, function () {
return [4 /*yield*/, adapters_1.adapter.connect(this.handle, function () {
_this.services = undefined;

@@ -134,4 +134,4 @@ _this._connected = false;

*/
BluetoothRemoteGATTServer.prototype.disconnect = function () {
adapter_1.adapter.disconnect(this.handle);
BluetoothRemoteGATTServerImpl.prototype.disconnect = function () {
adapters_1.adapter.disconnect(this.handle);
this._connected = false;

@@ -144,3 +144,3 @@ };

*/
BluetoothRemoteGATTServer.prototype.getPrimaryService = function (service) {
BluetoothRemoteGATTServerImpl.prototype.getPrimaryService = function (service) {
return __awaiter(this, void 0, void 0, function () {

@@ -173,3 +173,3 @@ var services;

*/
BluetoothRemoteGATTServer.prototype.getPrimaryServices = function (service) {
BluetoothRemoteGATTServerImpl.prototype.getPrimaryServices = function (service) {
return __awaiter(this, void 0, void 0, function () {

@@ -185,3 +185,3 @@ var services, filtered;

if (!!this.services) return [3 /*break*/, 2];
return [4 /*yield*/, adapter_1.adapter.discoverServices(this.handle, this.device._allowedServices)];
return [4 /*yield*/, adapters_1.adapter.discoverServices(this.handle, this.device._allowedServices)];
case 1:

@@ -193,3 +193,3 @@ services = _a.sent();

});
return new service_1.BluetoothRemoteGATTService(serviceInfo);
return new service_1.BluetoothRemoteGATTServiceImpl(serviceInfo);
});

@@ -201,3 +201,3 @@ _a.label = 2;

}
filtered = this.services.filter(function (serviceObject) { return serviceObject.uuid === helpers_1.getServiceUUID(service); });
filtered = this.services.filter(function (serviceObject) { return serviceObject.uuid === uuid_1.BluetoothUUID.getService(service); });
if (filtered.length !== 1) {

@@ -211,5 +211,5 @@ throw new Error('getPrimaryServices error: service not found');

};
return BluetoothRemoteGATTServer;
return BluetoothRemoteGATTServerImpl;
}());
exports.BluetoothRemoteGATTServer = BluetoothRemoteGATTServer;
exports.BluetoothRemoteGATTServerImpl = BluetoothRemoteGATTServerImpl;
//# sourceMappingURL=server.js.map
/// <reference types="web-bluetooth" />
import { TypedDispatcher } from './dispatcher';
import { BluetoothDevice } from './device';
import { BluetoothRemoteGATTCharacteristic, BluetoothRemoteGATTCharacteristicEvents } from './characteristic';
import { W3CBluetoothRemoteGATTService } from './interfaces';
import { BluetoothDeviceImpl } from './device';
import { CharacteristicEvents } from './characteristic';
import { EventDispatcher } from './events';
/**
* @hidden
*/
export interface BluetoothRemoteGATTServiceEvents extends BluetoothRemoteGATTCharacteristicEvents {
export interface ServiceEvents extends CharacteristicEvents {
/**

@@ -23,11 +22,10 @@ * Service added event

}
declare const BluetoothRemoteGATTService_base: new () => TypedDispatcher<BluetoothRemoteGATTServiceEvents>;
/**
* Bluetooth Remote GATT Service class
*/
export declare class BluetoothRemoteGATTService extends BluetoothRemoteGATTService_base implements W3CBluetoothRemoteGATTService {
export declare class BluetoothRemoteGATTServiceImpl extends EventDispatcher<ServiceEvents> implements BluetoothRemoteGATTService {
/**
* The device the service is related to
*/
readonly device: BluetoothDevice;
readonly device: BluetoothDeviceImpl;
/**

@@ -56,3 +54,3 @@ * The unique identifier of the service

*/
constructor(init: Partial<BluetoothRemoteGATTService>);
constructor(init: Partial<BluetoothRemoteGATTServiceImpl>);
/**

@@ -83,2 +81,1 @@ * Gets a single characteristic contained in the service

}
export {};

@@ -56,3 +56,3 @@ "use strict";

if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;

@@ -79,7 +79,6 @@ if (y = 0, t) op = [op[0] & 2, t.value];

Object.defineProperty(exports, "__esModule", { value: true });
exports.BluetoothRemoteGATTService = void 0;
var dispatcher_1 = require("./dispatcher");
exports.BluetoothRemoteGATTServiceImpl = void 0;
var adapters_1 = require("./adapters");
var characteristic_1 = require("./characteristic");
var helpers_1 = require("./helpers");
var adapter_1 = require("./adapter");
var uuid_1 = require("./uuid");
var events_1 = require("./events");

@@ -89,4 +88,4 @@ /**

*/
var BluetoothRemoteGATTService = /** @class */ (function (_super) {
__extends(BluetoothRemoteGATTService, _super);
var BluetoothRemoteGATTServiceImpl = /** @class */ (function (_super) {
__extends(BluetoothRemoteGATTServiceImpl, _super);
/**

@@ -96,3 +95,3 @@ * Service constructor

*/
function BluetoothRemoteGATTService(init) {
function BluetoothRemoteGATTServiceImpl(init) {
var _this = _super.call(this) || this;

@@ -123,9 +122,12 @@ /**

}
Object.defineProperty(BluetoothRemoteGATTService.prototype, "oncharacteristicvaluechanged", {
Object.defineProperty(BluetoothRemoteGATTServiceImpl.prototype, "oncharacteristicvaluechanged", {
set: function (fn) {
if (this._oncharacteristicvaluechanged) {
this.removeEventListener('characteristicvaluechanged', this._oncharacteristicvaluechanged);
this._oncharacteristicvaluechanged = undefined;
}
this._oncharacteristicvaluechanged = fn;
this.addEventListener('characteristicvaluechanged', this._oncharacteristicvaluechanged);
if (fn) {
this._oncharacteristicvaluechanged = fn;
this.addEventListener('characteristicvaluechanged', this._oncharacteristicvaluechanged);
}
},

@@ -135,9 +137,12 @@ enumerable: false,

});
Object.defineProperty(BluetoothRemoteGATTService.prototype, "onserviceadded", {
Object.defineProperty(BluetoothRemoteGATTServiceImpl.prototype, "onserviceadded", {
set: function (fn) {
if (this._onserviceadded) {
this.removeEventListener('serviceadded', this._onserviceadded);
this._onserviceadded = undefined;
}
this._onserviceadded = fn;
this.addEventListener('serviceadded', this._onserviceadded);
if (fn) {
this._onserviceadded = fn;
this.addEventListener('serviceadded', this._onserviceadded);
}
},

@@ -147,9 +152,12 @@ enumerable: false,

});
Object.defineProperty(BluetoothRemoteGATTService.prototype, "onservicechanged", {
Object.defineProperty(BluetoothRemoteGATTServiceImpl.prototype, "onservicechanged", {
set: function (fn) {
if (this._onservicechanged) {
this.removeEventListener('servicechanged', this._onservicechanged);
this._onservicechanged = undefined;
}
this._onservicechanged = fn;
this.addEventListener('servicechanged', this._onservicechanged);
if (fn) {
this._onservicechanged = fn;
this.addEventListener('servicechanged', this._onservicechanged);
}
},

@@ -159,9 +167,12 @@ enumerable: false,

});
Object.defineProperty(BluetoothRemoteGATTService.prototype, "onserviceremoved", {
Object.defineProperty(BluetoothRemoteGATTServiceImpl.prototype, "onserviceremoved", {
set: function (fn) {
if (this._onserviceremoved) {
this.removeEventListener('serviceremoved', this._onserviceremoved);
this._onserviceremoved = undefined;
}
this._onserviceremoved = fn;
this.addEventListener('serviceremoved', this._onserviceremoved);
if (fn) {
this._onserviceremoved = fn;
this.addEventListener('serviceremoved', this._onserviceremoved);
}
},

@@ -176,3 +187,3 @@ enumerable: false,

*/
BluetoothRemoteGATTService.prototype.getCharacteristic = function (characteristic) {
BluetoothRemoteGATTServiceImpl.prototype.getCharacteristic = function (characteristic) {
return __awaiter(this, void 0, void 0, function () {

@@ -205,3 +216,3 @@ var characteristics;

*/
BluetoothRemoteGATTService.prototype.getCharacteristics = function (characteristic) {
BluetoothRemoteGATTServiceImpl.prototype.getCharacteristics = function (characteristic) {
return __awaiter(this, void 0, void 0, function () {

@@ -217,3 +228,3 @@ var characteristics, filtered;

if (!!this.characteristics) return [3 /*break*/, 2];
return [4 /*yield*/, adapter_1.adapter.discoverCharacteristics(this.handle)];
return [4 /*yield*/, adapters_1.adapter.discoverCharacteristics(this.handle)];
case 1:

@@ -225,3 +236,3 @@ characteristics = _a.sent();

});
return new characteristic_1.BluetoothRemoteGATTCharacteristic(characteristicInfo);
return new characteristic_1.BluetoothRemoteGATTCharacteristicImpl(characteristicInfo);
});

@@ -234,3 +245,3 @@ _a.label = 2;

// Canonical-ize characteristic
characteristic = helpers_1.getCharacteristicUUID(characteristic);
characteristic = uuid_1.BluetoothUUID.getCharacteristic(characteristic);
filtered = this.characteristics.filter(function (characteristicObject) { return characteristicObject.uuid === characteristic; });

@@ -250,3 +261,3 @@ if (filtered.length !== 1) {

*/
BluetoothRemoteGATTService.prototype.getIncludedService = function (service) {
BluetoothRemoteGATTServiceImpl.prototype.getIncludedService = function (service) {
return __awaiter(this, void 0, void 0, function () {

@@ -279,3 +290,3 @@ var services;

*/
BluetoothRemoteGATTService.prototype.getIncludedServices = function (service) {
BluetoothRemoteGATTServiceImpl.prototype.getIncludedServices = function (service) {
return __awaiter(this, void 0, void 0, function () {

@@ -291,3 +302,3 @@ var services, filtered;

if (!!this.services) return [3 /*break*/, 2];
return [4 /*yield*/, adapter_1.adapter.discoverIncludedServices(this.handle, this.device._allowedServices)];
return [4 /*yield*/, adapters_1.adapter.discoverIncludedServices(this.handle, this.device._allowedServices)];
case 1:

@@ -299,3 +310,3 @@ services = _a.sent();

});
return new BluetoothRemoteGATTService(serviceInfo);
return new BluetoothRemoteGATTServiceImpl(serviceInfo);
});

@@ -307,3 +318,3 @@ _a.label = 2;

}
filtered = this.services.filter(function (serviceObject) { return serviceObject.uuid === helpers_1.getServiceUUID(service); });
filtered = this.services.filter(function (serviceObject) { return serviceObject.uuid === uuid_1.BluetoothUUID.getService(service); });
if (filtered.length !== 1) {

@@ -317,5 +328,5 @@ throw new Error('getIncludedServices error: service not found');

};
return BluetoothRemoteGATTService;
}(dispatcher_1.EventDispatcher));
exports.BluetoothRemoteGATTService = BluetoothRemoteGATTService;
return BluetoothRemoteGATTServiceImpl;
}(events_1.EventDispatcher));
exports.BluetoothRemoteGATTServiceImpl = BluetoothRemoteGATTServiceImpl;
//# sourceMappingURL=service.js.map

@@ -26,2 +26,4 @@ /*

// TODO: this example needs updating to use watchadvertisements
const webbluetooth = require("../");

@@ -62,4 +64,4 @@

const deviceFound = bluetoothDevice => {
const uuid = webbluetooth.getServiceUUID(eddystoneUUID);
const eddyData = bluetoothDevice.adData.serviceData.get(uuid);
const uuid = webbluetooth.BluetoothUUID.getService(eddystoneUUID);
const eddyData = bluetoothDevice._adData.serviceData.get(uuid);
if (eddyData) {

@@ -66,0 +68,0 @@ const decoded = decodeEddystone(eddyData);

@@ -97,3 +97,3 @@ /*

await enumerateGatt(server);
await server.disconnect();
server.disconnect();

@@ -100,0 +100,0 @@ console.log("\ndisconnected");

{
"name": "webbluetooth",
"version": "2.2.0",
"description": "Node.js implementation of the Web Bluetooth Specification",
"homepage": "https://github.com/thegecko/webbluetooth",
"author": "Rob Moran <rob@thegecko.org>",
"license": "MIT",
"version": "3.0.2",
"main": "dist/index.js",
"author": "Rob Moran <rob@thegecko.org>",
"engines": {
"node": ">=10.20.0 <11.x || >=12.17.0 <13.0 || >=14.0.0"
},
"repository": {

@@ -15,28 +17,42 @@ "type": "git",

"web-bluetooth",
"webbluetooth",
"ble",
"bluetooth"
],
"engines": {
"node": ">=10.16.0"
},
"scripts": {
"prepare": "yarn build",
"clean": "git clean -f -x ./dist ./docs",
"build": "tsc && yarn lint && yarn docs",
"install": "prebuild-install --backend cmake-js --runtime napi || cmake-js rebuild",
"clean": "yarn clean:cpp && yarn clean:ts",
"clean:cpp": "cmake-js clean && git clean -fx ./prebuilds",
"clean:ts": "git clean -fx ./dist ./docs",
"build:all": "yarn build:cpp && yarn build:ts",
"build:cpp": "cmake-js compile",
"build:ts": "tsc && yarn lint && yarn docs",
"watch": "tsc -w --preserveWatchOutput",
"lint": "eslint . --ext .ts,.tsx",
"lint": "eslint . --ext .ts",
"test": "mocha --timeout 10000 test/*.test.js",
"prebuild": "prebuild --backend cmake-js --runtime napi --all --strip --verbose",
"docs": "typedoc"
},
"dependencies": {
"@abandonware/noble": "1.9.2-15",
"@types/node": "^10.16.0",
"@types/web-bluetooth": "^0.0.14"
"bindings": "^1.5.0",
"cmake-js": "^7.0.0",
"node-addon-api": "^6.1.0",
"prebuild-install": "^7.1.1"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.28.0",
"@typescript-eslint/parser": "^4.28.0",
"eslint": "^7.29.0",
"typedoc": "^0.20",
"typescript": "~4.2.4"
"@types/node": "^20.2.5",
"@types/web-bluetooth": "^0.0.17",
"@typescript-eslint/eslint-plugin": "^5.46.1",
"@typescript-eslint/parser": "^5.46.1",
"eslint": "^8.29.0",
"mocha": "^10.2.0",
"prebuild": "^11.0.4",
"typedoc": "^0.24.7",
"typescript": "^4.9.4"
},
"binary": {
"napi_versions": [
6
]
}
}
# Node Web Bluetooth
Node.js implementation of the Web Bluetooth Specification
Node.js implementation of the [Web Bluetooth Specification](https://webbluetoothcg.github.io/web-bluetooth/)
[![Build Status](https://github.com/thegecko/webbluetooth/workflows/ci/badge.svg)](https://github.com/thegecko/webbluetooth/actions)
[![Build Status](https://github.com/thegecko/webbluetooth/workflows/prebuild/badge.svg)](https://github.com/thegecko/webbluetooth/actions)
[![npm](https://img.shields.io/npm/dm/webbluetooth.svg)](https://www.npmjs.com/package/webbluetooth)

@@ -10,3 +10,3 @@ [![Licence MIT](https://img.shields.io/badge/licence-MIT-blue.svg)](http://opensource.org/licenses/MIT)

[Node.js > v10.16.0](https://nodejs.org), which includes `npm`.
[Node.js > v10.20.0](https://nodejs.org), which includes `npm`.

@@ -27,10 +27,10 @@ ## Installation

The module exports a default `navigator.bluetooth` instance, the `Bluetooth` class to allow you to instantiate your own bluetooth instances and some helper methods:
The module exports a default `navigator.bluetooth` instance, the `Bluetooth` class to allow you to instantiate your own bluetooth instances and the Bluetooth helper methods:
- [bluetooth](globals.html#bluetooth)
- [Bluetooth()](classes/bluetooth.html)
- [getCanonicalUUID()](globals.html#getcanonicaluuid)
- [getServiceUUID()](globals.html#getserviceuuid)
- [getCharacteristicUUID()](globals.html#getcharacteristicuuid)
- [getDescriptorUUID()](globals.html#getdescriptoruuid)
- [BluetoothUUID.getService()](globals.html)
- [BluetoothUUID.getCharacteristic()](globals.html)
- [BluetoothUUID.getDescriptor()](globals.html)
- [BluetoothUUID.canonicalUUID()](globals.html)

@@ -42,6 +42,6 @@ ### Using the default bluetooth instance

```JavaScript
const bluetooth = require("webbluetooth").bluetooth;
const bluetooth = require('webbluetooth').bluetooth;
const device = await bluetooth.requestDevice({
filters:[{ services:[ "heart_rate" ] }]
filters:[{ services:[ 'heart_rate' ] }]
});

@@ -60,7 +60,7 @@

```JavaScript
const Bluetooth = require("webbluetooth").Bluetooth;
const Bluetooth = require('webbluetooth').Bluetooth;
const deviceFound = (device, selectFn) => {
// If device can be automatically selected, do so by returning true
if (device.name === "myName") return true;
if (device.name === 'myName') return true;

@@ -73,3 +73,3 @@ // Otherwise store the selectFn somewhere and execute it later to select this device

const device = await bluetooth.requestDevice({
filters:[{ services:[ "heart_rate" ] }]
filters:[{ services:[ 'heart_rate' ] }]
});

@@ -91,13 +91,15 @@

- [x] referringDevice - specification unstable
- [x] getAvailability() - specification unstable
- [ ] getAvailability() - unsupported in adapter
- [x] referringDevice
- [x] requestDevice()
- [x] getDevices()
- [x] RequestDeviceOptions.name
- [x] RequestDeviceOptions.namePrefix
- [x] RequestDeviceOptions.services
- [x] RequestDeviceOptions.filter.name
- [x] RequestDeviceOptions.filter.namePrefix
- [x] RequestDeviceOptions.filter.services
- [x] RequestDeviceOptions.filter.manufacturerData
- [x] RequestDeviceOptions.filter.serviceData
- [x] RequestDeviceOptions.acceptAllDevices
- [x] RequestDeviceOptions.optionalServices
- [x] RequestDeviceOptions.acceptAllDevices
- [ ] RequestDeviceOptions.manufacturerData - specification unstable
- [ ] RequestDeviceOptions.serviceData - specification unstable
- [ ] RequestDeviceOptions.exclusionFilters
- [ ] RequestDeviceOptions.optionalManufacturerData - used in advertisements, unsupported in adapter

@@ -109,11 +111,10 @@ ### BluetoothDevice

- [x] gatt
- [ ] forget
- [ ] watchingAdvertisements - specification unstable
- [ ] watchAdvertisements() - specification unstable
- [ ] unwatchAdvertisements() - specification unstable
- [x] forget()
- [ ] watchAdvertisements() - unsupported in adapter
- [ ] watchingAdvertisements - unsupported in adapter
### BluetoothRemoteGATTServer
- [x] device
- [x] connected
- [x] device
- [x] connect()

@@ -126,16 +127,24 @@ - [x] disconnect()

- [x] uuid
- [x] device
- [x] uuid
- [x] isPrimary
- [x] getCharacteristic()
- [x] getCharacteristics()
- [x] getIncludedService()
- [x] getIncludedServices()
- [ ] getIncludedService() - unsupported in adapter
- [ ] getIncludedServices() - unsupported in adapter
### BluetoothRemoteGATTCharacteristic
- [x] uuid
- [x] service
- [x] uuid
- [x] properties
- [x] value
- [ ] properties.broadcast - unsupported in adapter
- [x] properties.read
- [x] properties.writeWithoutResponse
- [x] properties.write
- [x] properties.notify
- [x] properties.indicate
- [ ] properties.authenticatedSignedWrites - unsupported in adapter
- [ ] properties.reliableWrite - unsupported in adapter
- [ ] properties.writableAuxiliaries - unsupported in adapter
- [x] getDescriptor()

@@ -152,4 +161,4 @@ - [x] getDescriptors()

- [x] uuid
- [x] characteristic
- [x] uuid
- [x] value

@@ -159,2 +168,9 @@ - [x] readValue()

### BluetoothUUID
- [x] getService()
- [x] getCharacteristic()
- [x] getDescriptor()
- [x] canonicalUUID()
### Events

@@ -164,3 +180,3 @@

- [x] availabilitychanged
- [ ] availabilitychanged - unsupported in adapter

@@ -170,3 +186,3 @@ #### Bluetooth Device

- [x] gattserverdisconnected
- [ ] advertisementreceived - specification unstable
- [ ] advertisementreceived - unsupported in adapter

@@ -176,4 +192,4 @@ #### Bluetooth Service

- [x] serviceadded
- [ ] servicechanged - unsupported in noble
- [ ] serviceremoved - unsupported in noble
- [ ] servicechanged - unsupported in adapter
- [ ] serviceremoved - unsupported in adapter

@@ -187,5 +203,39 @@ #### Bluetooth Characteristic

- [x] Device selector hook
- [x] Lookups for known services, characteristics and descriptors
- [x] Canonical UUID helper
- [x] Examples
- [x] API Documentation
## Development
### Cloning
This repository uses a submodule to reference the SimpleBLE library. Clone it as follows:
```bash
git clone https://github.com/thegecko/webbluetooth
cd webbluetooth
git submodule update --init
```
### Building
To build the SimpleBLE module, bindings and TypeScriptsource, run:
``` bash
yarn build:all
```
### Testing
The tests are set up to use a BBC micro:bit in range with the following services available:
- Device Info Service (0000180a-0000-1000-8000-00805f9b34fb)
- LED Service (e95dd91d-251d-470a-a062-fa1922dfa9a8)
- Button Service (e95d9882-251d-470a-a062-fa1922dfa9a8)
Firmware for this hardware including the services can be found here: https://microbit.org/get-started/user-guide/firmware/
To run the tests:
```bash
yarn test
```

@@ -5,2 +5,3 @@ {

"alwaysStrict": true,
"downlevelIteration": true,
"noImplicitReturns": true,

@@ -7,0 +8,0 @@ "noEmitOnError": true,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc