Fix nostr SimplePool bootstrap

This commit is contained in:
thePR0M3TH3AN committed 2025-10-26 21:30:14 -04:00
1 parent e30927d9fd
commit 325a6bd2bf
2 files changed
+35 -17

No files matched your search

+8 -4
View File
@@ -210,10 +210,14 @@ function isSimplePoolConstructor(candidate) {
return false;
}
return (
typeof prototype.sub === "function" &&
typeof prototype.close === "function"
);
const hasSubscribeMethod =
typeof prototype.sub === "function" ||
typeof prototype.subscribe === "function" ||
typeof prototype.subscribeMany === "function";
const hasCloseMethod = typeof prototype.close === "function";
return hasSubscribeMethod && hasCloseMethod;
}
function unwrapSimplePool(candidate) {
+27 -13
View File
@@ -584,19 +584,33 @@ export function bootstrapNostrTools() {
return activeTools;
};
try {
Object.defineProperty(scope, "NostrTools", {
configurable: true,
enumerable: true,
get() {
return activeTools;
},
set(value) {
applyActive(value);
},
});
} catch (error) {
userLogger.warn("[bitvid] Failed to install NostrTools guard.", error);
const existingDescriptor =
scope && typeof scope === "object"
? Object.getOwnPropertyDescriptor(scope, "NostrTools")
: null;
const canInstallGuard =
!existingDescriptor || existingDescriptor.configurable === true;
if (canInstallGuard) {
try {
Object.defineProperty(scope, "NostrTools", {
configurable: true,
enumerable: true,
get() {
return activeTools;
},
set(value) {
applyActive(value);
},
});
} catch (error) {
userLogger.warn("[bitvid] Failed to install NostrTools guard.", error);
}
} else {
devLogger.info(
"[bitvid] Skipping NostrTools guard; existing property is non-configurable."
);
}
applyActive(existingGlobalTools);