refactor: unwrap MDNS namespace + self-reexport (#22968)
This commit is contained in:
@@ -3,11 +3,10 @@ import { Bonjour } from "bonjour-service"
|
|||||||
|
|
||||||
const log = Log.create({ service: "mdns" })
|
const log = Log.create({ service: "mdns" })
|
||||||
|
|
||||||
export namespace MDNS {
|
let bonjour: Bonjour | undefined
|
||||||
let bonjour: Bonjour | undefined
|
let currentPort: number | undefined
|
||||||
let currentPort: number | undefined
|
|
||||||
|
|
||||||
export function publish(port: number, domain?: string) {
|
export function publish(port: number, domain?: string) {
|
||||||
if (currentPort === port) return
|
if (currentPort === port) return
|
||||||
if (bonjour) unpublish()
|
if (bonjour) unpublish()
|
||||||
|
|
||||||
@@ -42,9 +41,9 @@ export namespace MDNS {
|
|||||||
bonjour = undefined
|
bonjour = undefined
|
||||||
currentPort = undefined
|
currentPort = undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function unpublish() {
|
export function unpublish() {
|
||||||
if (bonjour) {
|
if (bonjour) {
|
||||||
try {
|
try {
|
||||||
bonjour.unpublishAll()
|
bonjour.unpublishAll()
|
||||||
@@ -56,5 +55,6 @@ export namespace MDNS {
|
|||||||
currentPort = undefined
|
currentPort = undefined
|
||||||
log.info("mDNS service unpublished")
|
log.info("mDNS service unpublished")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export * as MDNS from "./mdns"
|
||||||
|
|||||||
Reference in New Issue
Block a user