Search code examples
node.jsreactjsmulticastmdns

mDNS service discovery in ReactJS?


Is it possible to discover mdns tcp services (like _device-pair._tcp) in browser via reactjs? All packages I've found either require node (and more specifically its dgram package) or they are specifically for react-native.

If it is possible, how? If not, is there a specific reason? Is the browser not allowed the access?

I have no prior experience with mDNS so apologies if this is a stupid question.


Solution

  • Exposing this kind of functionality through the browser would be seen as a security risk. (you probably don't want single page applications / javascript running in a browser getting a detailed view of your local network)

    Given that mDNS builds on top multicast UDP this is not supported by your single page application running in a browser as these types of applications will be limited to communicate over

    • HTTP or HTTPs
    • Websockets (ws) or WebSockets Secure (wss)

    As such mDNS service discovery in an SPA is not possible unless some kind of other middleware is involved that can translate it into one of the above mentioned protocols