From f63dda8d57a5d8bca75582a60771c26bfb45c9ba Mon Sep 17 00:00:00 2001 From: Evan Hahn Date: Mon, 12 Feb 2024 22:59:46 +0000 Subject: [PATCH] chore: update bonjour-service to v1.2.1 This version integrates all of our patches except the one for the `probe` option when starting a `Service`. That version also has some trickiness around types for `start` and `stop`, which are also fixed here. I submitted these patches [upstream] but haven't heard back as of this writing. [upstream]: https://github.com/onlxltd/bonjour-service/pull/48 --- package-lock.json | 20 +---- package.json | 2 +- patches/bonjour-service+1.1.1.patch | 116 ---------------------------- patches/bonjour-service+1.2.1.patch | 77 ++++++++++++++++++ src/discovery/dns-sd.js | 2 +- 5 files changed, 83 insertions(+), 134 deletions(-) delete mode 100644 patches/bonjour-service+1.1.1.patch create mode 100644 patches/bonjour-service+1.2.1.patch diff --git a/package-lock.json b/package-lock.json index b7b9953f8..2c4bfbb07 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,7 +22,7 @@ "better-sqlite3": "^8.7.0", "big-sparse-array": "^1.0.3", "bogon": "^1.1.0", - "bonjour-service": "^1.1.1", + "bonjour-service": "^1.2.1", "compact-encoding": "^2.12.0", "corestore": "^6.8.4", "debug": "^4.3.4", @@ -1424,11 +1424,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/array-flatten": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-2.1.2.tgz", - "integrity": "sha512-hNfzcOV8W4NdualtqBFPyVO+54DSJuZGY9qT4pRroB6S9e3iiido2ISIC5h9R2sPJ8H3FHCIiEnsv1lPXO3KtQ==" - }, "node_modules/arraybuffer.prototype.slice": { "version": "1.0.1", "dev": true, @@ -1599,12 +1594,10 @@ } }, "node_modules/bonjour-service": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/bonjour-service/-/bonjour-service-1.1.1.tgz", - "integrity": "sha512-Z/5lQRMOG9k7W+FkeGTNjh7htqn/2LMnfOvBZ8pynNZCM9MwkQkI3zeI4oz09uWdcgmgHugVvBqxGg4VQJ5PCg==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/bonjour-service/-/bonjour-service-1.2.1.tgz", + "integrity": "sha512-oSzCS2zV14bh2kji6vNe7vrpJYCHGvcZnlffFQ1MEoX/WOeQ/teD8SYWKR942OI3INjq8OMNJlbPK5LLLUxFDw==", "dependencies": { - "array-flatten": "^2.1.2", - "dns-equal": "^1.0.0", "fast-deep-equal": "^3.1.3", "multicast-dns": "^7.2.5" } @@ -2354,11 +2347,6 @@ "node": ">=8" } }, - "node_modules/dns-equal": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/dns-equal/-/dns-equal-1.0.0.tgz", - "integrity": "sha512-z+paD6YUQsk+AbGCEM4PrOXSss5gd66QfcVBFTKR/HpFL9jCqikS94HYwKww6fQyO7IxrIIyUu+g0Ka9tUS2Cg==" - }, "node_modules/dns-packet": { "version": "5.6.1", "resolved": "https://registry.npmjs.org/dns-packet/-/dns-packet-5.6.1.tgz", diff --git a/package.json b/package.json index 131d567a3..7a0269155 100644 --- a/package.json +++ b/package.json @@ -119,7 +119,7 @@ "better-sqlite3": "^8.7.0", "big-sparse-array": "^1.0.3", "bogon": "^1.1.0", - "bonjour-service": "^1.1.1", + "bonjour-service": "^1.2.1", "compact-encoding": "^2.12.0", "corestore": "^6.8.4", "debug": "^4.3.4", diff --git a/patches/bonjour-service+1.1.1.patch b/patches/bonjour-service+1.1.1.patch deleted file mode 100644 index 04d291c9a..000000000 --- a/patches/bonjour-service+1.1.1.patch +++ /dev/null @@ -1,116 +0,0 @@ -diff --git a/node_modules/bonjour-service/dist/index.d.ts b/node_modules/bonjour-service/dist/index.d.ts -index a345f1f..7a44afa 100644 ---- a/node_modules/bonjour-service/dist/index.d.ts -+++ b/node_modules/bonjour-service/dist/index.d.ts -@@ -8,7 +8,7 @@ export declare class Bonjour { - unpublishAll(callback?: CallableFunction | undefined): void; - find(opts?: BrowserConfig | undefined, onup?: (service: Service) => void): Browser; - findOne(opts?: BrowserConfig | undefined, timeout?: number, callback?: CallableFunction): Browser; -- destroy(): void; -+ destroy(callback?: CallableFunction): void; - } - export { Service, ServiceReferer, ServiceConfig, Browser, BrowserConfig }; - export default Bonjour; -diff --git a/node_modules/bonjour-service/dist/index.js b/node_modules/bonjour-service/dist/index.js -index 2369679..e868386 100644 ---- a/node_modules/bonjour-service/dist/index.js -+++ b/node_modules/bonjour-service/dist/index.js -@@ -41,9 +41,9 @@ class Bonjour { - }, timeout); - return browser; - } -- destroy() { -+ destroy(callback) { - this.registry.destroy(); -- this.server.mdns.destroy(); -+ this.server.mdns.destroy(callback); - } - } - exports.Bonjour = Bonjour; -diff --git a/node_modules/bonjour-service/dist/lib/registry.js b/node_modules/bonjour-service/dist/lib/registry.js -index 22d6f82..09f2fea 100644 ---- a/node_modules/bonjour-service/dist/lib/registry.js -+++ b/node_modules/bonjour-service/dist/lib/registry.js -@@ -9,6 +9,7 @@ const dns_equal_1 = __importDefault(require("dns-equal")); - const service_1 = __importDefault(require("./service")); - const REANNOUNCE_MAX_MS = 60 * 60 * 1000; - const REANNOUNCE_FACTOR = 3; -+const noop = function () {} - class Registry { - constructor(server) { - this.services = []; -@@ -26,7 +27,7 @@ class Registry { - registry.probe(registry.server.mdns, service, (exists) => { - if (exists) { - service.stop(); -- console.log(new Error('Service name is already in use on the network')); -+ console.log(service, new Error('Service name is already in use on the network')); - return; - } - registry.announce(registry.server, service); -@@ -37,19 +38,20 @@ class Registry { - } - } - function stop(service, registry, callback) { -+ if (!callback) callback = noop - if (!service.activated) -- return; -+ return process.nextTick(callback); - if (!(service instanceof service_1.default)) -- return; -+ return process.nextTick(callback); - registry.teardown(registry.server, service, callback); - const index = registry.services.indexOf(service); - if (index !== -1) - registry.services.splice(index, 1); - } - const service = new service_1.default(config); -- service.start = start.bind(null, service, this); -+ service.start = start.bind(null, service, this, { probe: config.probe !== false }); - service.stop = stop.bind(null, service, this); -- service.start({ probe: config.probe !== false }); -+ service.start(); - return service; - } - unpublishAll(callback) { -@@ -123,7 +125,7 @@ class Registry { - return records; - }), 1); - if (records.length === 0) -- return callback && callback(); -+ return callback && process.nextTick(callback); - server.unregister(records); - server.mdns.respond(records, function () { - services.forEach(function (service) { -diff --git a/node_modules/bonjour-service/dist/lib/service.d.ts b/node_modules/bonjour-service/dist/lib/service.d.ts -index c4deebc..ab769f1 100644 ---- a/node_modules/bonjour-service/dist/lib/service.d.ts -+++ b/node_modules/bonjour-service/dist/lib/service.d.ts -@@ -11,6 +11,7 @@ export interface ServiceConfig { - subtypes?: Array; - txt?: KeyValue; - probe?: boolean; -+ disableIpv6?: boolean; - } - export interface ServiceRecord { - name: string; -diff --git a/node_modules/bonjour-service/dist/lib/service.js b/node_modules/bonjour-service/dist/lib/service.js -index 16b3526..3565973 100644 ---- a/node_modules/bonjour-service/dist/lib/service.js -+++ b/node_modules/bonjour-service/dist/lib/service.js -@@ -31,6 +31,7 @@ class Service extends events_1.EventEmitter { - this.fqdn = `${this.name}.${this.type}${TLD}`; - this.txt = config.txt; - this.subtypes = config.subtypes; -+ this.disableIpv6 = !!config.disableIpv6 - } - records() { - var records = [this.RecordPTR(this), this.RecordSRV(this), this.RecordTXT(this)]; -@@ -48,6 +49,7 @@ class Service extends events_1.EventEmitter { - records.push(this.RecordA(this, addr.address)); - break; - case 'IPv6': -+ if (this.disableIpv6) break; - records.push(this.RecordAAAA(this, addr.address)); - break; - } diff --git a/patches/bonjour-service+1.2.1.patch b/patches/bonjour-service+1.2.1.patch new file mode 100644 index 000000000..2d7053d59 --- /dev/null +++ b/patches/bonjour-service+1.2.1.patch @@ -0,0 +1,77 @@ +diff --git a/node_modules/bonjour-service/dist/lib/registry.js b/node_modules/bonjour-service/dist/lib/registry.js +index 5462ca2..662486d 100644 +--- a/node_modules/bonjour-service/dist/lib/registry.js ++++ b/node_modules/bonjour-service/dist/lib/registry.js +@@ -15,14 +15,18 @@ class Registry { + this.server = server; + } + publish(config) { +- function start(service, registry, opts) { ++ const configProbe = config.probe !== false; ++ ++ const service = new service_1.default(config, start.bind(null, this), stop.bind(null, this)); ++ ++ function start(registry, { probe = configProbe } = {}) { + if (service.activated) + return; + service.activated = true; + registry.services.push(service); + if (!(service instanceof service_1.default)) + return; +- if (opts === null || opts === void 0 ? void 0 : opts.probe) { ++ if (probe) { + registry.probe(registry.server.mdns, service, (exists) => { + if (exists) { + if (service.stop !== undefined) +@@ -37,7 +41,7 @@ class Registry { + registry.announce(registry.server, service); + } + } +- function stop(service, registry, callback) { ++ function stop(registry, callback) { + if (!callback) + callback = noop; + if (!service.activated) +@@ -49,10 +53,7 @@ class Registry { + if (index !== -1) + registry.services.splice(index, 1); + } +- const service = new service_1.default(config); +- service.start = start.bind(null, service, this); +- service.stop = stop.bind(null, service, this); +- service.start({ probe: config.probe !== false }); ++ service.start(); + return service; + } + unpublishAll(callback) { +diff --git a/node_modules/bonjour-service/dist/lib/service.d.ts b/node_modules/bonjour-service/dist/lib/service.d.ts +index 2c711f9..c459a07 100644 +--- a/node_modules/bonjour-service/dist/lib/service.d.ts ++++ b/node_modules/bonjour-service/dist/lib/service.d.ts +@@ -41,8 +41,8 @@ export declare class Service extends EventEmitter { + published: boolean; + activated: boolean; + destroyed: boolean; +- start?: CallableFunction; +- stop?: CallableFunction; ++ start: CallableFunction; ++ stop: CallableFunction; + private txtService; + constructor(config: ServiceConfig); + records(): Array; +diff --git a/node_modules/bonjour-service/dist/lib/service.js b/node_modules/bonjour-service/dist/lib/service.js +index 41da95a..ac71665 100644 +--- a/node_modules/bonjour-service/dist/lib/service.js ++++ b/node_modules/bonjour-service/dist/lib/service.js +@@ -10,8 +10,10 @@ const events_1 = require("events"); + const service_types_1 = require("./service-types"); + const TLD = '.local'; + class Service extends events_1.EventEmitter { +- constructor(config) { ++ constructor(config, start, stop) { + super(); ++ this.start = start; ++ this.stop = stop; + this.probe = true; + this.published = false; + this.activated = false; diff --git a/src/discovery/dns-sd.js b/src/discovery/dns-sd.js index 045c09eff..85d38b09c 100644 --- a/src/discovery/dns-sd.js +++ b/src/discovery/dns-sd.js @@ -119,7 +119,7 @@ export class DnsSd extends TypedEmitter { host: this.#name + '.local', port, type: SERVICE_NAME, - disableIpv6: this.#disableIpv6, + disableIPv6: this.#disableIpv6, }) } this.#advertisingStarting = once(this.#service, 'up')