libpeerdiscovery/dist/index.js

44 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-12-20 12:28:01 +00:00
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PeerDiscovery = void 0;
const b4a_1 = __importDefault(require("b4a"));
class PeerDiscovery {
_sources = new Map();
registerSource(name, source) {
if (this._sources.has(name)) {
return false;
}
this._sources.set(name, source);
return true;
}
removeSource(name) {
if (!this._sources.has(name)) {
return false;
}
this._sources.delete(name);
return true;
}
2023-01-15 08:36:25 +00:00
removeAllSources() {
this._sources.clear();
}
2023-01-15 08:50:17 +00:00
sourceExists(name) {
return this._sources.has(name);
}
2023-01-15 07:58:50 +00:00
async discover(pubkey, options = {}) {
2022-12-20 12:28:01 +00:00
if (!b4a_1.default.isBuffer(pubkey)) {
pubkey = b4a_1.default.from(pubkey, "hex");
}
for (const source of this._sources.values()) {
2023-01-15 07:58:50 +00:00
const result = await source(pubkey, options);
2022-12-20 12:28:01 +00:00
if (result) {
return result;
}
}
return false;
}
}
exports.PeerDiscovery = PeerDiscovery;
//# sourceMappingURL=index.js.map