-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(discovery-client): Monkeypatch uncatchable throw from mdns-js (#2433
- Loading branch information
Showing
4 changed files
with
33 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// @flow | ||
// mdns browser wrapper | ||
import mdns, {ServiceType} from 'mdns-js' | ||
import type {Browser} from 'mdns-js' | ||
|
||
monkeyPatchThrowers() | ||
|
||
export default function MdnsBrowser (): Browser { | ||
return mdns.createBrowser(mdns.tcp('http')) | ||
} | ||
|
||
function monkeyPatchThrowers () { | ||
// this method can throw (without emitting), so we need to patch this up | ||
const originalServiceTypeFromString = ServiceType.prototype.fromString | ||
|
||
ServiceType.prototype.fromString = function (...args) { | ||
try { | ||
originalServiceTypeFromString.apply(this, args) | ||
} catch (error) { | ||
console.warn(error) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters