(address: URL | string)
| 424 | * Try opening an address using whatever the system has set for opening URLs. |
| 425 | */ |
| 426 | export const open = async (address: URL | string): Promise<void> => { |
| 427 | if (typeof address === "string") { |
| 428 | throw new Error("Cannot open socket paths") |
| 429 | } |
| 430 | // Web sockets do not seem to work if browsing with 0.0.0.0. |
| 431 | const url = new URL(address) |
| 432 | if (url.hostname === "0.0.0.0") { |
| 433 | url.hostname = "localhost" |
| 434 | } |
| 435 | const platform = (await isWsl(process.platform, os.release(), "/proc/version")) ? "wsl" : process.platform |
| 436 | const { command, args, urlSearch } = constructOpenOptions(platform, url.search) |
| 437 | url.search = urlSearch |
| 438 | const proc = cp.spawn(command, [...args, url.toString()], {}) |
| 439 | await new Promise<void>((resolve, reject) => { |
| 440 | proc.on("error", reject) |
| 441 | proc.on("close", (code) => { |
| 442 | return code !== 0 ? reject(new Error(`Failed to open with code ${code}`)) : resolve() |
| 443 | }) |
| 444 | }) |
| 445 | } |
| 446 | |
| 447 | /** |
| 448 | * Return a promise that resolves with whether the socket path is active. |
no test coverage detected