Release rolling / release (push) Successful in 11m16s
Bump published pins (compact-encoding 3, bare-fetch/tls/https/ws 3, bare-subprocess 6, bare-signals 5, corestore 7.12, protomux 3.11, hypercore-crypto 3.7, bare-runtime 1.31) and regenerate catalogs, manifests, and kernel/seeder bundles. Adapt call sites to the new APIs: - Corestore: explicit session flush before suspend(); treeCache ctor opts - bare-crypto: KeyObject.export() instead of removed ._key - Protomux 3.11: wait for fullyOpened()/fullyClosed() on chat channels - bare-fetch: surface response.type and Headers.getSetCookie - host snapshots: bare-os 3.9 / bare-posix / bare-fs.statfs frsize - bare-subprocess 6: optional IPC channel + json serialization Keep catalog sync from wiping curated pearEntries. Teach the Node test shim to stub bare-thread/bare-worker (ESM absolute paths) and chain Bare.on so bare-timers can load. Booter 479, protocol 34, seeder 14.
1062 lines
37 KiB
JavaScript
1062 lines
37 KiB
JavaScript
var __bare_os_bundle_exports__ = (() => {
|
|
var __create = Object.create;
|
|
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __getProtoOf = Object.getPrototypeOf;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
}) : x)(function(x) {
|
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
});
|
|
var __commonJS = (cb, mod) => function __require2() {
|
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
};
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
// file that has been converted to a CommonJS file using a Babel-
|
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
mod
|
|
));
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
|
|
// ../../node_modules/bare-events/lib/errors.js
|
|
var require_errors = __commonJS({
|
|
"../../node_modules/bare-events/lib/errors.js"(exports, module) {
|
|
module.exports = class EventEmitterError extends Error {
|
|
constructor(msg, code, fn = EventEmitterError, opts) {
|
|
super(`${code}: ${msg}`, opts);
|
|
this.code = code;
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(this, fn);
|
|
}
|
|
}
|
|
get name() {
|
|
return "EventEmitterError";
|
|
}
|
|
static OPERATION_ABORTED(cause, msg = "Operation aborted") {
|
|
return new EventEmitterError(msg, "OPERATION_ABORTED", EventEmitterError.OPERATION_ABORTED, {
|
|
cause
|
|
});
|
|
}
|
|
static UNHANDLED_ERROR(cause, msg = "Unhandled error") {
|
|
return new EventEmitterError(msg, "UNHANDLED_ERROR", EventEmitterError.UNHANDLED_ERROR, {
|
|
cause
|
|
});
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-events/index.js
|
|
var require_bare_events = __commonJS({
|
|
"../../node_modules/bare-events/index.js"(exports, module) {
|
|
var errors = require_errors();
|
|
var EventListener = class {
|
|
constructor() {
|
|
this.list = [];
|
|
this.count = 0;
|
|
}
|
|
append(ctx, name, fn, once) {
|
|
this.count++;
|
|
ctx.emit("newListener", name, fn);
|
|
this.list.push([fn, once]);
|
|
}
|
|
prepend(ctx, name, fn, once) {
|
|
this.count++;
|
|
ctx.emit("newListener", name, fn);
|
|
this.list.unshift([fn, once]);
|
|
}
|
|
remove(ctx, name, fn) {
|
|
for (let i = 0, n = this.list.length; i < n; i++) {
|
|
const l = this.list[i];
|
|
if (l[0] === fn) {
|
|
this.list.splice(i, 1);
|
|
if (this.count === 1) delete ctx._events[name];
|
|
ctx.emit("removeListener", name, fn);
|
|
this.count--;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
removeAll(ctx, name) {
|
|
const list = [...this.list];
|
|
this.list = [];
|
|
if (this.count === list.length) delete ctx._events[name];
|
|
for (let i = list.length - 1; i >= 0; i--) {
|
|
ctx.emit("removeListener", name, list[i][0]);
|
|
}
|
|
this.count -= list.length;
|
|
}
|
|
emit(ctx, name, ...args) {
|
|
const list = [...this.list];
|
|
for (let i = 0, n = list.length; i < n; i++) {
|
|
const l = list[i];
|
|
if (l[1] === true) this.remove(ctx, name, l[0]);
|
|
Reflect.apply(l[0], ctx, args);
|
|
}
|
|
return list.length > 0;
|
|
}
|
|
};
|
|
function appendListener(ctx, name, fn, once) {
|
|
if (ctx._events === void 0) ctx._events = /* @__PURE__ */ Object.create(null);
|
|
const e = ctx._events[name] || (ctx._events[name] = new EventListener());
|
|
e.append(ctx, name, fn, once);
|
|
return ctx;
|
|
}
|
|
function prependListener(ctx, name, fn, once) {
|
|
if (ctx._events === void 0) ctx._events = /* @__PURE__ */ Object.create(null);
|
|
const e = ctx._events[name] || (ctx._events[name] = new EventListener());
|
|
e.prepend(ctx, name, fn, once);
|
|
return ctx;
|
|
}
|
|
function removeListener(ctx, name, fn) {
|
|
if (ctx._events === void 0) return ctx;
|
|
const e = ctx._events[name];
|
|
if (e !== void 0) e.remove(ctx, name, fn);
|
|
return ctx;
|
|
}
|
|
function throwUnhandledError(...args) {
|
|
let err;
|
|
if (args.length > 0) err = args[0];
|
|
if (err instanceof Error === false) err = errors.UNHANDLED_ERROR(err);
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(err, exports.prototype.emit);
|
|
}
|
|
queueMicrotask(() => {
|
|
throw err;
|
|
});
|
|
}
|
|
module.exports = exports = class EventEmitter {
|
|
constructor() {
|
|
this._events = /* @__PURE__ */ Object.create(null);
|
|
}
|
|
addListener(name, fn) {
|
|
return appendListener(this, name, fn, false);
|
|
}
|
|
addOnceListener(name, fn) {
|
|
return appendListener(this, name, fn, true);
|
|
}
|
|
prependListener(name, fn) {
|
|
return prependListener(this, name, fn, false);
|
|
}
|
|
prependOnceListener(name, fn) {
|
|
return prependListener(this, name, fn, true);
|
|
}
|
|
removeListener(name, fn) {
|
|
return removeListener(this, name, fn);
|
|
}
|
|
on(name, fn) {
|
|
return appendListener(this, name, fn, false);
|
|
}
|
|
once(name, fn) {
|
|
return appendListener(this, name, fn, true);
|
|
}
|
|
off(name, fn) {
|
|
return removeListener(this, name, fn);
|
|
}
|
|
emit(name, ...args) {
|
|
if (name === "error" && this._events !== void 0 && this._events.error === void 0) {
|
|
throwUnhandledError(...args);
|
|
}
|
|
if (this._events === void 0) return false;
|
|
const e = this._events[name];
|
|
return e === void 0 ? false : e.emit(this, name, ...args);
|
|
}
|
|
listeners(name) {
|
|
if (this._events === void 0) return [];
|
|
const e = this._events[name];
|
|
return e === void 0 ? [] : [...e.list];
|
|
}
|
|
rawListeners(name) {
|
|
if (this._events === void 0) return [];
|
|
const e = this._events[name];
|
|
return e === void 0 ? [] : e.list.map((l) => l[0]);
|
|
}
|
|
eventNames() {
|
|
if (this._events === void 0) return [];
|
|
return Reflect.ownKeys(this._events);
|
|
}
|
|
listenerCount(name) {
|
|
if (this._events === void 0) return 0;
|
|
const e = this._events[name];
|
|
return e === void 0 ? 0 : e.list.length;
|
|
}
|
|
getMaxListeners() {
|
|
return EventEmitter.defaultMaxListeners;
|
|
}
|
|
setMaxListeners(n) {
|
|
}
|
|
removeAllListeners(name) {
|
|
if (arguments.length === 0) {
|
|
for (const key of Reflect.ownKeys(this._events)) {
|
|
if (key === "removeListener") continue;
|
|
this.removeAllListeners(key);
|
|
}
|
|
this.removeAllListeners("removeListener");
|
|
} else {
|
|
const e = this._events[name];
|
|
if (e !== void 0) e.removeAll(this, name);
|
|
}
|
|
return this;
|
|
}
|
|
};
|
|
exports.EventEmitter = exports;
|
|
exports.errors = errors;
|
|
exports.defaultMaxListeners = 10;
|
|
exports.on = function on(emitter, name, opts = {}) {
|
|
const { signal } = opts;
|
|
if (signal && signal.aborted) {
|
|
throw errors.OPERATION_ABORTED(signal.reason);
|
|
}
|
|
let error = null;
|
|
let done = false;
|
|
const events = [];
|
|
const promises = [];
|
|
if (name !== "error") emitter.on("error", onerror);
|
|
if (signal) signal.addEventListener("abort", onabort);
|
|
emitter.on(name, onevent);
|
|
return {
|
|
next() {
|
|
if (events.length) {
|
|
return Promise.resolve({ value: events.shift(), done: false });
|
|
}
|
|
if (error) {
|
|
const err = error;
|
|
error = null;
|
|
return Promise.reject(err);
|
|
}
|
|
if (done) return onclose();
|
|
return new Promise((resolve, reject) => promises.push({ resolve, reject }));
|
|
},
|
|
return() {
|
|
return onclose();
|
|
},
|
|
throw(err) {
|
|
return onerror(err);
|
|
},
|
|
[Symbol.asyncIterator]() {
|
|
return this;
|
|
}
|
|
};
|
|
function onevent(...args) {
|
|
if (promises.length) {
|
|
promises.shift().resolve({ value: args, done: false });
|
|
} else {
|
|
events.push(args);
|
|
}
|
|
}
|
|
function onerror(err) {
|
|
emitter.off(name, onevent).off("error", onerror);
|
|
if (promises.length) {
|
|
promises.shift().reject(err);
|
|
} else {
|
|
error = err;
|
|
}
|
|
return Promise.resolve({ done: true });
|
|
}
|
|
function onabort() {
|
|
signal.removeEventListener("abort", onabort);
|
|
onerror(errors.OPERATION_ABORTED(signal.reason));
|
|
}
|
|
function onclose() {
|
|
emitter.off(name, onevent);
|
|
if (name !== "error") emitter.off("error", onerror);
|
|
if (signal) signal.removeEventListener("abort", onabort);
|
|
done = true;
|
|
if (promises.length) promises.shift().resolve({ done: true });
|
|
return Promise.resolve({ done: true });
|
|
}
|
|
};
|
|
exports.once = function once(emitter, name, opts = {}) {
|
|
const { signal } = opts;
|
|
if (signal && signal.aborted) {
|
|
return Promise.reject(errors.OPERATION_ABORTED(signal.reason));
|
|
}
|
|
return new Promise((resolve, reject) => {
|
|
if (name !== "error") emitter.on("error", onerror);
|
|
if (signal) signal.addEventListener("abort", onabort);
|
|
emitter.once(name, onevent);
|
|
function onevent(...args) {
|
|
if (name !== "error") emitter.off("error", onerror);
|
|
if (signal) signal.removeEventListener("abort", onabort);
|
|
resolve(args);
|
|
}
|
|
function onerror(err) {
|
|
emitter.off(name, onevent);
|
|
if (name !== "error") emitter.off("error", onerror);
|
|
reject(err);
|
|
}
|
|
function onabort() {
|
|
signal.removeEventListener("abort", onabort);
|
|
onerror(errors.OPERATION_ABORTED(signal.reason));
|
|
}
|
|
});
|
|
};
|
|
exports.forward = function forward(from, to, names, opts = {}) {
|
|
if (typeof names === "string") names = [names];
|
|
const { emit = to.emit.bind(to) } = opts;
|
|
const listeners = names.map(
|
|
(name) => function onevent(...args) {
|
|
emit(name, ...args);
|
|
}
|
|
);
|
|
to.on("newListener", (name) => {
|
|
const i = names.indexOf(name);
|
|
if (i !== -1 && to.listenerCount(name) === 0) {
|
|
from.on(name, listeners[i]);
|
|
}
|
|
}).on("removeListener", (name) => {
|
|
const i = names.indexOf(name);
|
|
if (i !== -1 && to.listenerCount(name) === 0) {
|
|
from.off(name, listeners[i]);
|
|
}
|
|
});
|
|
};
|
|
exports.listenerCount = function listenerCount(emitter, name) {
|
|
return emitter.listenerCount(name);
|
|
};
|
|
exports.getMaxListeners = function getMaxListeners(emitter) {
|
|
if (typeof emitter.getMaxListeners === "function") {
|
|
return emitter.getMaxListeners();
|
|
}
|
|
return exports.defaultMaxListeners;
|
|
};
|
|
exports.setMaxListeners = function setMaxListeners(n, ...emitters) {
|
|
if (emitters.length === 0) exports.defaultMaxListeners = n;
|
|
else {
|
|
for (const emitter of emitters) {
|
|
if (typeof emitter.setMaxListeners === "function") {
|
|
emitter.setMaxListeners(n);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-bluetooth-linux/binding.js
|
|
var require_binding = __commonJS({
|
|
"../../node_modules/bare-bluetooth-linux/binding.js"(exports, module) {
|
|
module.exports = __require.addon();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-bluetooth-linux/lib/device.js
|
|
var require_device = __commonJS({
|
|
"../../node_modules/bare-bluetooth-linux/lib/device.js"(exports, module) {
|
|
var EventEmitter = require_bare_events();
|
|
var binding = require_binding();
|
|
module.exports = exports = class Device extends EventEmitter {
|
|
constructor(adapter, path, address) {
|
|
super();
|
|
this._adapter = adapter;
|
|
this._path = path;
|
|
this._address = address;
|
|
this._services = /* @__PURE__ */ new Map();
|
|
}
|
|
get services() {
|
|
return this._services;
|
|
}
|
|
get path() {
|
|
return this._path;
|
|
}
|
|
get address() {
|
|
return this._address;
|
|
}
|
|
get name() {
|
|
if (this._adapter._destroyed) return;
|
|
return binding.deviceGetName(this._adapter._handle, this._path);
|
|
}
|
|
get rssi() {
|
|
if (this._adapter._destroyed) return;
|
|
return binding.deviceGetRSSI(this._adapter._handle, this._path);
|
|
}
|
|
get paired() {
|
|
if (this._adapter._destroyed) return;
|
|
return binding.deviceGetPaired(this._adapter._handle, this._path);
|
|
}
|
|
get connected() {
|
|
if (this._adapter._destroyed) return;
|
|
return binding.deviceGetConnected(this._adapter._handle, this._path);
|
|
}
|
|
get servicesResolved() {
|
|
if (this._adapter._destroyed) return;
|
|
return binding.deviceGetServicesResolved(this._adapter._handle, this._path);
|
|
}
|
|
get uuids() {
|
|
if (this._adapter._destroyed) return [];
|
|
return binding.deviceGetUUIDs(this._adapter._handle, this._path);
|
|
}
|
|
get manufacturerData() {
|
|
if (this._adapter._destroyed) return {};
|
|
const result = {};
|
|
binding.deviceGetManufacturerData(this._adapter._handle, this._path, result);
|
|
return result;
|
|
}
|
|
get serviceData() {
|
|
if (this._adapter._destroyed) return {};
|
|
const result = {};
|
|
binding.deviceGetServiceData(this._adapter._handle, this._path, result);
|
|
return result;
|
|
}
|
|
connect() {
|
|
if (this._adapter._destroyed) return;
|
|
return new Promise((resolve, reject) => {
|
|
binding.deviceConnect(this._adapter._handle, this._path, (err) => {
|
|
if (err) reject(err);
|
|
else resolve();
|
|
});
|
|
});
|
|
}
|
|
disconnect() {
|
|
if (this._adapter._destroyed) return;
|
|
return new Promise((resolve, reject) => {
|
|
binding.deviceDisconnect(this._adapter._handle, this._path, (err) => {
|
|
if (err) reject(err);
|
|
else resolve();
|
|
});
|
|
});
|
|
}
|
|
pair() {
|
|
if (this._adapter._destroyed) return;
|
|
return new Promise((resolve, reject) => {
|
|
binding.devicePair(this._adapter._handle, this._path, (err) => {
|
|
if (err) reject(err);
|
|
else resolve();
|
|
});
|
|
});
|
|
}
|
|
[Symbol.for("bare.inspect")]() {
|
|
return {
|
|
__proto__: { constructor: Device },
|
|
path: this.path,
|
|
address: this.address,
|
|
name: this.name
|
|
};
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-bluetooth-linux/lib/service.js
|
|
var require_service = __commonJS({
|
|
"../../node_modules/bare-bluetooth-linux/lib/service.js"(exports, module) {
|
|
var EventEmitter = require_bare_events();
|
|
var binding = require_binding();
|
|
module.exports = exports = class Service extends EventEmitter {
|
|
constructor(device, path, uuid) {
|
|
super();
|
|
this._device = device;
|
|
this._path = path;
|
|
this._uuid = uuid;
|
|
this._characteristics = /* @__PURE__ */ new Map();
|
|
}
|
|
get path() {
|
|
return this._path;
|
|
}
|
|
get uuid() {
|
|
return this._uuid;
|
|
}
|
|
get characteristics() {
|
|
return this._characteristics;
|
|
}
|
|
get primary() {
|
|
if (this._device._adapter._destroyed) return;
|
|
return binding.serviceIsPrimary(this._device._adapter._handle, this._path);
|
|
}
|
|
[Symbol.for("bare.inspect")]() {
|
|
return {
|
|
__proto__: { constructor: Service },
|
|
uuid: this.uuid,
|
|
primary: this.primary
|
|
};
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-bluetooth-linux/lib/characteristic.js
|
|
var require_characteristic = __commonJS({
|
|
"../../node_modules/bare-bluetooth-linux/lib/characteristic.js"(exports, module) {
|
|
var EventEmitter = require_bare_events();
|
|
var binding = require_binding();
|
|
module.exports = exports = class Characteristic extends EventEmitter {
|
|
constructor(adapter, path, uuid) {
|
|
super();
|
|
this._adapter = adapter;
|
|
this._path = path;
|
|
this._uuid = uuid;
|
|
this._descriptors = /* @__PURE__ */ new Map();
|
|
}
|
|
get descriptors() {
|
|
return this._descriptors;
|
|
}
|
|
get path() {
|
|
return this._path;
|
|
}
|
|
get uuid() {
|
|
return this._uuid;
|
|
}
|
|
get flags() {
|
|
if (this._adapter._destroyed) return [];
|
|
return binding.charGetFlags(this._adapter._handle, this._path);
|
|
}
|
|
get mtu() {
|
|
if (this._adapter._destroyed) return void 0;
|
|
return binding.charGetMTU(this._adapter._handle, this._path);
|
|
}
|
|
read() {
|
|
if (this._adapter._destroyed) return;
|
|
return new Promise((resolve, reject) => {
|
|
binding.charRead(this._adapter._handle, this._path, (err, buffer) => {
|
|
if (err) reject(err);
|
|
else resolve(buffer);
|
|
});
|
|
});
|
|
}
|
|
write(value, opts = {}) {
|
|
if (this._adapter._destroyed) return;
|
|
return new Promise((resolve, reject) => {
|
|
binding.charWrite(this._adapter._handle, this._path, value, opts.type, (err) => {
|
|
if (err) reject(err);
|
|
else resolve();
|
|
});
|
|
});
|
|
}
|
|
startNotify() {
|
|
if (this._adapter._destroyed) return;
|
|
return new Promise((resolve, reject) => {
|
|
binding.charStartNotify(this._adapter._handle, this._path, (err) => {
|
|
if (err) reject(err);
|
|
else resolve();
|
|
});
|
|
});
|
|
}
|
|
stopNotify() {
|
|
if (this._adapter._destroyed) return;
|
|
return new Promise((resolve, reject) => {
|
|
binding.charStopNotify(this._adapter._handle, this._path, (err) => {
|
|
if (err) reject(err);
|
|
else resolve();
|
|
});
|
|
});
|
|
}
|
|
[Symbol.for("bare.inspect")]() {
|
|
return {
|
|
__proto__: { constructor: Characteristic },
|
|
uuid: this.uuid,
|
|
path: this.path
|
|
};
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-bluetooth-linux/lib/descriptor.js
|
|
var require_descriptor = __commonJS({
|
|
"../../node_modules/bare-bluetooth-linux/lib/descriptor.js"(exports, module) {
|
|
var EventEmitter = require_bare_events();
|
|
var binding = require_binding();
|
|
module.exports = exports = class Descriptor extends EventEmitter {
|
|
constructor(adapter, path, uuid) {
|
|
super();
|
|
this._adapter = adapter;
|
|
this._path = path;
|
|
this._uuid = uuid;
|
|
}
|
|
get path() {
|
|
return this._path;
|
|
}
|
|
get uuid() {
|
|
return this._uuid;
|
|
}
|
|
get flags() {
|
|
if (this._adapter._destroyed) return [];
|
|
return binding.descGetFlags(this._adapter._handle, this._path);
|
|
}
|
|
read() {
|
|
if (this._adapter._destroyed) return;
|
|
return new Promise((resolve, reject) => {
|
|
binding.descRead(this._adapter._handle, this._path, (err, buffer) => {
|
|
if (err) reject(err);
|
|
else resolve(buffer);
|
|
});
|
|
});
|
|
}
|
|
write(value) {
|
|
if (this._adapter._destroyed) return;
|
|
return new Promise((resolve, reject) => {
|
|
binding.descWrite(this._adapter._handle, this._path, value, (err) => {
|
|
if (err) reject(err);
|
|
else resolve();
|
|
});
|
|
});
|
|
}
|
|
[Symbol.for("bare.inspect")]() {
|
|
return {
|
|
__proto__: { constructor: Descriptor },
|
|
uuid: this.uuid,
|
|
path: this.path
|
|
};
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-bluetooth-linux/lib/adapter.js
|
|
var require_adapter = __commonJS({
|
|
"../../node_modules/bare-bluetooth-linux/lib/adapter.js"(exports, module) {
|
|
var EventEmitter = require_bare_events();
|
|
var binding = require_binding();
|
|
var Device = require_device();
|
|
var Service = require_service();
|
|
var Characteristic = require_characteristic();
|
|
var Descriptor = require_descriptor();
|
|
module.exports = exports = class Adapter extends EventEmitter {
|
|
constructor(opts = {}) {
|
|
super();
|
|
this._path = opts.path || "/org/bluez/hci0";
|
|
this._destroyed = false;
|
|
this._devices = /* @__PURE__ */ new Map();
|
|
this._gattApp = null;
|
|
this._handle = binding.adapterInit(
|
|
this._path,
|
|
this,
|
|
this._ondeviceadded,
|
|
this._ondeviceremoved,
|
|
this._onserviceadded,
|
|
this._onserviceremoved,
|
|
this._oncharadded,
|
|
this._oncharremoved,
|
|
this._ondescadded,
|
|
this._ondescremoved,
|
|
this._oncharvalue,
|
|
this._ondevicepropschanged,
|
|
this._onadvertisementrelease,
|
|
this._ongattcharacteristicwrite
|
|
);
|
|
}
|
|
get path() {
|
|
return this._path;
|
|
}
|
|
get powered() {
|
|
return binding.adapterGetPowered(this._handle);
|
|
}
|
|
set powered(val) {
|
|
binding.adapterSetPowered(this._handle, val);
|
|
}
|
|
get discovering() {
|
|
return binding.adapterGetDiscovering(this._handle);
|
|
}
|
|
get address() {
|
|
return binding.adapterGetAddress(this._handle);
|
|
}
|
|
get devices() {
|
|
return this._devices;
|
|
}
|
|
setDiscoveryFilter({ uuids = [], rssi, transport } = {}) {
|
|
binding.adapterSetDiscoveryFilter(this._handle, uuids, rssi, transport);
|
|
}
|
|
startDiscovery() {
|
|
binding.adapterStartDiscovery(this._handle);
|
|
}
|
|
stopDiscovery() {
|
|
binding.adapterStopDiscovery(this._handle);
|
|
}
|
|
registerAdvertisement(advertisement) {
|
|
if (this._destroyed) return Promise.reject(new Error("Adapter is destroyed"));
|
|
return new Promise((resolve, reject) => {
|
|
binding.advertisementRegister(
|
|
this._handle,
|
|
advertisement.type,
|
|
advertisement.serviceUUIDs,
|
|
advertisement.localName,
|
|
(err) => {
|
|
if (err) reject(err);
|
|
else resolve();
|
|
}
|
|
);
|
|
});
|
|
}
|
|
unregisterAdvertisement(advertisement) {
|
|
if (this._destroyed) return Promise.reject(new Error("Adapter is destroyed"));
|
|
return new Promise((resolve, reject) => {
|
|
binding.advertisementUnregister(this._handle, (err) => {
|
|
if (err) reject(err);
|
|
else resolve();
|
|
});
|
|
});
|
|
}
|
|
registerApplication(application) {
|
|
if (this._destroyed) return Promise.reject(new Error("Adapter is destroyed"));
|
|
if (this._gattApp) return Promise.reject(new Error("An application is already registered"));
|
|
this._gattApp = application;
|
|
for (let i = 0; i < application.services.length; i++) {
|
|
const svc = application.services[i];
|
|
const svcIdx = binding.gattServiceAdd(this._handle, application.path, svc.uuid, svc.primary);
|
|
for (let j = 0; j < svc.characteristics.length; j++) {
|
|
const ch = svc.characteristics[j];
|
|
ch._path = binding.gattCharacteristicAdd(
|
|
this._handle,
|
|
svcIdx,
|
|
ch.uuid,
|
|
ch.flags,
|
|
ch.value instanceof Uint8Array ? ch.value : new Uint8Array(ch.value)
|
|
);
|
|
ch._adapter = this;
|
|
}
|
|
}
|
|
return new Promise((resolve, reject) => {
|
|
binding.gattRegister(this._handle, (err) => {
|
|
if (err) reject(err);
|
|
else resolve();
|
|
});
|
|
});
|
|
}
|
|
unregisterApplication(application) {
|
|
if (this._destroyed) return Promise.reject(new Error("Adapter is destroyed"));
|
|
return new Promise((resolve, reject) => {
|
|
binding.gattUnregister(this._handle, (err) => {
|
|
if (err) {
|
|
reject(err);
|
|
} else {
|
|
this._gattApp._reset();
|
|
this._gattApp = null;
|
|
resolve();
|
|
}
|
|
});
|
|
});
|
|
}
|
|
destroy() {
|
|
if (this._destroyed) return;
|
|
this._destroyed = true;
|
|
this._devices.clear();
|
|
if (this._gattApp) {
|
|
binding.gattUnregister(this._handle, () => {
|
|
});
|
|
this._gattApp._reset();
|
|
this._gattApp = null;
|
|
}
|
|
binding.adapterDestroy(this._handle);
|
|
}
|
|
[Symbol.dispose]() {
|
|
this.destroy();
|
|
}
|
|
[Symbol.for("bare.inspect")]() {
|
|
return {
|
|
__proto__: { constructor: Adapter },
|
|
path: this.path,
|
|
powered: this.powered,
|
|
discovering: this.discovering
|
|
};
|
|
}
|
|
_ondeviceadded(path, address) {
|
|
const device = new Device(this, path, address);
|
|
this._devices.set(path, device);
|
|
this.emit("device", device);
|
|
}
|
|
_ondeviceremoved(path) {
|
|
const device = this._devices.get(path);
|
|
if (device) {
|
|
this._devices.delete(path);
|
|
this.emit("deviceRemoved", device);
|
|
}
|
|
}
|
|
_onserviceadded(path, devicePath, uuid) {
|
|
const device = this._devices.get(devicePath);
|
|
if (device) {
|
|
const service = new Service(device, path, uuid);
|
|
device._services.set(path, service);
|
|
device.emit("service", service);
|
|
}
|
|
}
|
|
_onserviceremoved(path, devicePath) {
|
|
const device = this._devices.get(devicePath);
|
|
if (device) {
|
|
const service = device._services.get(path);
|
|
if (service) {
|
|
device._services.delete(path);
|
|
device.emit("serviceRemoved", service);
|
|
}
|
|
}
|
|
}
|
|
_oncharadded(path, servicePath, uuid) {
|
|
for (const device of this._devices.values()) {
|
|
const service = device._services.get(servicePath);
|
|
if (service) {
|
|
const characteristic = new Characteristic(this, path, uuid);
|
|
service._characteristics.set(path, characteristic);
|
|
service.emit("characteristic", characteristic);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
_oncharremoved(path, servicePath) {
|
|
for (const device of this._devices.values()) {
|
|
const service = device._services.get(servicePath);
|
|
if (service) {
|
|
const characteristic = service._characteristics.get(path);
|
|
if (characteristic) {
|
|
service._characteristics.delete(path);
|
|
service.emit("characteristicRemoved", characteristic);
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
_ondescadded(path, charPath, uuid) {
|
|
for (const device of this._devices.values()) {
|
|
for (const service of device._services.values()) {
|
|
const characteristic = service._characteristics.get(charPath);
|
|
if (characteristic) {
|
|
const descriptor = new Descriptor(this, path, uuid);
|
|
characteristic._descriptors.set(path, descriptor);
|
|
characteristic.emit("descriptor", descriptor);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
_ondescremoved(path, charPath) {
|
|
for (const device of this._devices.values()) {
|
|
for (const service of device._services.values()) {
|
|
const characteristic = service._characteristics.get(charPath);
|
|
if (characteristic) {
|
|
const descriptor = characteristic._descriptors.get(path);
|
|
if (descriptor) {
|
|
characteristic._descriptors.delete(path);
|
|
characteristic.emit("descriptorRemoved", descriptor);
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
_ondevicepropschanged(path, connected, paired, servicesResolved, rssi, name) {
|
|
const device = this._devices.get(path);
|
|
if (!device) return;
|
|
if (connected !== void 0) device.emit("connected", connected);
|
|
if (paired !== void 0) device.emit("paired", paired);
|
|
if (servicesResolved !== void 0) device.emit("servicesResolved", servicesResolved);
|
|
if (rssi !== void 0) device.emit("rssi", rssi);
|
|
if (name !== void 0) device.emit("name", name);
|
|
}
|
|
_onadvertisementrelease() {
|
|
this.emit("advertisementReleased");
|
|
}
|
|
_ongattcharacteristicwrite(path, value) {
|
|
if (!this._gattApp) return;
|
|
for (const svc of this._gattApp.services) {
|
|
for (const ch of svc.characteristics) {
|
|
if (ch._path === path) {
|
|
ch._value = value;
|
|
ch.emit("write", value);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
_oncharvalue(path, buffer) {
|
|
for (const device of this._devices.values()) {
|
|
for (const service of device._services.values()) {
|
|
const characteristic = service._characteristics.get(path);
|
|
if (characteristic) {
|
|
characteristic.emit("data", buffer);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-bluetooth-linux/lib/advertisement.js
|
|
var require_advertisement = __commonJS({
|
|
"../../node_modules/bare-bluetooth-linux/lib/advertisement.js"(exports, module) {
|
|
module.exports = exports = class Advertisement {
|
|
constructor({ type = "peripheral", localName, serviceUUIDs = [] } = {}) {
|
|
this._type = type;
|
|
this._localName = localName;
|
|
this._serviceUUIDs = serviceUUIDs;
|
|
}
|
|
get type() {
|
|
return this._type;
|
|
}
|
|
get localName() {
|
|
return this._localName;
|
|
}
|
|
get serviceUUIDs() {
|
|
return this._serviceUUIDs;
|
|
}
|
|
[Symbol.for("bare.inspect")]() {
|
|
return {
|
|
__proto__: { constructor: Advertisement },
|
|
type: this.type,
|
|
localName: this.localName,
|
|
serviceUUIDs: this.serviceUUIDs
|
|
};
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-bluetooth-linux/lib/gatt-application.js
|
|
var require_gatt_application = __commonJS({
|
|
"../../node_modules/bare-bluetooth-linux/lib/gatt-application.js"(exports, module) {
|
|
module.exports = exports = class GattApplication {
|
|
constructor({ path } = {}) {
|
|
this._path = path;
|
|
this._services = [];
|
|
}
|
|
get path() {
|
|
return this._path;
|
|
}
|
|
get services() {
|
|
return this._services;
|
|
}
|
|
addService(service) {
|
|
this._services.push(service);
|
|
}
|
|
_reset() {
|
|
for (const svc of this._services) {
|
|
for (const ch of svc.characteristics) {
|
|
ch._reset();
|
|
}
|
|
}
|
|
}
|
|
[Symbol.for("bare.inspect")]() {
|
|
return {
|
|
__proto__: { constructor: GattApplication },
|
|
path: this.path,
|
|
services: this.services
|
|
};
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-bluetooth-linux/lib/gatt-service.js
|
|
var require_gatt_service = __commonJS({
|
|
"../../node_modules/bare-bluetooth-linux/lib/gatt-service.js"(exports, module) {
|
|
module.exports = exports = class GattService {
|
|
constructor({ uuid, primary = true } = {}) {
|
|
this._uuid = uuid;
|
|
this._primary = primary;
|
|
this._characteristics = [];
|
|
}
|
|
get uuid() {
|
|
return this._uuid;
|
|
}
|
|
get primary() {
|
|
return this._primary;
|
|
}
|
|
get characteristics() {
|
|
return this._characteristics;
|
|
}
|
|
addCharacteristic(characteristic) {
|
|
this._characteristics.push(characteristic);
|
|
}
|
|
[Symbol.for("bare.inspect")]() {
|
|
return {
|
|
__proto__: { constructor: GattService },
|
|
uuid: this.uuid,
|
|
primary: this.primary,
|
|
characteristics: this.characteristics
|
|
};
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-bluetooth-linux/lib/gatt-characteristic.js
|
|
var require_gatt_characteristic = __commonJS({
|
|
"../../node_modules/bare-bluetooth-linux/lib/gatt-characteristic.js"(exports, module) {
|
|
var EventEmitter = require_bare_events();
|
|
var binding = require_binding();
|
|
module.exports = exports = class GattCharacteristic extends EventEmitter {
|
|
constructor({ uuid, flags = [], value = new Uint8Array() } = {}) {
|
|
super();
|
|
this._uuid = uuid;
|
|
this._flags = flags;
|
|
this._value = value;
|
|
this._adapter = null;
|
|
this._path = null;
|
|
}
|
|
get uuid() {
|
|
return this._uuid;
|
|
}
|
|
get flags() {
|
|
return this._flags;
|
|
}
|
|
get value() {
|
|
return this._value;
|
|
}
|
|
_reset() {
|
|
this._adapter = null;
|
|
this._path = null;
|
|
}
|
|
set value(v) {
|
|
this._value = v;
|
|
if (this._adapter && this._path) {
|
|
binding.gattCharacteristicSetValue(
|
|
this._adapter._handle,
|
|
this._path,
|
|
v instanceof Uint8Array ? v : new Uint8Array(v)
|
|
);
|
|
}
|
|
}
|
|
[Symbol.for("bare.inspect")]() {
|
|
return {
|
|
__proto__: { constructor: GattCharacteristic },
|
|
uuid: this.uuid,
|
|
flags: this.flags
|
|
};
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-bluetooth-linux/index.js
|
|
var require_bare_bluetooth_linux = __commonJS({
|
|
"../../node_modules/bare-bluetooth-linux/index.js"(exports) {
|
|
exports.Adapter = require_adapter();
|
|
exports.Device = require_device();
|
|
exports.Service = require_service();
|
|
exports.Characteristic = require_characteristic();
|
|
exports.Descriptor = require_descriptor();
|
|
exports.Advertisement = require_advertisement();
|
|
exports.GattApplication = require_gatt_application();
|
|
exports.GattService = require_gatt_service();
|
|
exports.GattCharacteristic = require_gatt_characteristic();
|
|
}
|
|
});
|
|
|
|
// ../../bare-lib-entry-bareBluetoothLinux.js
|
|
var bare_lib_entry_bareBluetoothLinux_exports = {};
|
|
__export(bare_lib_entry_bareBluetoothLinux_exports, {
|
|
default: () => bare_lib_entry_bareBluetoothLinux_default
|
|
});
|
|
var import_bare_bluetooth_linux = __toESM(require_bare_bluetooth_linux());
|
|
var bare_lib_entry_bareBluetoothLinux_default = import_bare_bluetooth_linux.default;
|
|
return __toCommonJS(bare_lib_entry_bareBluetoothLinux_exports);
|
|
})();
|
|
;(function(){var g=globalThis;var s="__bare_os_stdlib__";g[s]=g[s]||{};var e=typeof __bare_os_bundle_exports__!=="undefined"?__bare_os_bundle_exports__:void 0;var v=e!=null&&typeof e==="object"&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;g[s]["bareBluetoothLinux"]=v;})();
|