npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

expo-bonjour

v0.1.1

Published

Zero-config mDNS (Bonjour) service discovery for Expo and React Native apps.

Readme

expo-bonjour

Zero-config mDNS (Bonjour) service discovery for Expo and React Native apps. 一个”零配置“(mDNS)服务插件,让你可以利用mDNS和Bonjour服务,发现局域网中的设备。

安装

npx expo install expo-bonjour

注意,不支持在 Expo Go 中使用。请安装expo-dev-client并重新构建应用。

配置

app.json中添加以下配置:

{
  "expo": {
    "plugins": [
      [
        "expo-bonjour",
        {
          "localNetworkUsageDescription": "iOS上的本地局域网的权限说明文案",
          "bonjourServices": ["_http._tcp", "_https._tcp"]
        }
      ]
    ]
  }
}

使用

发现设备

import ExpoBonjour from "expo-bonjour";
import { useEvent } from "expo";

const App = () => {
  const newDevice = useEvent(ExpoBonjour, "onDeviceFound");
  useEffect(() => {
    ExpoBonjour.startScan("_http", "_tcp");
    return () => {
      ExpoBonjour.stopScan();
    };
  }, []);

  useEffect(() => {
    if (newDevice) {
      console.log("发现设备:", newDevice);
    }

    /// 或者,你也可以通过监听onDeviceFound以及onDeviceRemoved事件,并通过getAllDevices()方法来获取当前最新的已经扫描到的所有设备。
  }, [newDevice]);
};

获取设备的IP地址

import ExpoBonjour from "expo-bonjour";

const App = () => {
  const newDevice = useEvent(ExpoBonjour, "onDeviceFound");
  useEffect(() => {
    ExpoBonjour.startScan("_http", "_tcp");
    return () => {
      ExpoBonjour.stopScan();
    };
  }, []);

  useEffect(() => {
    if (newDevice) {
      ExpoBonjour.getIPAddress(newDevice).then((deviceInfoWithIPAddress) => {
        console.log("包含IP地址的设备详细信息:", deviceInfoWithIPAddress);
      });
    }
  }, [newDevice]);
};

发布服务

上述内容是扫描其他设备的信息的,你也可以把自己的信息发布到局域网内。需要注意的是,发布服务后,后续的接口处理需要自己额外处理。假如你在8080端口发布了一个_https._tcp的服务,那么你要自己处理8080端口收到的请求。

import ExpoBonjour from "expo-bonjour";

const App = () => {
  useEffect(() => {
    ExpoBonjour.publish({
      name: "_myapp",
      port: 8080,
      service: "_tcp",
      txtRecord: {
        version: "1.0.0",
      },
    });
    return () => {
      ExpoBonjour.stopPublish();
    };
  }, []);
};

支持

本人热衷于开发各种Expo插件,热衷于学习与跟进Expo的最新动态。如果您有任何问题或建议,欢迎联系我。 QQ群:682911244